I have the following Camel route:
<route id="myroute">
<from uri="timer://runOnce?repeatCount=1&delay=10" />
<!-- Set a new property on the exchange. -->
<to uri="bean:propSetter?method=setProp" />
<to uri="direct:fizz" />
</route>
My PropSetter
bean:
public class PropSetter {
// Add new "buzz" ArrayList<Long> to the exchange.
public void setProp(Exchange exchange) {
exchange.setProperty("buzz", new ArrayList<Long>());
}
}
I would like to rewrite this without a Java bean and instead use Camel's <setProperty/>
element. The only thing I can think of is to use the built-in Groovy expression:
<route id="myroute">
<from uri="timer://runOnce?repeatCount=1&delay=10" />
<!-- Set a new property on the exchange. -->
<setProperty propertyName="buzz">
<groovy>new ArrayList<Long>();</groovy>
</setProperty>
<to uri="direct:fizz" />
</route>
But this does not seem to work. So how can I use XML to set a new ArrayList<Long>
on the exchange called buzz
?
Define a list using Spring's util namespace as :
<util:list id="myList" value-type="java.lang.String">
</util:list>
Then using the simple language you can access the bean and set in an exchange property
<camel:setProperty propertyName="buzz">
<camel:simple>${bean:myList}</camel:simple>
</camel:setProperty>
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.