ChrisGeo ChrisGeo - 2 months ago 30
Groovy Question

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?

Answer

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}}")
Comments