简体   繁体   中英

Apache Camel - Groovy Scripting

I am trying to use a Groovy script in the Spring DSL as follows:

<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:

       <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.

Any idea what is wrong?

I think it is evaluating ('file.one.isActive' == 'true') before it is resolving. Better to resolve ( 'file.one.isActive' ) == 'true' for clarity

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. Properties attribute is resolved to exchange properties. Seems like it is Camel defect (using Camel 2.16.1).

Workaround:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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