ammachado opened a new pull request, #31060: URL: https://github.com/apache/camel/pull/31060
# Description Follow-up of [CAMEL-25135](https://issues.apache.org/jira/browse/CAMEL-25135) (#27430), fixing [CAMEL-25420](https://issues.apache.org/jira/browse/CAMEL-25420). **Problem.** The CAMEL-25135 dedup of a route configuration's `onCompletion` depends on the `routeConfiguration` back-reference, and only the fluent Java `RouteConfigurationDefinition.onCompletion()` sets it. The YAML (`RouteConfigurationDefinitionDeserializer`) and XML (`ModelParser`, JAXB for Spring XML) DSLs call `setOnCompletions()` instead, so: - **named configurations**: the `configurationId` dedup never applied. The `onCompletion` fired once for each opted-in route of the exchange (and BeforeConsumer could fire first from the sub-route). - **global configurations** (no `id`, or `*`): kept the model default `routeScoped=true`, so they fired for every route of the exchange, e.g. twice for `from(a).to("direct:b")`. The ticket does not mention this case, and the Java DSL sets `routeScoped=false` for it. **Fix.** In `RouteDefinitionHelper.getRouteConfigurationDefinitionConsumer()`, the merge point used by both `RoutesDefinition.prepareRoute()` and `AbstractCamelContextFactoryBean`, an `OnCompletionDefinition` without a back-reference gets one, and `routeScoped=false` when the configuration is global. This is the same decision the fluent method makes. It runs at merge time rather than in the setter because in YAML `id` may come after `onCompletion`. Definitions built with the Java DSL already have the back-reference and are not touched. **Tests.** Each new test fails without the fix (fires 2× instead of 1×) and passes with it: - `RoutesConfigurationOnCompletionSetterTest` (camel-core): the `setOnCompletions` path for global, `*`, named (indirect consumer, both routes opted in) and BeforeConsumer. - `XmlRouteConfigurationOnCompletionTest` (camel-xml-io-dsl): named and global. - `RouteConfigurationTest` (camel-yaml-dsl): global, and named with `id` after `onCompletion`. The full camel-core suite passes (9973 tests, 0 failures, 44 skipped that were already skipped before this change), as do the existing CAMEL-25135 tests and the YAML dump tests. **Upgrade guide.** Added a 4.24 entry: YAML/XML route configuration `onCompletion` no longer fires once per route. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. Not from the root folder: I built `core/camel-core-model`, `core/camel-core`, `core/camel-xml-io`, `dsl/camel-xml-io-dsl` and `dsl/camel-yaml-dsl/camel-yaml-dsl` with their upstream modules and ran `mvn formatter:format impsort:sort` on the changed modules. `git status` was clean afterwards. The change touches no generated files. # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. 🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of Adriano Machado (@ammachado) _This was generated by an AI agent and may contain inaccuracies. Please verify before relying on it._ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
