shashank created CAMEL-27283:
--------------------------------

             Summary: camel-core - Dynamic Router: an exception of the router 
expression after the second step is lost and the message goes on as a success
                 Key: CAMEL-27283
                 URL: https://issues.apache.org/jira/browse/CAMEL-27283
             Project: Camel
          Issue Type: Bug
          Components: camel-core
            Reporter: shashank
            Assignee: shashank


h3. What happens

RoutingSlip (used by the Routing Slip and the Dynamic Router EIPs) wraps every 
step in the error handler of the route, and {{RedeliveryErrorHandler.process}} 
always returns {{false}}, so from the second step on the EIP goes on in 
{{continueRoutingSlip}}, the code for a step that completed asynchronously. 
That code differs from the synchronous loop:

# The {{catch}} sets an exception on {{stepExchange}}, the exchange the step 
ran on, which is a copy of the message unless the step was the first one. When 
the expression of a Dynamic Router throws (a bean method annotated with 
{{@DynamicRouter}}, a custom {{Expression}}, any expression that throws instead 
of setting the exception), the original callback is called with the message as 
it was after an earlier step and without the exception: no onException, no dead 
letter channel, the consumer commits (file moved to .done, JMS message acked), 
the reply of the last step is dropped, and the route goes on after the 
{{dynamicRouter}} as if the router had returned null.
# After a failed step the router expression is called once more with the failed 
exchange before the EIP stops (the synchronous loop checks the failure first).
# {{ignoreInvalidEndpoints}} is applied only at the top of the next iteration, 
so an invalid last endpoint ({{FailedToCreateProducerException}}) fails the 
message.

h3. How to reproduce

{{from("direct:start").dynamicRouter(expr).to("mock:result")}} where the 
expression returns {{direct:foo}}, {{direct:bar}} and then throws 
{{IllegalStateException}}: mock:result receives the message with the body of 
the second step and no exception; onException is not called. The same with 
{{.bean(router, "route")}} and a method annotated with {{@DynamicRouter}}. With 
{{routingSlip(header("slip")).ignoreInvalidEndpoints()}} and slip 
{{direct:foo,file:x?fileExist=Append&tempPrefix=a}} the message fails with 
FailedToCreateProducerException.

h3. Fix

{{continueRoutingSlip}} sets the exception on the original exchange, and after 
each step it applies ignoreInvalidEndpoints and checks for a failure before it 
asks the router for the next step, as the synchronous loop does.

_Filed with Claude Code on behalf of allthingssecurity._



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to