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

   ## Summary
   
   Fix `ScpOperations.storeFileDirectly()` so that it correctly connects the 
SCP channel before writing, making `checksumFileAlgorithm` work with the SCP 
producer.
   
   ## Root Cause
   
   `storeFileDirectly()` opened a `ChannelExec` but never called 
`channel.setCommand()` or `channel.connect(timeout)`, so the write on the 
channel always failed. It also never disconnected the channel in a `finally` 
block (resource leak), and passed the raw `name` to `write()` without resolving 
the remote path via `getRemoteFile()`.
   
   Since `GenericFileProducer.writeChecksumFile()` calls `storeFileDirectly()` 
whenever `checksumFileAlgorithm` is set, every SCP exchange with that option 
set failed with `GenericFileOperationFailedException: Failed to write file 
<name>.<algorithm>`.
   
   ## Fix
   
   Align `storeFileDirectly()` with `storeFile()`:
   - Add `ObjectHelper.notNull(session, "session")` guard
   - Resolve the remote path via `getRemoteFile(name, cfg)`
   - Set the SCP command via `channel.setCommand(getScpCommand(cfg, file))`
   - Connect with the configured timeout via `channel.connect(timeout)`
   - Disconnect the channel in a `finally` block and clear the field
   - Use `StandardCharsets.UTF_8` instead of the platform default for the 
payload bytes
   
   ## Tests
   
   `ScpProducerChecksumFileAlgorithmTest` (new, embedded SSH server):
   - `testChecksumFileIsWritten`: sends `Hello World` with 
`checksumFileAlgorithm=md5`; verifies the exchange succeeds, `hello.txt.md5` 
contains the correct hex MD5, and `CamelFileChecksum` header is set.
   - `testChecksumFileIsWrittenInSubDirectory`: same with `subdir/bye.txt`.
   - `testNoChecksumFileWithoutOption`: control — without the option, no `.md5` 
file is written and no checksum header is set.
   
   ---
   _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
   


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