camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Calvert, Zach (Zach)** CTR **" <>
Subject Error Handler
Date Thu, 03 Nov 2011 14:21:08 GMT
I have a CXF bean sending out a camel message on a ProducerTemplate and I want any exceptions
thrown on the route to immediately come back as the response.  It is an inOut message:
producer.sendBodyAndHeaders(URI, ExchangePattern.InOut, body, headers);

I have not figured out the magic method to getting the response to automatically fast fail
if an exception is thrown by any method along the way.  For example, the URI goes to an ActiveMQ
queue, and if I have it immediately run
If (true) throw new RuntimeException();

The exception eventually results the jetty response of HTTP 500 server error on the jetty
CXF API.  I have two bundles, one bundle is the jetty CXF followed by sending this to an active
MQ queue and the second bundle consumes the message with another route.  If on the second
route, the operation throws an Exception and I create an error handler, to the tune of

            <camel:bean ref="fastFailErrorHandler" method="handleError" />

    public Object handleError(Exchange exchange) {
        Throwable caused = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
        logger.debug("Error handler triggered");
        return caused;

The original problem will be a timeout exception, waiting the default 20 seconds.  If I modify
it to be
            <camel:bean ref="fastFailErrorHandler" method="handleError" />

Then the body continues working its way through subsequent queues as if nothing went wrong.

How do I tell Camel, "hey Camel, please throw this thing to the original caller as the response

Zach Calvert

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message