I am setting a property of camel exchange in route 1. I am trying to update the same in the second route inside a splitter. but in the second iteration of splitter i am getting the original value that I set in the route 1 instead of the new updated value. Below is the sample i am trying..
<route handleFault="true" streamCache="true" id="route1">
<from uri="cxfrs://bean://test?synchronous=true"/>
<bean ref="testBean" method="setMyProperty"/>// setting initial value for property
<to uri="direct:directCall"/>
</route>
<route handleFault="true" streamCache="true" id="route2">
<from uri="direct:directcall"/>
<log message="Inside Second call..."/>
<split>
<jsonpath>some Json path</jsonpath>
<bean ref="formatConvertor" method ="convertLHMToJSON(${body})"/>
<split>
<jsonpath>some json path</jsonpath>
<bean ref="PropertySetter" method ="setProperty"/> //I am setting new value in this method
</split>
</split>
Inside the beans:
public void setMyProperty(Exchange exchange) {
exchange.setProperty("testProp", "hello");
}
public void setProperty(Exchange exchange) {
sysout(exchange.getProperty("testProp").toString())//this always prints "hello"
String x=exchange.getProperty("testProp")+some other value;// in all iterations of split I am getting 'hello' as the value of the property instead of new value
exchange.setProperty("testProp", x);
sysout(exchange.getProperty("testProp").toString())// this line prints the new value
}
Why the property is not updated? Even i tried setting in headers. same result. Thank you.
You must use a split-aggregate pattern and copy the property value during each iteration of the split from the old exchange to the new exchange because every time when the split iteration happens a new exchange is created from the source message (only carrying the properties & headers set before the split) recover headers value after split apache camel