davsclaus commented on code in PR #28048:
URL: https://github.com/apache/camel/pull/28048#discussion_r4306642871


##########
components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java:
##########
@@ -378,11 +382,36 @@ public boolean storeFile(String fileName, Exchange 
exchange, long size) throws G
             setPermissions(file);
 
             return true;
-        } catch (InvalidPayloadException | NoSuchAlgorithmException | 
IOException e) {
+        } catch (InvalidPayloadException e) {
+            // say why: the body cannot be written as it is
+            throw new GenericFileOperationFailedException("Cannot store file: 
" + file + ": " + e.getMessage(), e);
+        } catch (NoSuchAlgorithmException | IOException e) {
             throw new GenericFileOperationFailedException("Cannot store file: 
" + file, e);
         }
     }
 
+    /**
+     * The body as a stream to write. A Map or a List (a body unmarshalled 
from JSON, or built as a map) cannot become
+     * one, and the converter's message only names the conversion: say what to 
do (CAMEL-25751).
+     */
+    static InputStream mandatoryBodyStream(Exchange exchange, Message message) 
throws InvalidPayloadException {
+        try {
+            return message.getMandatoryBody(InputStream.class);
+        } catch (InvalidPayloadException e) {
+            Object body = message.getBody();
+            if (body instanceof Map || body instanceof Collection) {
+                InvalidPayloadException answer = new InvalidPayloadException(
+                        exchange, InputStream.class, message,
+                        "a " + (body instanceof Map ? "Map" : body instanceof 
List ? "List" : "Collection")
+                                                              + " is not file 
content: marshal it first (marshal: json) or set the body to the"
+                                                              + " text");
+                answer.initCause(e.getCause() != null ? e.getCause() : e);

Review Comment:
   Kept as the http producer has it since CAMEL-25309 
(`HttpProducer.mandatoryBodyStream`), so the three places chain the same way: 
the conversion failure is the direct cause and the hint is in the message. 
CAMEL-25749 moves them onto one helper, where this can change in one place.
   
   _Claude Code on behalf of davsclaus_



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