davsclaus opened a new pull request, #28927: URL: https://github.com/apache/camel/pull/28927
Fixes [CAMEL-26154](https://issues.apache.org/jira/browse/CAMEL-26154). ### 1. The producer corrupted binary bodies **Was:** `IggyProducer` converted every body that is not a `List` or an Iggy `Message` to a `String`. A `byte[]` like `ff fe 00 41` was decoded as text and sent as `EF BF BD EF BF BD 00 41`. **Now:** a `byte[]`, `InputStream` (so also stream caches), `ByteBuffer`, `File`, `Path` or `WrappedFile` body is converted to `byte[]` and sent unchanged. The message header is built the same way `Message.of(String)` builds it (server generated id, payload length, no user headers). All other bodies are still sent as UTF-8 text via `toString()`/type conversion, as before; that conversion now uses `mandatoryConvertTo` so a body that cannot convert fails clearly instead of passing `null` to the client. ### 2. The consumer decoded the payload with the platform charset **Was:** `IggyFetchRecords` set the body to `new String(message.payload())` (with a `TODO is it ok?`), so binary payloads could not be read back, and text depended on the default charset of the JVM. **Now:** the body is the payload as a `byte[]`, like the other messaging consumers (paho, hivemq, nats). Camel converts it to a `String` where one is needed. This is a behaviour change, so it is in the upgrade guide. ### 3. No body failed with a NullPointerException **Now:** the producer reads the body with `getMandatoryBody()`, so no body fails with an `InvalidPayloadException` before the client is called. ### 4. An empty List failed with an unclear error **Now:** an empty `List` sends nothing and the exchange completes (the same as camel-kafka does for an empty `Iterable`). On the same lines: a `List` with a `null` element passed both type checks and failed in the client with a `NullPointerException`; it now fails with `The List body must not contain null elements`. ### 5. camel-test-infra-iggy cannot start the 0.9.0 image Not changed: already fixed on main by CAMEL-26326 (#28554), which sets `IGGY_NODE_ADVERTISED_ADDRESS` and `IGGY_SHARDING_CPU_ALLOCATION`. ### Tests - New `IggyMessageBodyTest` (mocked Iggy client, no server): byte[] and stream bodies keep their bytes, text is sent as UTF-8, no body / empty List / List with null, and the consumer gives a `byte[]` body. Without the fix 6 of its 7 tests fail (the UTF-8 text test guards the unchanged behaviour). - `IggyConsumerIT` reads the body with `getBody(String.class)`, and `IggyTestBase` decodes the polled payloads as UTF-8. - `mvn clean install -Psourcecheck` in `components/camel-iggy`: 26 unit tests and 12 ITs (against the iggy 0.9.0 container) pass. ### Docs and generated files - `@BodyTypes` of the endpoint updated (consumer: `bytes`/`byte[]`; producer text rewritten), `iggy.json` regenerated and copied to the catalog. - New "Message body" section in `iggy-component.adoc` (copied to the catalog). - Upgrade guide 4.24: new `camel-iggy - binary payloads, and the body of the consumer` entry next to the existing camel-iggy entry. ### Open question The empty `List` case could also fail with a clear message instead of sending nothing. I chose sending nothing (nothing to send, like camel-kafka); easy to switch if you prefer a failure. _Claude Code on behalf of Claus Ibsen (davsclaus)_ 🤖 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]
