Hi,I have the follow routes that StartRoute process an Order, splitting itens
and call direct:processItem route to process itens.
I have an aggregation to aggregate results.
When processItem route catch an Exception (throw by MyService.class) with
.OnException(Exception.class) .handle(true) .log("Error on item");
my aggregation class agregate results (OK) but the code after split never
run
.log("split end").log("${body}").process(new ServletProcessor());
My code:
@Component public class StartRoute extends SpringRouteBuilder { @Override
public void configure() throws Exception { XPathBuilder xPath =
xpath("/order/itens/item"); errorHandler(defaultErrorHandler()
.maximumRedeliveries(3) .redeliveryDelay(1000)
.retryAttemptedLogLevel(LoggingLevel.ERROR));
onException(Exception.class) .handled(true)
.log("something wrong"); from("cxfrs:bean:rsServer").routeId("startRoute")
.to("bean:myService?method=process") .split(xPath, ,new
MyAggregation()) .to("direct:processItem") .end()
.log("split end") .log("${body}") .process(new
ServletProcessor()); } }
@Componentpublic class AnotherRoute extends SpringRouteBuilder { @Override
public void configure() throws Exception { onException(Exception.class)
.handled(true) .log("Error on item");
from("direct:processItem").routeId("processItemRoute") .log("${body}")
.bean(MyService.class) .log("ending route"); }}
public class MyAggregation implements AggregationStrategy { @Override public
Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
if(oldExchange == null) { return newExchange; } else { String oldBody =
oldExchange.getIn().getBody(String.class); String newBody =
newExchange.getIn().getBody(String.class); String catBody =
oldBody+newBody; oldExchange.getIn().setBody(catBody); } return
oldExchange; }}
If i remove Aggregation from split or change processItemRoute to use
Try...catch, everythings works fine.My processItem route with try...catch
and with that works ok.
@Componentpublic class AnotherRoute extends SpringRouteBuilder { @Override
public void configure() throws Exception {
from("direct:processItem").routeId("processItemRoute") .log("${body}")
.doTry() .bean(MyService.class) .doCatch(Exception.class)
.log("error") .doFinally() .log("ending route") .end(); }}
Whats the diference between .onException and try..catch, that second one
works fine for me?Is there any problem with my aggregation code ?I want to
use .onException because clean my route code.Thanks,Paulo
and call direct:processItem route to process itens.
I have an aggregation to aggregate results.
When processItem route catch an Exception (throw by MyService.class) with
.OnException(Exception.class) .handle(true) .log("Error on item");
my aggregation class agregate results (OK) but the code after split never
run
.log("split end").log("${body}").process(new ServletProcessor());
My code:
@Component public class StartRoute extends SpringRouteBuilder { @Override
public void configure() throws Exception { XPathBuilder xPath =
xpath("/order/itens/item"); errorHandler(defaultErrorHandler()
.maximumRedeliveries(3) .redeliveryDelay(1000)
.retryAttemptedLogLevel(LoggingLevel.ERROR));
onException(Exception.class) .handled(true)
.log("something wrong"); from("cxfrs:bean:rsServer").routeId("startRoute")
.to("bean:myService?method=process") .split(xPath, ,new
MyAggregation()) .to("direct:processItem") .end()
.log("split end") .log("${body}") .process(new
ServletProcessor()); } }
@Componentpublic class AnotherRoute extends SpringRouteBuilder { @Override
public void configure() throws Exception { onException(Exception.class)
.handled(true) .log("Error on item");
from("direct:processItem").routeId("processItemRoute") .log("${body}")
.bean(MyService.class) .log("ending route"); }}
public class MyAggregation implements AggregationStrategy { @Override public
Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
if(oldExchange == null) { return newExchange; } else { String oldBody =
oldExchange.getIn().getBody(String.class); String newBody =
newExchange.getIn().getBody(String.class); String catBody =
oldBody+newBody; oldExchange.getIn().setBody(catBody); } return
oldExchange; }}
If i remove Aggregation from split or change processItemRoute to use
Try...catch, everythings works fine.My processItem route with try...catch
and with that works ok.
@Componentpublic class AnotherRoute extends SpringRouteBuilder { @Override
public void configure() throws Exception {
from("direct:processItem").routeId("processItemRoute") .log("${body}")
.doTry() .bean(MyService.class) .doCatch(Exception.class)
.log("error") .doFinally() .log("ending route") .end(); }}
Whats the diference between .onException and try..catch, that second one
works fine for me?Is there any problem with my aggregation code ?I want to
use .onException because clean my route code.Thanks,Paulo