You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ninadmnaik <nn...@gmail.com> on 2014/04/23 19:21:30 UTC

Using consumer.bridgeErrorHandler won't allow onException() route to execute completely.

Hello, 

We are using "consumer.bridgeErrorHandler=true" in our route, so that if
there's an exception during picking up of files, the Camel Error Handler can
deal with it. 

It appears from the documentation and code snippet at:
http://camel.apache.org/file2.html (Using consumer.bridgeErrorHandler
section) that if there's an error picking up files, the "onException" clause
will be invoked and will continue to execute the ".to("mock:error") clause.

However, in our case, the "onException" clause is invoked, however the ".to"
clause isn't. Here's how our code looks like:

      onException(SomeException.class).process(new Processor()
      {
         @Override
         public void process(Exchange exchange)
         {
	 //Do some logging, processing etc. 
         }
      }).to("direct:sendEmail");

So, in the above code the ".to("direct:sendEmail")" part is never invoked. 

While I was debugging this, I found out that in
BridgeExceptionHandlerToErrorHandler.java#handleException(String message,
Exchange exchange, Throwable exception), Exchange.REDELIVERY_EXHAUSTED is
set to true on Exchange:
       // and mark as redelivery exhausted as we cannot do redeliveries
        exchange.setProperty(Exchange.REDELIVERY_EXHAUSTED, Boolean.TRUE);

This causes this exchange to get marked as "exhausted" in
RedeliveryErrorHandler.java#processErrorHandler(final Exchange exchange,
final AsyncCallback callback, final RedeliveryData data) and the
".to("direct:sendEmail")" part of the route is never processed. 

This isn't compliant with the documentation. 

So, the question is: do we need to set another property on the route to
execute the complete route? Currently, we are just removing
"Exchange.REDELIVERY_EXHAUSTED" from the exchange in our onException clause

      onException(SomeException.class).process(new Processor()
      {
         @Override
         public void process(Exchange exchange)
         { 
             exchange.getProperties().remove(Exchange.REDELIVERY_EXHAUSTED);

         }
      }).to("direct:sendEmail");


 






--
View this message in context: http://camel.465427.n5.nabble.com/Using-consumer-bridgeErrorHandler-won-t-allow-onException-route-to-execute-completely-tp5750507.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using consumer.bridgeErrorHandler won't allow onException() route to execute completely.

Posted by ninadmnaik <nn...@gmail.com>.
Yeah, this works. Thanks Claus ! Don't know how I missed that.



--
View this message in context: http://camel.465427.n5.nabble.com/Using-consumer-bridgeErrorHandler-won-t-allow-onException-route-to-execute-completely-tp5750507p5750656.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using consumer.bridgeErrorHandler won't allow onException() route to execute completely.

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You need to use handled(true) in your onException block.

On Wed, Apr 23, 2014 at 7:21 PM, ninadmnaik <nn...@gmail.com> wrote:
> Hello,
>
> We are using "consumer.bridgeErrorHandler=true" in our route, so that if
> there's an exception during picking up of files, the Camel Error Handler can
> deal with it.
>
> It appears from the documentation and code snippet at:
> http://camel.apache.org/file2.html (Using consumer.bridgeErrorHandler
> section) that if there's an error picking up files, the "onException" clause
> will be invoked and will continue to execute the ".to("mock:error") clause.
>
> However, in our case, the "onException" clause is invoked, however the ".to"
> clause isn't. Here's how our code looks like:
>
>       onException(SomeException.class).process(new Processor()
>       {
>          @Override
>          public void process(Exchange exchange)
>          {
>          //Do some logging, processing etc.
>          }
>       }).to("direct:sendEmail");
>
> So, in the above code the ".to("direct:sendEmail")" part is never invoked.
>
> While I was debugging this, I found out that in
> BridgeExceptionHandlerToErrorHandler.java#handleException(String message,
> Exchange exchange, Throwable exception), Exchange.REDELIVERY_EXHAUSTED is
> set to true on Exchange:
>        // and mark as redelivery exhausted as we cannot do redeliveries
>         exchange.setProperty(Exchange.REDELIVERY_EXHAUSTED, Boolean.TRUE);
>
> This causes this exchange to get marked as "exhausted" in
> RedeliveryErrorHandler.java#processErrorHandler(final Exchange exchange,
> final AsyncCallback callback, final RedeliveryData data) and the
> ".to("direct:sendEmail")" part of the route is never processed.
>
> This isn't compliant with the documentation.
>
> So, the question is: do we need to set another property on the route to
> execute the complete route? Currently, we are just removing
> "Exchange.REDELIVERY_EXHAUSTED" from the exchange in our onException clause
>
>       onException(SomeException.class).process(new Processor()
>       {
>          @Override
>          public void process(Exchange exchange)
>          {
>              exchange.getProperties().remove(Exchange.REDELIVERY_EXHAUSTED);
>
>          }
>       }).to("direct:sendEmail");
>
>
>
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-consumer-bridgeErrorHandler-won-t-allow-onException-route-to-execute-completely-tp5750507.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
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
hawtio: http://hawt.io/
fabric8: http://fabric8.io/