You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by XiaoPeng Li <xp...@talend.com> on 2012/03/07 10:07:28 UTC
endDoTry() problem
Hi,
I had some problems when I tried "endDoTry()" in my RouteBuilder. Here are the codes:
from("timer://myTimer?period=2000").setBody()
.simple("Current time is ${header.firedTime}").doTry()
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
throw new Exception("Customized");
}
}).setBody(constant("No Exception")).to("log:no-error")
.to("file://c:/data/input/cFile").endDoTry()
.doCatch(Exception.class).to("log:catch");
}
will cause an Exception:
Exception in thread "main" java.lang.ClassCastException: org.apache.camel.model.RouteDefinition cannot be cast to org.apache.camel.model.TryDefinition
And even worse, if we add some other routing nodes to Route, for example:
from("timer://myTimer?period=2000").setBody()
.simple("Current time is ${header.firedTime}").doTry()
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
throw new Exception("Customized");
}
}).setBody(constant("No Exception")).to("log:no-error")
.loadBalance().random().to("log:load1").to("log:load1")
.to("file://c:/data/input/cFile").endDoTry()
.doCatch(Exception.class).to("log:catch");
}
after loadBalance(), there will be no exception.
I believe it's a camel bug, and here is similar bug https://issues.apache.org/jira/browse/CAMEL-4517 with endChoice().
My question is: will camel fix this problem to make sure it's OK to use endDoTry() in all cases?
Best Regards
Xiaopeng Li
Re: endDoTry() problem
Posted by kamranzafar <xe...@gmail.com>.
Thanks, this is now working with global onException.
--
View this message in context: http://camel.465427.n5.nabble.com/endDoTry-problem-tp5543541p5743110.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: endDoTry() problem
Posted by Claus Ibsen <cl...@gmail.com>.
Instead of doTry doCatch then just use an onException in the route.
On Tue, Nov 12, 2013 at 11:35 AM, kamranzafar <xe...@gmail.com> wrote:
> Just tried it with end() on split but still doesn't work. Still gives the
> same exception.
>
> from("jpa:org.example.SystemProperty?consumeDelete=true&consumer.namedQuery=ControlProductLoadTrigger")
> .routeId(getClass().getSimpleName()).doTry().process(new Processor()
> {
> @Override
> public void process(Exchange exchange) throws Exception {
> List<Product> products = fetchProducts();
> exchange.getIn().setBody(products);
> }
> }).split(body()).to("jpa:org.example.Product")*.end().*endDoTry().doCatch(Throwable.class)
> .transform().simple("${exception.message}").log(LoggingLevel.ERROR,
> "${body}").end();
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/endDoTry-problem-tp5543541p5743093.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
Re: endDoTry() problem
Posted by kamranzafar <xe...@gmail.com>.
Just tried it with end() on split but still doesn't work. Still gives the
same exception.
from("jpa:org.example.SystemProperty?consumeDelete=true&consumer.namedQuery=ControlProductLoadTrigger")
.routeId(getClass().getSimpleName()).doTry().process(new Processor()
{
@Override
public void process(Exchange exchange) throws Exception {
List<Product> products = fetchProducts();
exchange.getIn().setBody(products);
}
}).split(body()).to("jpa:org.example.Product")*.end().*endDoTry().doCatch(Throwable.class)
.transform().simple("${exception.message}").log(LoggingLevel.ERROR,
"${body}").end();
--
View this message in context: http://camel.465427.n5.nabble.com/endDoTry-problem-tp5543541p5743093.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: endDoTry() problem
Posted by Claus Ibsen <cl...@gmail.com>.
You need to end the split also.
On Mon, Nov 11, 2013 at 6:56 PM, kamranzafar <xe...@gmail.com> wrote:
> Thanks for replying, doTry is there in the route. The only reason I used
> "endDoTry" is because I need to split the exchange body before persistence.
> It won't let me use split without "endDoTry".
>
> from("jpa:org.example.SystemProperty?consumeDelete=true&consumer.namedQuery=ControlProductLoadTrigger")
> .routeId(getClass().getSimpleName()).*doTry()*.process(new
> Processor() {
> @Override
> public void process(Exchange exchange) throws Exception {
> List<Product> products = fetchProducts();
> exchange.getIn().setBody(products);
> }
> }).*split(body())*.to("jpa:org.example.Product").endDoTry().doCatch(Throwable.class)
> .transform().simple("${exception.message}").log(LoggingLevel.ERROR,
> "${body}").end();
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/endDoTry-problem-tp5543541p5743054.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
Re: endDoTry() problem
Posted by kamranzafar <xe...@gmail.com>.
Thanks for replying, doTry is there in the route. The only reason I used
"endDoTry" is because I need to split the exchange body before persistence.
It won't let me use split without "endDoTry".
from("jpa:org.example.SystemProperty?consumeDelete=true&consumer.namedQuery=ControlProductLoadTrigger")
.routeId(getClass().getSimpleName()).*doTry()*.process(new
Processor() {
@Override
public void process(Exchange exchange) throws Exception {
List<Product> products = fetchProducts();
exchange.getIn().setBody(products);
}
}).*split(body())*.to("jpa:org.example.Product").endDoTry().doCatch(Throwable.class)
.transform().simple("${exception.message}").log(LoggingLevel.ERROR,
"${body}").end();
--
View this message in context: http://camel.465427.n5.nabble.com/endDoTry-problem-tp5543541p5743054.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: endDoTry() problem
Posted by Claus Ibsen <cl...@gmail.com>.
endDoTry() is only needed in some cases if you use doTry .. doCatch.
And you must have a doTry, which you do NOT have.
On Mon, Nov 11, 2013 at 6:17 PM, kamranzafar <xe...@gmail.com> wrote:
> Hi I am having the same issue in camel version 2.10.2. The route below throws
> exception
>
> from("jpa:org.example.SystemProperty?consumeDelete=true&consumer.namedQuery=ControlProductLoadTrigger")
> .routeId(getClass().getSimpleName()).doTry().process(new Processor()
> {
> @Override
> public void process(Exchange exchange) throws Exception {
> List<Product> products = fetchProducts();
> exchange.getIn().setBody(products);
> }
> }).split(body()).to("jpa:org.example.Product").endDoTry().doCatch(Throwable.class)
> .transform().simple("${exception.message}").log(LoggingLevel.ERROR,
> "${body}").end();
>
> This gives me:
>
> java.lang.ClassCastException: org.apache.camel.model.RouteDefinition cannot
> be cast to org.apache.camel.model.TryDefinition
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/endDoTry-problem-tp5543541p5743050.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
Re: endDoTry() problem
Posted by kamranzafar <xe...@gmail.com>.
Hi I am having the same issue in camel version 2.10.2. The route below throws
exception
from("jpa:org.example.SystemProperty?consumeDelete=true&consumer.namedQuery=ControlProductLoadTrigger")
.routeId(getClass().getSimpleName()).doTry().process(new Processor()
{
@Override
public void process(Exchange exchange) throws Exception {
List<Product> products = fetchProducts();
exchange.getIn().setBody(products);
}
}).split(body()).to("jpa:org.example.Product").endDoTry().doCatch(Throwable.class)
.transform().simple("${exception.message}").log(LoggingLevel.ERROR,
"${body}").end();
This gives me:
java.lang.ClassCastException: org.apache.camel.model.RouteDefinition cannot
be cast to org.apache.camel.model.TryDefinition
--
View this message in context: http://camel.465427.n5.nabble.com/endDoTry-problem-tp5543541p5743050.html
Sent from the Camel - Users mailing list archive at Nabble.com.