gnodet-bot commented on code in PR #28048:
URL: https://github.com/apache/camel/pull/28048#discussion_r4306553885
##########
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:
💡 **Suggestion:** `e.getCause()` can be non-null here (the 4-arg
`InvalidPayloadException` constructor used by `getMandatoryBody` does forward
the conversion cause), so the ternary is exercised in practice. Simplifying to
`answer.initCause(e)` always chains the original `InvalidPayloadException` as
the direct cause, which gives a slightly cleaner stack trace — the conversion
failure is preserved either way. Non-blocking.
--
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]