camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: onException not triggered
Date Fri, 18 Oct 2013 07:06:23 GMT
Yes the 2nd route handles the error, and so when the messages returns
to route 1, it has already been handled by an error handler, and is
not handled again. This is by design.

Also avoids endless error handling etc.

You can set the 2nd route to have no error handler, or call the 2nd
route in a do try .. do catch style.



On Fri, Oct 18, 2013 at 4:10 AM, Christian Posta
<christian.posta@gmail.com> wrote:
> Maybe someone else can explain the reasoning for this behavior, but what's
> happening is:
>
> your errorHandler is handling the exception in route 2, but it doesn't see
> any exception handlers (none declared on the immediate route, and none
> globally defined).
>
> so it just tries redelivery, marks it as "FAILURE_HANDLED". When the first
> route gets the exchange, it will decide what to do with it... and since the
> route first handling the error marked it as "FAILURE_HANDLED" the first
> route doesn't try to do anything with it and propagate the exception back
> up.
>
> To get the behavior you're looking for, move the onException clause to be
> global.
>
> HTH
>
>
> On Thu, Oct 17, 2013 at 3:33 PM, Bilgin Ibryam <bibryam@gmail.com> wrote:
>
>> Hi Camel riders,
>>
>> I'm trying to figure out why onException is not triggerd in the following
>> route. The solution I found is to use try-catch instead, but I'd prefer to
>> have it work only with errorHandler and onException
>>
>>
>> import org.apache.camel.builder.RouteBuilder;
>> import org.apache.camel.test.junit4.CamelTestSupport;
>> import org.junit.Test;
>>
>> public class ErrorTest extends CamelTestSupport {
>>
>>     @Test
>>     public void testErrorIsThrown() throws Exception {
>>
>>         getMockEndpoint("mock:foundException").expectedMessageCount(1);
>>
>>         try {
>>             template.sendBody("direct:start", "test");
>>             fail("Propagate exception back to consumer");
>>         } catch (Exception e) {
>>         }
>>         assertMockEndpointsSatisfied();
>>     }
>>
>>     @Override
>>     protected RouteBuilder createRouteBuilder() {
>>         return new RouteBuilder() {
>>             public void configure() {
>>
>>                 from("direct:start")
>>                         .to("direct:internal")
>>                             .onException(Exception.class)
>>                             .to("mock:foundException");
>>
>>                 from("direct:internal")
>>
>> .errorHandler(defaultErrorHandler().maximumRedeliveries(2))
>>                         .throwException(new RuntimeException())
>>                         .to("mock:never");
>>             }
>>         };
>>     }
>> }
>>
>>
>>
>> --
>> Bilgin Ibryam
>>
>> Apache Camel & Apache OFBiz committer
>> Blog: ofbizian.com
>> Twitter: @bibryam <https://twitter.com/bibryam>
>>
>> Author of Instant Apache Camel Message Routing
>> http://www.amazon.com/dp/1783283475
>>
>
>
>
> --
> *Christian Posta*
> http://www.christianposta.com/blog
> twitter: @christianposta



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Mime
View raw message