jboss - Caught exception inaccessible after routing -


i'm building exception handler jboss/camel project. catching exception onexception clause works, , can access caught exception bean, work's directly in exception handler. since need handler in multiple different projects, want direct handler different route (in different context), , handle exception there centrally. after routing, caught exception not accessible longer. why this, , how can fix that. i'd not have add ejb of projects.

code:

<camelcontext id="project1context" xmlns="http://camel.apache.org/schema/spring">     <onexception>         <exception>java.lang.exception</exception>         <handled>             <constant>true</constant>         </handled>         <bean ref="projectspecificbean" method="peekexception" />         <to uri="activemq:queue:centralexceptionhandling" />     </onexception>      [... routes of context, exception happens ...] </camelcontext> 

in bean:

public void peekexception(exchange camelexchange) {     exception e = camelexchange.getproperty(exchange.exception_caught, exception.class);     log.warn("caught general exception", e); } 

this gives me access exception inside bean. when remove <bean ref="projectspecificbean" method="peekexception" /> onexception clause , add same thing route @ activemq:queue:centralexceptionhandling (to bean local project there, in different camelcontext), cannot find exception anywhere in exchange.

to able receive exception on client of activemq queue need use camel jms component option "transferexchange". option must enabled on both sides (during sending activemq queue , receiving it). in case not message body/headers sent whole exchange transfered. see http://camel.apache.org/jms.html (transferexchange option). in general looks there no queue between exception route , exception handler route. here details documentation:

you can transfer exchange on wire instead of body , headers. following fields transferred: in body, out body, fault body, in headers, out headers, fault headers, exchange properties, exchange exception. requires objects serializable. camel exclude non-serializable objects , log @ warn level. must enable option on both producer , consumer side, camel knows payloads exchange , not regular payload.

example of code:

<camelcontext id="project1context" xmlns="http://camel.apache.org/schema/spring"> <onexception>     <exception>java.lang.exception</exception>     <handled>         <constant>true</constant>     </handled>     <bean ref="projectspecificbean" method="peekexception" />     <to uri="activemq:queue:centralexceptionhandling?transferexchange=true" /> </onexception>  [... routes of context, exception happens ...] </camelcontext>  // somewhere in central exception handler. <camelcontext id="exceptionhandlercontext" xmlns="http://camel.apache.org/schema/spring"> <route>     <from uri="activemq:queue:centralexceptionhandling?transferexchange=true" />     <!-- here have same exchange before sent activemq --> </route> </camelcontext> 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -