camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jorabin <>
Subject Incorrect behavior of onCompletion for exception and stop
Date Fri, 15 Aug 2014 16:19:19 GMT
(Amplification of  a less specific post

a) following exception the onCompletion route runs but stops after the first
processor (seemingly because the property CamelErrorHandlerHandled is in the
copied exchange)
b) onCompletion following exception runs the onCompleteOnly() route not the
onFailureOnly() route 
c) following stop() the onCompletion doesn't run (seemingly because of the
presence of CamelRouteStop property in the copied exchange)
A work around to a) and c) is to remove the relevant properties  - in the
following example in a RoutePolicy
A unit test demonstrating this follows:
    @Test    public void onCompletionStopTest () throws Exception {       
RouteBuilder b = new RouteBuilder() {            @Override            public
void configure() throws Exception {               
onCompletion().onFailureOnly()                        .log("failing
${body}")                        .log("continuing to fail ${body}")                      

.to("mock:failed");                onCompletion().onCompleteOnly()                       
.log("completing ${body}")                        .log("continuing to
complete ${body}")                        .to("mock:complete");               
onException(Exception.class)                        .log("Handling
exception")                        .handled(true)                       
.end();                from("direct:input")                       
.routePolicy(new RoutePolicySupport() {                            @Override             
public void onExchangeDone(Route route, Exchange exchange) {                             
exchange.removeProperty(Exchange.ROUTE_STOP);                            }               
})                        .choice()                           
.when(simple("${body} == 'stop'"))                               
.log("stopping")                                .stop()                           
.when(simple("${body} == 'fault'"))                               
.when(simple("${body} == 'except'"))                               
.log("excepting")                                .throwException(new
Exception("Exception requested"))                        .end()                       
.log("finishing")                        .to("mock:end");            }       
};        context().addRoutes(b);        MockEndpoint end =
getMockEndpoint("mock:end");        end.expectedMessageCount(1);       
MockEndpoint complete = getMockEndpoint("mock:complete");        // except
should count as failure not completion       
complete.expectedBodiesReceived("finish", "stop", "except");       
MockEndpoint failed = getMockEndpoint("mock:failed");       
template().sendBody("direct:input","except");        Thread.sleep(1000);       
assertMockEndpointsSatisfied();    }

View this message in context:
Sent from the Camel - Users mailing list archive at
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message