camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dnn <Daniel.Nawro...@ngc.com>
Subject onException handling
Date Thu, 08 Apr 2010 19:07:42 GMT

I am trying to use global onException handling with a transacted route. 
According to the everything I've read, the following should print the "HEY I
GOT AN EXCEPTION" message:

<camelContext errorHandlerRef="myErrorHandler">
   <onException>
      <exception>java.lang.Exception</exception>
      <log loggingLevel="ERROR" message="HEY I GOT AN EXCEPTION" />
   </onException>
   <route>
      <from uri="jms:test" />
      <transacted />
      <to uri="someProcessorThatThrowsAnException" />
   </route>
</camelContext>
<bean id="myErrorHandler"
class="org.apache.camel.spring.spi.TransactionErrorHandlerBuilder"> 
   <property name="transactionTemplate"
ref="PROPAGATION_REQUIRES_NEW_TEMPLATE" />
</bean>
<bean id="PROPAGATION_REQUIRES_NEW_TEMPLATE"
class="org.springframework.transaction.support.TransactionTemplate">
   <property name="transactionManager" ref="transactionManager" />
   <property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"
/>
</bean>

I would imagine that when "someProcessorThatThrowsAnException" is executed,
it will throw an exception that is handled by the global onException
handler.  However, it doesn't work and my log message is never printed out.

I have found a workaround by moving the onException handling INSIDE the
<transacted></transacted> block as such:

<camelContext errorHandlerRef="myErrorHandler">
   <route>
      <from uri="jms:test" />
      <transacted>
         <onException>
            <exception>java.lang.Exception</exception>
            <log loggingLevel="ERROR" message="HEY I GOT AN EXCEPTION" />
         </onException>
         <to uri="someProcessorThatThrowsAnException" />
      </transacted>
   </route>
</camelContext>

It appears that the <transacted></transacted> block is creating its own
try/catch block that is ignorant of the global onException handler.  Is this
the expected behavior?  Is there any way to make it act like my first
example?  I would prefer using the global onException route to share it
among several routes.

I am using Camel 2.2.0.

Thanks,
Dan Nawrocki

-- 
View this message in context: http://old.nabble.com/onException-handling-tp28183226p28183226.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message