Six Stars

[Talend 6.2.0] doTry on setHeader does not work

Hi,
I am using Talend Open Studio for ESB v6.2.0 and Karaf 4.0.5.
Camel route (.kar) is as follows and is deployed in container/deploy
talend-camel floow ---> cDoTry --> cJavaDSLComponent (setHeader("X-Field").simple("${header.X-AnotherField}"))
                                   cCatch (Exception.class)  --> cJavaDSLComponent (setHeader("X-Field").contant("some value"))
                                   cFinally --> flow continues
If the header.X-AnotherField exists, everything works fine. If the header does not exist, flow fails silently (no error or exception thrown) at doTry and does not continue.
Similar behaviour happens with fetching values to header via jsonpath. Replacing cJavaDSLComponent for cSetHeader component is same.
Is this intended behaviour, am I using the components wrong?
2 REPLIES
One Star

Re: [Talend 6.2.0] doTry on setHeader does not work

Martin, just use a "CProcessor" component with the following few lines: ( copy and paste these lines in the CProcessor "basic settings"->"Code" area )
String vXAnotherField = (String)exchange.getIn().getHeader("X-AnotherField");
if(vXAnotherField == null) 
exchange.getIn().setHeader("X-Field","some value"); 
else
exchange.getIn().setHeader("X-Field",vXAnotherField); 
as shown bellow:

you don't need to crate any try/catch block.
Hope this helps, Esteban. 
Six Stars

Re: [Talend 6.2.0] doTry on setHeader does not work

Thank you zarcap, cProcessor works fine. I guess usage of cPRocessor is much more effective than using talend components as cSetHeader.