You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Hilde <hi...@yahoo.de> on 2012/07/11 17:40:12 UTC

Exception handling within route chains

Hello!

We design different camel routes in different RouteBuilder classes and the
one is 
calling the other one:

RouteBuilder No. 1

@Override
public void configure() throws Exception {
	from("activemq:" + JmsDestinations.QUEUE_INIT_MAIN_ROUTE)
			.routeId("initMainRoute")
			.onException(Exception.class)
			.handled(true)
			.to("activemq:topic:" + JmsDestinations.TOPIC_LOG_SERVICE)
			.end()
			.to("direct:emptyDirectoryRoute")
			.setHeader("SUCCESS_INIT",
header(EmptyDirectoryDataReceived.IS_DIRECTORY_CLEANSED));
	}


RouteBuilder No. 2

@Override
public void configure() throws Exception {
	from("direct:emptyDirectoryRoute").routeId("emptyDirectoryRoute")
			.onException(Exception.class)
			.end()
			.bean(EmptyDirectoryDataReceived.class)
			.setBody(simple("${header." + DN1CamelHeader.PROTOCOL_DIRECTORY_CLEANING
+ "}"));
	}

How can we reach that the exception handling in route No. 1 catches and
handles all exceptions that are thrown in route No. 2?
Global scoped exception handling seems not an alternative because we have
many routes and exceptions should be handled individually.

Many thanks
Hilde


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

Re: Exception handling within route chains

Posted by Hilde <hi...@yahoo.de>.
Hello Claus!

YUHUUUUU I got it and it is working! Your last posting gave me a reality
check. Thanks a lot.

The following code snippet propagates the exception back to the calling
route:

RouteBuilder No. 1

@Override
public void configure() throws Exception {
	from("activemq:" + JmsDestinations.QUEUE_INIT_MAIN_ROUTE)
		.routeId("initMainRoute")
		.onException(Exception.class)
		.handled(true)
		.to("activemq:topic:" + JmsDestinations.TOPIC_LOG_SERVICE)
		.end()
		.to("*direct:emptyDirectoryRoute*")
		.setHeader("SUCCESS_INIT",
header(EmptyDirectoryDataReceived.IS_DIRECTORY_CLEANSED));
}

RouteBuilder No. 2

@Override
public void configure() throws Exception {
	from("*direct:emptyDirectoryRoute*").routeId("emptyDirectoryRoute")
		.errorHandler(noErrorHandler())				
		.bean(EmptyDirectoryDataReceived.class) *// throws an exception here*
		.setBody(simple("${header." + DN1CamelHeader.PROTOCOL_DIRECTORY_CLEANING +
"}"));
}

Thanks Thanks!
Hilde
	

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

Re: Exception handling within route chains

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Jul 12, 2012 at 9:28 AM, Hilde <hi...@yahoo.de> wrote:
> Hello!
>
> thanks for help.
>
> It is about how route scoped exception handling can catch exceptions thrown
> in other
> routes (to("direct:otherRoute")).
>

The 2nd route will NOT use a route scoped error handler from ANOTHER route.

You can though configure the "otherRoute" to not use any error handler
(eg noErrorHandler),
then it will not use the global error handler, but let any exceptions
be propagated back as-is
to the caller route, which then can react.


But just write some small camel routes and try for yourself. Thats the
best way to learn.

> What about exceptions thrown in Beans? Are they propagated to the camel
> route
> or do they have to handled in Java as usual?
>

Any bean/processor etc that throw an exception is propagated back to
the Camel routing engine,
which then lets its error handling kick in, and decide what to do.



> Hilde
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-within-route-chains-tp5715862p5715925.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 within route chains

Posted by Hilde <hi...@yahoo.de>.
Hello!

thanks for help.

It is about how route scoped exception handling can catch exceptions thrown
in other 
routes (to("direct:otherRoute")).

What about exceptions thrown in Beans? Are they propagated to the camel
route
or do they have to handled in Java as usual?

Hilde

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

Re: Exception handling within route chains

Posted by Christian Müller <ch...@gmail.com>.
I think Hilde means it's not possible for her because they have many routes
which different exception routes. So, using a global onException definition
is not insufficient.

@Hilde: You have to handle the exception in route 2. If it's not handled in
route 2, it's not propagated to route 1. In this case, the global exception
handler will be kicked in.

Best,
Christian

On Wed, Jul 11, 2012 at 6:41 PM, Claus Ibsen <cl...@gmail.com> wrote:

> When you use Java DSL, then use Java inheritance to have global scoped
> error handling.
>
> Create a base class that is a RouteBuilder, and do your global scoped
> error handling etc, in the configure method.
> And then invoke a abstract method, that your other routes extend and
> do their routing inside.
>
>
> On Wed, Jul 11, 2012 at 5:40 PM, Hilde <hi...@yahoo.de> wrote:
> > Hello!
> >
> > We design different camel routes in different RouteBuilder classes and
> the
> > one is
> > calling the other one:
> >
> > RouteBuilder No. 1
> >
> > @Override
> > public void configure() throws Exception {
> >         from("activemq:" + JmsDestinations.QUEUE_INIT_MAIN_ROUTE)
> >                         .routeId("initMainRoute")
> >                         .onException(Exception.class)
> >                         .handled(true)
> >                         .to("activemq:topic:" +
> JmsDestinations.TOPIC_LOG_SERVICE)
> >                         .end()
> >                         .to("direct:emptyDirectoryRoute")
> >                         .setHeader("SUCCESS_INIT",
> > header(EmptyDirectoryDataReceived.IS_DIRECTORY_CLEANSED));
> >         }
> >
> >
> > RouteBuilder No. 2
> >
> > @Override
> > public void configure() throws Exception {
> >         from("direct:emptyDirectoryRoute").routeId("emptyDirectoryRoute")
> >                         .onException(Exception.class)
> >                         .end()
> >                         .bean(EmptyDirectoryDataReceived.class)
> >                         .setBody(simple("${header." +
> DN1CamelHeader.PROTOCOL_DIRECTORY_CLEANING
> > + "}"));
> >         }
> >
> > How can we reach that the exception handling in route No. 1 catches and
> > handles all exceptions that are thrown in route No. 2?
> > Global scoped exception handling seems not an alternative because we have
> > many routes and exceptions should be handled individually.
> >
> > Many thanks
> > Hilde
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/Exception-handling-within-route-chains-tp5715862.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 within route chains

Posted by Claus Ibsen <cl...@gmail.com>.
When you use Java DSL, then use Java inheritance to have global scoped
error handling.

Create a base class that is a RouteBuilder, and do your global scoped
error handling etc, in the configure method.
And then invoke a abstract method, that your other routes extend and
do their routing inside.


On Wed, Jul 11, 2012 at 5:40 PM, Hilde <hi...@yahoo.de> wrote:
> Hello!
>
> We design different camel routes in different RouteBuilder classes and the
> one is
> calling the other one:
>
> RouteBuilder No. 1
>
> @Override
> public void configure() throws Exception {
>         from("activemq:" + JmsDestinations.QUEUE_INIT_MAIN_ROUTE)
>                         .routeId("initMainRoute")
>                         .onException(Exception.class)
>                         .handled(true)
>                         .to("activemq:topic:" + JmsDestinations.TOPIC_LOG_SERVICE)
>                         .end()
>                         .to("direct:emptyDirectoryRoute")
>                         .setHeader("SUCCESS_INIT",
> header(EmptyDirectoryDataReceived.IS_DIRECTORY_CLEANSED));
>         }
>
>
> RouteBuilder No. 2
>
> @Override
> public void configure() throws Exception {
>         from("direct:emptyDirectoryRoute").routeId("emptyDirectoryRoute")
>                         .onException(Exception.class)
>                         .end()
>                         .bean(EmptyDirectoryDataReceived.class)
>                         .setBody(simple("${header." + DN1CamelHeader.PROTOCOL_DIRECTORY_CLEANING
> + "}"));
>         }
>
> How can we reach that the exception handling in route No. 1 catches and
> handles all exceptions that are thrown in route No. 2?
> Global scoped exception handling seems not an alternative because we have
> many routes and exceptions should be handled individually.
>
> Many thanks
> Hilde
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-within-route-chains-tp5715862.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