Yamahar1sp
Yamahar1sp

Reputation: 510

onException and onCompletion together in RouteBuilder`s route

I would like to use OnException & OnComplition together in one route (Camel version 2.10.0.redhat-60024):

from("direct:camelTestEndpoint").
            onCompletion().
                log("onCompletion1").
                log("onCompletion2").
                log("onCompletion3").
            end().
            onException(Throwable.class).
                handled(true).
                log("onException").
            end().

            log("route")
            .throwException(new RuntimeException());

Although it does not work as I expect. Exception in main route causes onComplition route to stop after first processor (it is handled in PipelineHelper`s continueProcessing() method). Camel checks if exception was handled and if yes - stops the processing.

Output:

route
onException
onCompletion1

Is there I gentle way to say camel that it should skip this (without "CamelErrorHandlerHandled" property removal)?

Thanks

Upvotes: 2

Views: 5578

Answers (2)

vks
vks

Reputation: 199

//STEP1: call Successful Route
   from("direct:Route_OnCompletion_OnSuccess")
        .onCompletion()
          .onCompleteOnly()
            .log("On Complete Passed")
            .to("direct:Route_OnSuccess")
        .end()
        .to("direct:Route_OnCompletion_OnFailure");

//STEP2: call Failure Route                
    from("direct:Route_OnCompletion_OnFailure")
        .onCompletion()           
            .onFailureOnly()    
                .log("On Complete Failed "+ body())
                .to("direct:Route_OnFailure")       
        .end() 
        .to("direct:Route_MainFlow");

Upvotes: 0

Claus Ibsen
Claus Ibsen

Reputation: 55555

This is a bug in that version of Camel.

This has been fixed by CAMEL-7707.

As a workaround you would need to manually remove those details from the exchange, in the first process in the onCompletion you do.

For example something a like

    // must remember some properties which we cannot use during onCompletion processing
    // as otherwise we may cause issues
    Object stop = exchange.removeProperty(Exchange.ROUTE_STOP);
    Object failureHandled = exchange.removeProperty(Exchange.FAILURE_HANDLED);
    Object caught = exchange.removeProperty(Exchange.EXCEPTION_CAUGHT);
    Object errorhandlerHandled = exchange.removeProperty(Exchange.ERRORHANDLER_HANDLED);

Upvotes: 1

Related Questions