For this we made use of the RethrowException bean which has a very simple implementation. A single void method which takes an Exchange as a parameter. The only slightly interesting thing about this post is how we get our hands on the Exception that Camel caught for us. That is quite straightforward because luckily for us, Camel sets the caught exception as a Property on the exchange with the key CamelExceptionCaught. So the code for the RethrowingException bean is:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.ic.camel.tools.bean.exception; | |
import org.apache.camel.Exchange; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class RethrowException { | |
Logger logger=LoggerFactory.getLogger(RethrowException.class); | |
public void processExchange(Exchange exchange) throws Throwable | |
{ | |
Throwable caughtException=(Throwable) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); | |
if(caughtException!=null) | |
{ | |
logger.debug("Rethrowing Exception "+caughtException.getClass()); | |
throw caughtException; | |
} | |
} | |
} |
Funny. I wrote this class too. Do you still use Camel?
ReplyDelete