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

   Fixes [CAMEL-26257](https://issues.apache.org/jira/browse/CAMEL-26257), 
found while adding the catalog body types (CAMEL-24961).
   
   ## 1. A binary stream or File payload is corrupted
   
   **Was:** `FCUtils.resolvePayload` sent a `byte[]` and a `String` as they 
are, but converted any other body with `getMandatoryBody(String.class)` and 
back to UTF-8 bytes. A binary `InputStream` or `File` payload reached the 
function changed, without an error: every byte that is not valid UTF-8, such as 
0xff, became EF BF BD (00 ff fe 41 80 7f went out as 00 ef bf bd ef bf bd 41 ef 
bf bd 7f). A binary `GenericFile` from a file consumer failed with an 
`InvalidPayloadException` caused by a `MalformedInputException`. A `Map` or a 
POJO was sent as its `toString()`, which is not JSON.
   
   **Now:** a body that is not a `byte[]` or a `String` is converted with 
`getMandatoryBody(byte[].class)`, so an `InputStream`, a `File` and a 
`GenericFile` are sent as their bytes, unchanged. A `String` is still sent in 
UTF-8, a `byte[]` as it is, and no body still invokes the function with an 
empty payload. A body that does not convert to bytes, such as a `Map` or a 
POJO, now fails with an `InvalidPayloadException` that names its type, and the 
function is not invoked. The catalog body types (`producerIn`) are updated to 
match.
   
   ## Tests
   
   - New `InvokeFunctionPayloadTest` (8 tests) with a Mockito `Client` set on 
the endpoint, which captures the `InvokeFunctionRequest`. It covers a `String` 
with non-ASCII text, a `byte[]`, an `InputStream`, a `File` and a `GenericFile` 
holding the bytes 00 ff fe 41 80 7f, no body, a `Map` and a POJO.
   - With the `src/main` changes reverted, 5 of the 8 tests fail: the stream 
and the file on the corrupted bytes, the `GenericFile` on the old 
`InvalidPayloadException` (`MalformedInputException`), and the `Map` and the 
POJO because no exception is thrown (they were sent as their `toString()`). The 
3 that pass are the `String`, the `byte[]` and no body, whose payload does not 
change.
   - Module tests: 9 tests, 0 failures.
   
   ## Docs and generated files
   
   - Component doc: a new "Payload of invokeFunction" section that says how 
each body is sent.
   - The `@BodyTypes` description of `FCEndpoint`; the regenerated 
`alibaba-fc.json` and the doc are copied into the catalog.
   - Upgrade guide entry for 4.24: a stream or a file is sent as its bytes, and 
a body that does not convert to bytes fails with an `InvalidPayloadException` 
instead of being sent as its `toString()`.
   
   ## Not changed
   
   - No body still invokes the function with an empty payload. The catalog body 
types list no body (`null`) as a carrier of `invokeFunction`, `aws2-lambda` 
also invokes its function without a payload, and invoking a function without 
input, for example from a timer, is a valid call. **Open question:** should no 
body fail instead?
   - A `Map` or a POJO is not marshalled to JSON by the component: that would 
be a new feature, and a function may expect another format. It fails, so the 
route marshals it first.
   
   Main only, as the other fixes of the CAMEL-24961 follow-ups.
   
   _Claude Code on behalf of Andrea Cosentino (oscerd)_
   
   🤖 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