camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bilgin Ibryam <bibr...@gmail.com>
Subject Re: onException not triggered
Date Fri, 18 Oct 2013 09:23:43 GMT
Thanks for the insight guys.

@Christian moving onException to context is not solving it, as in this case
the errorHandler is not doing reties!

My final goal is simple:
Let the second route to retry 3 times, and if it fails propagate back.
Then route one sends an error message (mock:exceptionFound) and propagates
the exception back, so that the originial fila based consumer can put the
file to failled location.

The solution I found was to keep the error handled in route two and use
try-catch in route one.
Couldn't find a cleaner solution using only onException and/or errorHandler

Cheers,



On 18 October 2013 08:06, Claus Ibsen <claus.ibsen@gmail.com> wrote:

> 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
>



-- 
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

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