Claus Ibsen created CAMEL-28100:
-----------------------------------
Summary: camel-core - intercept is lost when a route is created
again from its definition, and should not intercept the steps of onCompletion
Key: CAMEL-28100
URL: https://issues.apache.org/jira/browse/CAMEL-28100
Project: Camel
Issue Type: Bug
Components: camel-core
Reporter: Claus Ibsen
Fix For: 4.25.0
h3. 1. intercept is lost when the route is created again (bug)
{{InterceptReifier}} removes its definition from the route outputs
({{core/camel-core-reifier/src/main/java/org/apache/camel/reifier/InterceptReifier.java:89}}).
Every path that creates the route again from the same {{RouteDefinition}}
therefore loses the intercept:
* {{CamelContext}} {{stop()}} + {{start()}} on the same instance (verified with
a test, also for an intercept from a route configuration);
* {{removeRouteDefinition}} + {{addRouteDefinition}} of the same definition;
* {{AdviceWith}} after the context started, for a RouteBuilder-level intercept.
onException, onCompletion, interceptFrom and interceptSendToEndpoint survive a
restart. A route stop/start through the {{RouteController}} keeps the intercept.
Proposed fix:
* Keep the definition in the route and return no processor, as
{{InterceptSendToEndpointReifier}} has done since CAMEL-25140.
* Make the {{first}} flag in {{ProcessorReifier}} (lines 699-708,
{{route.getOutputs().get(0) == definition}}) skip the abstract outputs
(onException, intercept, interceptFrom, interceptSendToEndpoint, onCompletion).
Otherwise a kept intercept makes the first real step "not first". From reading
the code, this is already wrong for a route whose first output is a merged
onException, interceptSendToEndpoint or onCompletion, which affects the
BacklogDebugger {{_all_routes_}} initial breakpoint.
h3. 2. intercept is for the main route path: do not intercept the steps of
onCompletion (behaviour change)
After a route is prepared, its outputs are: onException,
interceptSendToEndpoint, interceptFrom, intercept, onCompletion, then the route
steps. Each {{Channel}} only gets the intercept strategies that exist when it
is built, so what the intercept reaches depends on that order:
* the steps of onException, interceptFrom and interceptSendToEndpoint are not
intercepted;
* the onCompletion step and the steps inside onCompletion are intercepted.
intercept is meant for the main route path, so the steps of onCompletion should
not be intercepted either.
* Tests that pin today's counts: {{OnCompletionAndInterceptTest}},
{{OnCompletionAndInterceptGlobalTest}},
{{OnCompletionAndInterceptAndOnExceptionGlobalTest}} in camel-core and their
{{SpringOnCompletionAndIntercept*Test}} copies in camel-spring-xml (for example
5 and 4 intercepted steps become 2 and 1).
* {{intercept.adoc}} says "every processing step"; it should say which steps:
the steps of the main route path, not those of onException, onCompletion,
interceptFrom and interceptSendToEndpoint.
* Upgrade guide 4.25 entry.
Also pin today's semantics with tests before changing anything: which steps are
intercepted, the order of several intercepts (from reading the code, the
intercepts of a route configuration run in reverse declaration order and before
the RouteBuilder ones), restart, removing and adding the same definition, and
AdviceWith.
Found while analysing CAMEL-25142 (late binding of cross-cutting features),
with probe tests on main (4a354d948e9c).
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)