Thanks Quinn.


I knew that "global" onException clauses are only scoped to their RouteBuilder.



Follow-up question: Why are they not working for a subroute inside the same 
RouteBuilder?



Context for other readers: In the following example, the onException clause 
works fine for the "direct:input" route, but not for the "direct:subroute" 
route. For the latter, the default ErrorHandler is used.



public void configure() throws Exception {

            onException(Throwable.class)

                                   .handled(true)

                                   [do error handling]

                                   .to("seda:error");



            from("direct:input")

                                   [do whatever needed]

                                   .to("direct:subroute")

                                   [do whatever needed]

                                   .to("seda:output");



            from("direct:subroute")

                                   [do whatever needed]

}



Thanks

Stephan





-----Ursprüngliche Nachricht-----
Von: Quinn Stevenson [mailto:qu...@pronoia-solutions.com]
Gesendet: Mittwoch, 20. Dezember 2017 20:41
An: users@camel.apache.org
Betreff: Re: MockEndpoint does not receive message if error occures in subroute



I’m not sure why this is working in the real world, but the reason the test is 
failing is the default error handler is picking up the exception from the call 
to the direct://Validate <direct://Validate> route.  If you add 
".errorHandler(new NoErrorHandlerBuilder())” to the direct://Validate 
<direct://Validate> route, your test will pass.



Quinn Stevenson

qu...@pronoia-solutions.com<mailto:qu...@pronoia-solutions.com>

(801) 244-7758







> On Dec 1, 2017, at 6:07 AM, Burkard Stephan 
> <stephan.burk...@visana.ch<mailto:stephan.burk...@visana.ch>> wrote:

>

> Hi Camel users

>

> I have attached a simplified example project (Maven) to illustrate a strange 
> problem I have in the tests of a current project.

>

> *** Setup ***

> - There is a Camel route that receives messages

> - It sends them to a validation subroute

> - The validation subroute uses a choice/when block to check a header

> value

>

> - If the header is ok, the message goes to the standard output

> endpoint

> - If the header is wrong, an exception is thrown and the error handler

> kicks in

> - The error handler sends the message to an alternative endpoint

>

> *** Problem ***

> If you open the project and run the route tests, you will see that one test 
> fails.

> - It sends a message with the wrong header, so an exception is thrown

> - In the console output you can see that the error route processes the

> message (as expected) ==> But the error endpoint mock does not receive

> the message (WHY? This is wrong!)

>

> *** It works in real life ***

> - When I run the real project with the real endpoints, the error

> endpoint produces the messages

> - It is only in the test this does not work

>

> *** Strange effect ***

> When I move the choice/when block from the subroute to the main route,

> the test is successful

>

> Can anyone explain this? Is this a bug or am I doing/expecting something 
> wrong?

>

> Thanks

> Stephan

>

>

> <CamelRouteTestDemo.zip>


Reply via email to