camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jorabin <jo.ra...@wiforia.com>
Subject Incorrect behavior of onCompletion for exception and stop
Date Fri, 15 Aug 2014 16:19:19 GMT
(Amplification of  a less specific post
<http://camel.465427.n5.nabble.com/Behavior-of-onCompletion-for-exception-fault-and-stop-td5754257.html>

)
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.ERRORHANDLER_HANDLED);                               
exchange.removeProperty(Exchange.ROUTE_STOP);                            }               
       
})                        .choice()                           
.when(simple("${body} == 'stop'"))                               
.log("stopping")                                .stop()                           
.when(simple("${body} == 'fault'"))                               
.log("faulting")                               
.setFaultBody(constant("faulted"))                           
.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");       
failed.expectedBodiesReceived("faulted");       
template().sendBody("direct:input","finish");       
template().sendBody("direct:input","stop");       
template().sendBody("direct:input","fault");       
template().sendBody("direct:input","except");        Thread.sleep(1000);       
assertMockEndpointsSatisfied();    }




--
View this message in context: http://camel.465427.n5.nabble.com/Incorrect-behavior-of-onCompletion-for-exception-and-stop-tp5755272.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message