ammachado opened a new pull request, #28648: URL: https://github.com/apache/camel/pull/28648
# Description [CAMEL-26389](https://issues.apache.org/jira/browse/CAMEL-26389), tier 1 item #2 of [CAMEL-25132](https://issues.apache.org/jira/browse/CAMEL-25132). When redelivery is enabled (`maximumRedeliveries != 0`, `retryWhile`, or an `onException` with redeliveries), `RedeliveryTask.prepare` called `defensiveCopyExchangeIfNeeded`, which copies the whole `Exchange` before every node, also when the node succeeds. A redelivery only ever reads `original.getIn()` from that copy (`prepareExchangeForRedelivery`). This change keeps `exchange.getIn().copy()` instead. This is the same message copy as before: the `AbstractExchange` copy constructor makes its IN message with `parent.getIn().copy()`. What is no longer done per node is the rest of the exchange copy: the internal properties `EnumMap`, exchange properties, variables (an `ExchangeVariableRepository`), safe copy properties and message history. The only other difference is the exchange that the stored message refers to, and `copyFrom` does not use it, because the target message (`exchange.getIn()`) already has its exchange. Routes behave as before: exchange properties and variables were never restored on redelivery. CAMEL-25132 measured 8712 → 2408 bytes and 1550 → 1158 ns per exchange on a 10-node route with `maximumRedeliveries(3)`. The protected `defensiveCopyExchangeIfNeeded` is deprecated and no longer called. Nothing in the repository overrides it (`DefaultErrorHandler`, `DeadLetterChannel` and the camel-spring and camel-jta transaction error handlers inherit it). Since an override elsewhere would be silently ignored, the 4.24 upgrade guide has an entry for it. Tests in the new `RedeliveryErrorHandlerCopyInMessageTest`: - `testSuccessPathDoesNotCopyExchange`: a counting `SafeCopyProperty` (whose `safeCopy()` runs on every exchange copy) on a route with redelivery enabled. It counted 3 copies (one per node) before this change, and counts 0 now. The route does not use `mock:` endpoints, because `MockEndpoint` copies the exchanges it receives. - `testRedeliveryRestoresOriginalInMessage`: each attempt sees the original body and header, and an exchange property set by a failed attempt is kept. This passes before and after the change. Verified: 639 tests in camel-core (`*Redelivery*`, `*DeadLetter*`, `*ErrorHandler*`, `*OnException*`, `*Retry*`, `*UseOriginal*`). The 8 skipped tests are `@Disabled` on main. I did not run the camel-spring and camel-jta tests; both transaction error handlers delegate to `super.process`. # 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 and installed the changed module (camel-core-processor), ran `mvn formatter:format impsort:sort` on the changed modules, and `git status` was clean afterwards. # 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. The code and this description were written with Claude Code (Claude Opus 5.5) and reviewed by me. 🤖 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]
