Sammy
Sammy

Reputation: 1218

onCompletion in Camel 2.14

I'd like to wrap the result of a processed message into some reply-object to answer a webservice. This is my test-route:

this.from("cxf:someEndpoint")
        .process(new SomeProcessorThatMightThrowAnException())
        .process(new SomeOtherProcessorThatMightThrowAnException())
        .log("normal end of route");

Nevermind if there was an exception or not, the result should be wrapped in some object, that is given back to the caller of my ws.

In camel 2.13.x I did this by adding an other processor to the end of the route and to do the same in 'onException'.
Now I tried to simplify this (technical thing and handle it outside of the 'functional route') in camel 2.14 (2.14 because of 'modeBeforeConsumer'), and added this to my routebuilder:

onCompletion()
    .modeBeforeConsumer()
    .process(new ConvertToWsReplyProcessor());

This ConvertToWsReplyProcessor should handle an Exception, but I found no way to see, if there was an Exception, because exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class) is allways null.

Questions:
1) Is there a way to find out if there was an excetion in onCompletion()?
2) The only way I found to prevent camel from dumping a stacktrace is to use onException(Ex...).handled(true), are there others? 3) How are these onXY processed? Do they get a copy of the exchange? And is onCompletion called last?

Upvotes: 0

Views: 612

Answers (1)

Willem Jiang
Willem Jiang

Reputation: 3291

OnCompletionProcessor just remove some exchange properties before processing the exchange, that could explain why you cannot fine the exception here.

As camel use onException to handle the exception, I'm afraid you have to do it that way.

Upvotes: 1

Related Questions