Hi
I have been looking at onCompletion in 4 scenarios:
a) normal - exchange finishes normally
b) on exception - an exception is thrown and handled
c) stop is called in the route
d) the faultBody is set
It looks to me as though onCompletion is not triggered when stop is called
but is in the other circumstances. I'm wondering if this is by design and
why?
Also although the onCompletion is called on exception as shown by logging,
it doesn't seem that the exception reaches the mock:complete endpoint, as
shown by the assertion that only 2 messages are received is satisfied.
Thanks in advance for any enlightenment on this
Jo
The route is as follows
        RouteBuilder b = new RouteBuilder() {            @Override           
public void configure() throws Exception {                onCompletion()        
               
.log("completing ${body}")                        .to("mock:complete");         
      
from("direct:input")                        .onException(Exception.class)       
                    
.handled(true)                        .end()                       
.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);        //
System.out.println(ModelHelper.dumpModelAsXml(b.getRouteCollection()));       
MockEndpoint end = getMockEndpoint("mock:end");       
end.expectedMessageCount(1);        MockEndpoint complete =
getMockEndpoint("mock:complete");        complete.expectedMessageCount(2);
// SHOULD BE 4?        complete.expectedBodiesReceived("finish", "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();
the log output is as follows
14-07-22 18:48:03.263 [main] INFO  o.a.camel.impl.DefaultCamelContext -
Route: route1 started and consuming from: Endpoint[direct://input]14-07-22
18:48:03.875 [main] INFO  route1 - finishing14-07-22 18:48:03.881 [main]
INFO  route1 - stopping14-07-22 18:48:03.881 [Camel (camel-1) thread #0 -
OnCompletion] INFO  route1 - completing finish14-07-22 18:48:03.882 [main]
INFO  route1 - faulting14-07-22 18:48:03.883 [Camel (camel-1) thread #2 -
OnCompletion] INFO  route1 - completing faulted14-07-22 18:48:03.883 [main]
INFO  route1 - excepting14-07-22 18:48:03.894 [Camel (camel-1) thread #3 -
OnCompletion] INFO  route1 - completing except14-07-22 18:48:04.887 [main]
INFO  o.a.c.component.mock.MockEndpoint - Asserting: Endpoint[mock://end] is
satisfied14-07-22 18:48:04.887 [main] INFO 
o.a.c.component.mock.MockEndpoint - Asserting: Endpoint[mock://complete] is
satisfied




--
View this message in context: 
http://camel.465427.n5.nabble.com/Behavior-of-onCompletion-for-exception-fault-and-stop-tp5754257.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to