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

   # Description
   
   [CAMEL-25905](https://issues.apache.org/jira/browse/CAMEL-25905)
   
   With `checksumFileAlgorithm`, the file producer wrapped the body in a 
`DigestInputStream`, so the checksum was that of the body, not of the written 
file. With `charset` set, the charset path then read that stream with `new 
InputStreamReader(is)` (the default charset of the JVM) instead of the `Reader` 
conversion it uses without a checksum. Adding the checksum option to a route 
that re-encodes files therefore changed the output:
   
   - the bytes of a file consumed with `charset=ISO-8859-1` were decoded as 
UTF-8, so every non-ASCII character was written as U+FFFD;
   - the checksum header and the checksum file did not match the written file 
whenever the encoding changed a byte;
   - a String body whose exchange carries the endpoint charset (for example 
sent with a `ProducerTemplate`) failed with `UnmappableCharacterException`;
   - with `fileExist=Append` and `appendChars`, the checksum left out the 
appended characters.
   
   Changes (`FileOperations`):
   - The digest is updated with the bytes written to the file: a 
`DigestOutputStream` under the writer of the charset path, and the buffer and 
the `appendChars` bytes of the stream path.
   - The charset path decodes the body as it does without the checksum option 
(`Reader` conversion with the exchange charset).
   - The writer of the charset path is an `OutputStreamWriter` with a 
`CharsetEncoder` that reports unmappable characters, as 
`Files.newBufferedWriter` did; the charset is resolved before the file is 
opened, as before.
   - Upgrade note in the 4.24 guide: checksums of such files differ from the 
ones written before.
   
   Tests:
   - New `FileProducerChecksumOfWrittenFileTest` in camel-core (4 tests). On 
main: `transcodedFileHasItsOwnChecksumAndContent` fails with `array lengths 
differ, expected: <17> but was: <20>`, 
`stringWrittenWithCharsetHasTheChecksumOfTheFile` fails with a 
`CamelExecutionException` caused by `UnmappableCharacterException`, 
`appendCharsArePartOfTheChecksum` fails with `expected: <d2a84f4b...> but was: 
<a591a6d4...>`. `bodyWithoutCharsetKeepsItsChecksum` is a control and passes on 
main.
   - The existing `FileProducerChecksumFileAlgorithmTest` (9 tests, including 
the non-repeatable stream case) passes.
   - The tests of the `org.apache.camel.component.file` package of camel-core: 
478 run, 0 failures, 0 errors, 12 skipped. camel-file: 28 run, 0 failures. 
`FileProducerNoForcedWritesTest` failed once and passed on the rerun; it does 
not use the checksum option (its consumer polls the directory the route writes 
to).
   
   What was not run: the whole camel-core test suite (only the file package 
above); the full root build.
   
   Not changed:
   - With `fileExist=Append` to an existing file, the checksum covers the bytes 
this exchange wrote, not the whole file (as before).
   - The remote file producers (ftp, sftp, scp, smb, azure-files) expose 
`checksumFileAlgorithm` too, but since the checksum moved into `FileOperations` 
(CAMEL-22846, 4.18) they never calculate one, so no header and no checksum file 
are written; 4.14.x wrote one for them. I can file a follow-up JIRA.
   
   # 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-25905](https://issues.apache.org/jira/browse/CAMEL-25905).
   
   # 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.
     (I built camel-file and camel-core with their dependencies and ran the 
tests above, including the formatter and import-sort plugins; no generated file 
changes. I did not run the full root build.)
   
   # 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.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit 
carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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