Search code examples
apache-camelonexception

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


Solution

  • 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);