Bilgin,

Not sure why moving the onException to global wouldn't work for you.
The error handler checks local scope and global scope to find an
appropriate exception handler.

It works on the latest master here:

https://github.com/christian-posta/camel-sandbox/blob/master/camel-snapshot/src/test/java/posta/ErrorTest.java#L45


On Fri, Oct 18, 2013 at 2:23 AM, Bilgin Ibryam <bibr...@gmail.com> wrote:

> 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.ib...@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.po...@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 <bibr...@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: cib...@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
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Reply via email to