简体   繁体   English

Apache Camel-Groovy脚本

[英]Apache Camel - Groovy Scripting

I am trying to use a Groovy script in the Spring DSL as follows: 我正在尝试在Spring DSL中使用Groovy脚本,如下所示:

<from uri="file://{{my.path}}">
    <choice>
        <when>
            <groovy>properties.resolve 'file.one.isActive' == 'true'</groovy>
            <to uri="file://{{file.one}}"/>
        </when>
        <otherwise>
            <to uri="file://{{file.two}}"/>
        </otherwise>
    </choice>
</from>

However I am getting the following exception: 但是我得到以下异常:

    Exhausted after delivery attempt:
     1 caught: groovy.lang.MissingMethodException: 
       No signature of method: java.util.LinkedHashMap.resolve() 
           is applicable for argument types: 
                     (java.lang.Boolean) values: [false]

I have these dependencies in my pom.xml: 我的pom.xml中有以下依赖项:

       <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-script</artifactId>
            <version>2.13.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-groovy</artifactId>
            <version>2.13.1</version>
        </dependency>

Based on http://camel.apache.org/groovy.html I should be able to use the properties reference with a resolve method. 基于http://camel.apache.org/groovy.html我应该能够将properties引用与resolve方法一起使用。

Any idea what is wrong? 知道有什么问题吗?

I think it is evaluating ('file.one.isActive' == 'true') before it is resolving. 我认为它正在解决('file.one.isActive'=='true')。 Better to resolve ( 'file.one.isActive' ) == 'true' for clarity 为了清晰起见,更好地解析 'file.one.isActive' =='true'

I faced same issue so posting solution for other people who will face it in future. 我遇到了同样的问题,因此为将来会遇到的其他人发布解决方案。

Despite of information in camel doc which says that script context is preconfigured with properties attribute of org.apache.camel.builder.script.PropertiesFunction type it is not happening. 尽管骆驼文档中有信息说脚本上下文已使用org.apache.camel.builder.script.PropertiesFunction类型的properties属性进行了预配置,但这种情况并未发生。 Properties attribute is resolved to exchange properties. 属性属性解析为交换属性。 Seems like it is Camel defect (using Camel 2.16.1). 似乎是Camel缺陷(使用Camel 2.16.1)。

Workaround: 解决方法:

camelContext.resolvePropertyPlaceholders("{{file.one.isActive}}")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM