camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Calvert, Zach (Zach)** CTR **" <zcalv...@motive.com>
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:onException>
            <camel:exception>java.lang.Throwable</camel:exception>
            <camel:bean ref="fastFailErrorHandler" method="handleError" />
        </camel:onException>

    public Object handleError(Exchange exchange) {
        Throwable caused = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
        exchange.getIn().setFault(true);
        exchange.getOut().setFault(true);
        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:onException>
            <camel:exception>java.lang.Throwable</camel:exception>
            <camel:handled>
                <camel:constant>true</camel:constant>
            </camel:handled>
            <camel:bean ref="fastFailErrorHandler" method="handleError" />
        </camel:onException>

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
body".




Thanks,
Zach Calvert


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