davsclaus opened a new pull request, #28924: URL: https://github.com/apache/camel/pull/28924
Fixes [CAMEL-26153](https://issues.apache.org/jira/browse/CAMEL-26153). ### A body that does not convert to byte[] was published as an empty payload **What was wrong:** `HiveMQProducer.process` read the body with the non-mandatory `getBody(byte[].class)` and replaced `null` with `new byte[0]`. A `Map`, a POJO or a number has no converter to `byte[]`, so `getBody` returned `null` and the producer published an empty MQTT message, with no error and no log. The data was lost. camel-paho fails the exchange for the same bodies. **What changed:** - With a body, the producer now uses `getMandatoryBody(byte[].class)`, so a body that does not convert fails the exchange with `InvalidPayloadException`. A message without a body is still published as an empty payload (as before, and as `HiveMQEmptyPayloadIT` checks). - The header and body reads are inside a try/catch that sets the exception and calls `callback.done(true)`, so a failure there goes through the async callback instead of being thrown out of `process(exchange, callback)`. (An invalid QoS header already ended up on the exchange before; the test for it is a regression guard.) **Tests:** new `HiveMQProducerBodyTest` (fake client, no broker): text body is published, no body is an empty payload, `Map`/`Integer`/POJO bodies fail with `InvalidPayloadException` and publish nothing, an invalid QoS header fails the exchange. The three `Map`/`Integer`/POJO tests fail without the fix. Module build with `-Psourcecheck`: 32 unit tests and 10 ITs (hivemq-ce in Docker) pass. **Docs and generated files:** - `@BodyTypes` producerIn text updated (it described the old silent empty payload); regenerated `hivemq.json` and copied it to the catalog. - `hivemq-component.adoc`: short note on what the producer sends; copied to the catalog docs. - Upgrade guide 4.24: new `camel-hivemq` entry, since a route that sent such a body now fails instead of publishing an empty message. **Not changed:** no new option to keep the old behaviour; an empty payload for a body with data is never the intended result. _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]
