See this FAQ http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html
On Fri, May 10, 2013 at 4:52 PM, apatel <apa...@asg.bellsouth.net> wrote: > Apache Camel 2.11.0, 2.10.4 > > > Below route does not return "foo" > > > ========= > <route xmlns="http://camel.apache.org/schema/spring" trace="true"> > <from uri="servlet:///nimbus/testTryCatch"/> > <setHeader headerName="foo"> > <constant>bar</constant> > </setHeader> > > <doTry> > > <setHeader headerName="MAP_NAME"> > <constant>fooName</constant> > </setHeader> > <setHeader headerName="MAP_KEY"> > <constant>bar</constant> > </setHeader> > <to uri="bean:myService?method=getMapEntry"/> > > <doCatch> > <exception>java.lang.Throwable</exception> > </doCatch> > </doTry> > > <setBody> > <header>foo</header> > </setBody> > </route> > > > class myServices > { > public void getMapEntry(Exchange e) { > def EEL_METHOD = "getMapEntry" > def mapKey > def mapName > try{ > mapKey = e.getIn().getHeader("MAP_KEY", String.class) > mapName =e.getIn().getHeader("MAP_NAME", String.class) > // support inout pattern > def headers = e.getIn().getHeaders() > > def res = this.getMap(mapName).get(mapKey) > if( res != null){ > headers.put("CACHE_ENTRY_FOUND", "true") > e.getOut().setBody( res ) > > }else{ > headers.put("CACHE_ENTRY_FOUND", "false") > // support inout pattern > e.getOut().setBody( e.getIn().getBody() ) > > } > > e.getOut().setHeaders(headers) > > }catch(all){ > > throw all > } > } > } > > Below route does return "foo" since i removed try catch > ========= > > <route xmlns="http://camel.apache.org/schema/spring" trace="true"> > <from uri="servlet:///nimbus/testTryCatch"/> > <setHeader headerName="foo"> > <constant>bar</constant> > </setHeader> > > > > <setHeader headerName="MAP_NAME"> > <constant>fooName</constant> > </setHeader> > <setHeader headerName="MAP_KEY"> > <constant>bar</constant> > </setHeader> > <to uri="bean:myService?method=getMapEntry"/> > <setBody> > <header>foo</header> > </setBody> > </route> > > > > Below route does return "foo" since i add <to uri="mock:results"/> that > set exchange.out= exchange.in > ======== > > <route xmlns="http://camel.apache.org/schema/spring" trace="true"> > <from uri="servlet:///nimbus/tesTryCatch"/> > <setHeader headerName="foo"> > <constant>bar</constant> > </setHeader> > > <doTry> > > <setHeader headerName="MAP_NAME"> > <constant>fooName</constant> > </setHeader> > <setHeader headerName="MAP_KEY"> > <constant>bar</constant> > </setHeader> > <to uri="bean:myService?method=getMapEntry"/> > > <to uri="mock:results"/> > <doCatch> > <exception>java.lang.Throwable</exception> > </doCatch> > </doTry> > > <setBody> > <header>foo</header> > </setBody> > </route> > > > Also if i changes myService method to set exchange.out = exchange.in it > works. > > > class myServices > { > public void getMapEntry(Exchange e) { > > def mapKey > def mapName > //I added e.setOut(e.getIn()) > e.setOut(e.getIn()) > > try{ > mapKey = e.getIn().getHeader("MAP_KEY", String.class) > mapName =e.getIn().getHeader("MAP_NAME", String.class) > // support inout pattern > def headers = e.getIn().getHeaders() > > def res = this.getMap(mapName).get(mapKey) > if( res != null){ > headers.put("CACHE_ENTRY_FOUND", "true") > e.getOut().setBody( res ) > > }else{ > headers.put("CACHE_ENTRY_FOUND", "false") > // support inout pattern > e.getOut().setBody( e.getIn().getBody() ) > > } > > e.getOut().setHeaders(headers) > > }catch(all){ > > throw all > } > } > } > > > I believe it occurred in any Async processor. > > > Thanks for your help!!! > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Route-with-doTry-calling-service-does-not-have-exchange-in-exchange-out-does-not-work-tp5732293.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen ----------------- Red Hat, Inc. FuseSource is now part of Red Hat Email: cib...@redhat.com Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen