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

   [CAMEL-27151](https://issues.apache.org/jira/browse/CAMEL-27151)
   
   ## Problem
   
   When the body cannot be written as a file, for example a `List` after 
`unmarshal: csv`, the ftp and sftp producers fail with only:
   
   ```
   WARN  RemoteFileProducer : Writing file failed with: Cannot store file: 
failed/invoices-2026-11-01.csv
   ```
   
   The reason is in the cause, which no log line shows: `No body available of 
type: java.io.InputStream but has type: java.util.ArrayList ...`. The message 
reads like a problem with the folder or the permissions, but the folder is 
fine: the same producer writes a text body there. I checked this with `camel 
infra run sftp` and a route that sends a `List` and then a text to the same 
folder.
   
   The file producer already says why (CAMEL-25751): `Cannot store file: 
<file>: ... the body is a List, which is not file content: marshal it first 
(marshal: csv, for the file name ...)`. The ftp and sftp producers did not.
   
   In the local-model benchmark (connect-sftp-transfer step 2, r30 to r35), an 
`onException` sends a batch that failed to the folder `failed` on the server, 
and the body is the parsed CSV. 19 of 35 step runs got the bare message, and 12 
of them failed. The model changed the folder and the options, because the 
message did not say that the body was the problem. As the failed write is in 
the `onException`, the batch is rolled back and polled again, so a run logged 
up to 123 errors.
   
   ## Change
   
   - `FileOperations.mandatoryBodyStream` moves to 
`GenericFileHelper.mandatoryBodyStream(Exchange, Message, String fileName)`, so 
the remote file components can use it. The file component works as before.
   - `FtpOperations` and `SftpOperations` read the body to store with it, and 
`Cannot store file: <name>` ends with its message, as the file component does. 
The producer's WARN shows it too.
   
   ## Tests
   
   - `SftpOperationFailureMessageIT` and `FtpChangeDirectoryFailureMessageIT`: 
a `List` body sent to a folder that exists gives `Cannot store file: ...` with 
"the body is a List, which is not file content: marshal it first (marshal: csv, 
for the file name invoices.csv)". Both new tests fail without the change.
   - camel-ftp: all unit tests (275) and integration tests (531). One 
integration test fails on macOS, on main as well: 
`SftpConsumerWrongPasswordIT.connectionFailureIsRetried` expects "connection is 
closed by foreign host", and gets "Session.connect: java.net.SocketException: 
Connection reset". It does not touch the code of this change.
   - camel-file: the producer tests (`FileProducerMapBodyTest`); camel-core: 
the file component tests (548).
   
   _Claude Code on behalf of davsclaus_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_016Y4dDi5iQNgtHrDdz2NpwF
   


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