You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by kikou1984 <hi...@atos.net> on 2013/01/08 11:15:02 UTC
OnException Problem
Hi,
I followed this exemple on camel site.
"http://camel.apache.org/exception-clause.html".
I want to catch all Exception and stop the program when the first Exception
is catched.
Here the main program :
******************************************************
public void configure(){
onException(Exception.class).process(new
MyFunctionFailureHandler()).stop();
from("file:///D:/fileCamel/in?noop=true")
.bean(BeanTest.class, "myfonction")
.to("file:///D:/fileCamel/in");
}
******************************************************
Here the BeanTest:
******************************************************
public class BeanTest {
public void myfonction(Exchange exchange) throws Exception{
System.out.println("IN myfonction");
throw new Exception();
}
}
******************************************************
Here the class MyFunctionFailureHandler .
******************************************************
public class MyFunctionFailureHandler implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
Throwable caused;
caused = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
System.out.println("ERREUR EXCEPTION " + caused);
// send it to our mock endpoint
exchange.getContext().createProducerTemplate().send("mock:myerror",
exchange);
}
}
******************************************************
but it doesn't work .
Where should i put the "OnException(...) on the main program to catch
Exception and stop the program.
--
View this message in context: http://camel.465427.n5.nabble.com/OnException-Problem-tp5725110.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: OnException Problem
Posted by kikou1984 <hi...@atos.net>.
Ok I understood thxs
--
View this message in context: http://camel.465427.n5.nabble.com/OnException-Problem-tp5725110p5725135.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: OnException Problem
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
> onException(Exception.class).process(new MyFunctionFailureHandler()).stop();
The .stop() does not stop the program. It stops continue routing the
message. Though that is implied when you use onException anyway.
See this FAQ
http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html
You can then stop the route, or stop CamelContext, to stop Camel itself.
On Tue, Jan 8, 2013 at 11:15 AM, kikou1984 <hi...@atos.net> wrote:
> Hi,
>
> I followed this exemple on camel site.
> "http://camel.apache.org/exception-clause.html".
>
> I want to catch all Exception and stop the program when the first Exception
> is catched.
>
> Here the main program :
>
> ******************************************************
> public void configure(){
>
> onException(Exception.class).process(new
> MyFunctionFailureHandler()).stop();
>
> from("file:///D:/fileCamel/in?noop=true")
> .bean(BeanTest.class, "myfonction")
> .to("file:///D:/fileCamel/in");
> }
> ******************************************************
>
>
> Here the BeanTest:
> ******************************************************
> public class BeanTest {
>
>
> public void myfonction(Exchange exchange) throws Exception{
> System.out.println("IN myfonction");
> throw new Exception();
> }
> }
> ******************************************************
>
> Here the class MyFunctionFailureHandler .
>
> ******************************************************
> public class MyFunctionFailureHandler implements Processor {
>
> @Override
> public void process(Exchange exchange) throws Exception {
>
> Throwable caused;
> caused = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
> System.out.println("ERREUR EXCEPTION " + caused);
> // send it to our mock endpoint
> exchange.getContext().createProducerTemplate().send("mock:myerror",
> exchange);
> }
>
> }
> ******************************************************
>
> but it doesn't work .
> Where should i put the "OnException(...) on the main program to catch
> Exception and stop the program.
>
>
>
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/OnException-Problem-tp5725110.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen