chala2001 opened a new pull request, #26024:
URL: https://github.com/apache/camel/pull/26024

   # Description
   
   With `clientRequestValidation` enabled and a REST service that declares a 
required body, binary
   payloads came through corrupted. Posting `application/octet-stream` data 
ended up with large parts
   of the content replaced by `EF BF BD`, the Unicode replacement character.
   
   `DefaultRestClientRequestValidator` reads the body as a String to check that 
it is present, and then
   wrote that String back onto the message:
   
   ```java
   body = MessageHelper.extractBodyAsString(exchange.getIn());
   if (ObjectHelper.isNotEmpty(body)) {
       exchange.getIn().setBody(body);
   }
   ```
   
   The write back is what destroys the payload. Bytes that are not valid UTF-8 
do not survive the trip
   through a String, so the route downstream receives replacement characters 
instead of the original
   data. The write back is also not needed to keep the body readable: 
`MessageHelper.extractBodyAsString`
   already converts the body to a `StreamCache`, sets that on the message and 
resets it, so the body
   stays re-readable on its own. Removing the two lines keeps the required body 
check and leaves the
   payload alone.
   
   This was raised on Zulip and James Netherton pointed at these lines as the 
likely cause:
   
https://camel.zulipchat.com/#narrow/channel/257302-camel-quarkus/topic/Binary.20data.20issue.20using.20Rest.20DSL/with/617455026
   
   `RestJettyRequiredBodyTest#testJettyBinaryBodyNotCorrupted` posts a small 
byte array that is not
   valid UTF-8 to an `application/octet-stream` service with a required body, 
and asserts the bytes
   come back unchanged. With the fix reverted the test fails, since the payload 
comes back with
   replacement characters.
   
   Also added a short note to the 4.23 upgrade guide, because the message body 
type after validation
   changes for anyone who relied on it being a String.
   
   # 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).
   
   CAMEL-24409
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   - [x] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   # 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.
   
   Written with Claude Code. The commit carries a `Co-authored-by` trailer.
   
   _Claude Code on behalf of chala2001_
   


-- 
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]

Reply via email to