You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by smadarapu <sr...@adp.com> on 2012/07/12 15:57:59 UTC

Exception handling in Camel Routes.

Hi

Seems like this is a basic feature, but I cant get it working as i expected.

I have this route defined using Java DSL...

from(endPointURI).delay(5000)
     .routeId(routeId)
    
/.onException(Throwable.class).handled(true).process(*getInputfileExceptionHandler()*).end()/
     .process(updateHeadersForInputfileProcess(tenantId))
     .to("bean:taskCreator")
    
.wireTap("bean:inputFileRouteLifeCycle?method=startChangeSetProcessing(" +
routeId + ", ${header.task} )")
     .to("bean:taskAppenderCreator");

When a message gets to this route, the first thing getting executed is the
code in the Processor that is returned by getInputfileExceptionHandler().
Then it starts executing the other steps, and when there is an exception in
the other steps the exception handler is not getting called at all.

What am I missing here?

Thanks
Srikanth

--
View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-in-Camel-Routes-tp5715952.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Exception handling in Camel Routes.

Posted by Christian Müller <ch...@gmail.com>.
Could you have a look at [1]? There are many tests which make sure it works.
And if it doesn't work for you, could you please attach a test which
indicate this. With a test it's much more easier for us to check what's
going wrong - in your code or in Camel. And at the end, you will have a
solution in a shorter time.

[1]
https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/

Best,
Christian

On Mon, Jul 16, 2012 at 6:20 PM, smadarapu <sr...@adp.com>wrote:

> Hi Christian,
>
> If you read my initial post, my question is what am I missing. I had what
> you suggested but its not working.
> Christian Mueller wrote
> >
> > It's documented here [1].
> >
> > You can e.g. do:
> > from("direct:start")
> >
> >
> .onException(MyTechnicalException.class).maximumRedeliveries(0).handled(true).end()
> >
> >
> .onException(MyFunctionalException.class).maximumRedeliveries(0).handled(true).to("bean:myOwnHandler").end()
> >   .choice()
> >     .when().xpath("//type = 'myType'").to("bean:myServiceBean")
> >   .end()
> >   .to("mock:result");
> >
> >
> > [1] http://camel.apache.org/exception-clause.html
> >
> > Best,
> > Christian
> >
> > On Fri, Jul 13, 2012 at 5:57 PM, smadarapu
> > &lt;srikanth.madarapu@&gt;wrote:
> >
> >> Can you please elaborate "A route can have a N+ route scoped
> >> onException's.
> >> That is possible."
> >>
> >> In my case when I had the onException on the route, whatever the code i
> >> put
> >> for onException got executed immediately after a message arrived to that
> >> route (without an actual exception), and not when that exception really
> >> happened.
> >>
> >> --
> >> View this message in context:
> >>
> http://camel.465427.n5.nabble.com/Exception-handling-in-Camel-Routes-tp5715952p5716018.html
> >> Sent from the Camel - Users mailing list archive at Nabble.com.
> >>
> >
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Exception-handling-in-Camel-Routes-tp5715952p5716089.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Exception handling in Camel Routes.

Posted by smadarapu <sr...@adp.com>.
Hi Christian,

If you read my initial post, my question is what am I missing. I had what
you suggested but its not working. 
Christian Mueller wrote
> 
> It's documented here [1].
> 
> You can e.g. do:
> from("direct:start")
> 
> .onException(MyTechnicalException.class).maximumRedeliveries(0).handled(true).end()
> 
> .onException(MyFunctionalException.class).maximumRedeliveries(0).handled(true).to("bean:myOwnHandler").end()
>   .choice()
>     .when().xpath("//type = 'myType'").to("bean:myServiceBean")
>   .end()
>   .to("mock:result");
> 
> 
> [1] http://camel.apache.org/exception-clause.html
> 
> Best,
> Christian
> 
> On Fri, Jul 13, 2012 at 5:57 PM, smadarapu
> &lt;srikanth.madarapu@&gt;wrote:
> 
>> Can you please elaborate "A route can have a N+ route scoped
>> onException's.
>> That is possible."
>>
>> In my case when I had the onException on the route, whatever the code i
>> put
>> for onException got executed immediately after a message arrived to that
>> route (without an actual exception), and not when that exception really
>> happened.
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Exception-handling-in-Camel-Routes-tp5715952p5716018.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
> 


--
View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-in-Camel-Routes-tp5715952p5716089.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Exception handling in Camel Routes.

Posted by Christian Müller <ch...@gmail.com>.
It's documented here [1].

You can e.g. do:
from("direct:start")

.onException(MyTechnicalException.class).maximumRedeliveries(0).handled(true).end()

.onException(MyFunctionalException.class).maximumRedeliveries(0).handled(true).to("bean:myOwnHandler").end()
  .choice()
    .when().xpath("//type = 'myType'").to("bean:myServiceBean")
  .end()
  .to("mock:result");


[1] http://camel.apache.org/exception-clause.html

Best,
Christian

On Fri, Jul 13, 2012 at 5:57 PM, smadarapu <sr...@adp.com>wrote:

> Can you please elaborate "A route can have a N+ route scoped onException's.
> That is possible."
>
> In my case when I had the onException on the route, whatever the code i put
> for onException got executed immediately after a message arrived to that
> route (without an actual exception), and not when that exception really
> happened.
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Exception-handling-in-Camel-Routes-tp5715952p5716018.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Exception handling in Camel Routes.

Posted by smadarapu <sr...@adp.com>.
Can you please elaborate "A route can have a N+ route scoped onException's.
That is possible."

In my case when I had the onException on the route, whatever the code i put
for onException got executed immediately after a message arrived to that
route (without an actual exception), and not when that exception really
happened.

--
View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-in-Camel-Routes-tp5715952p5716018.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Exception handling in Camel Routes.

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Jul 12, 2012 at 6:09 PM, smadarapu <sr...@adp.com> wrote:
> I think i figured it out, the "onException" set up is per RouteBuilder and
> not per Route, so I removed the onException setup from route to the route
> builder and it is working as i want it.
>
> What i still don't understand is why does the Route definition supports the
> "onException" setup, what is the purpose?
>
> Also the per route builder setup adds a limitation that I cannot have the
> definition of two routes (in the same RouteBuilder class) that need
> different handling of the same exception.
>

A route can have a N+ route scoped onException's. That is possible.

If you put onException outside (from) then its scoped for the current
RouteBuilder class.


> Thanks
> Srikanth
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-in-Camel-Routes-tp5715952p5715962.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Exception handling in Camel Routes.

Posted by Willem Jiang <wi...@gmail.com>.
You can use the try ... catch ... finally DSL[1]  if you want to check 
the exception you want per route.
The "onException" is a more generic way to handle the exception per 
RouteBuilder.

[1]http://camel.apache.org/try-catch-finally.html


On Fri Jul 13 00:09:02 2012, smadarapu wrote:
> I think i figured it out, the "onException" set up is per RouteBuilder and
> not per Route, so I removed the onException setup from route to the route
> builder and it is working as i want it.
>
> What i still don't understand is why does the Route definition supports the
> "onException" setup, what is the purpose?
>
> Also the per route builder setup adds a limitation that I cannot have the
> definition of two routes (in the same RouteBuilder class) that need
> different handling of the same exception.
>
> Thanks
> Srikanth
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-in-Camel-Routes-tp5715952p5715962.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
         http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang


Re: Exception handling in Camel Routes.

Posted by smadarapu <sr...@adp.com>.
I think i figured it out, the "onException" set up is per RouteBuilder and
not per Route, so I removed the onException setup from route to the route
builder and it is working as i want it.

What i still don't understand is why does the Route definition supports the
"onException" setup, what is the purpose?

Also the per route builder setup adds a limitation that I cannot have the
definition of two routes (in the same RouteBuilder class) that need
different handling of the same exception.

Thanks
Srikanth

--
View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-in-Camel-Routes-tp5715952p5715962.html
Sent from the Camel - Users mailing list archive at Nabble.com.