davsclaus opened a new pull request, #28928: URL: https://github.com/apache/camel/pull/28928
Fixes [CAMEL-26156](https://issues.apache.org/jira/browse/CAMEL-26156). ### 1. FIRE and SETSTATE with an empty body still ran the operation `PubNubProducer.doFire` and `doSetState` set a `CamelException` and called `callback.done(true)` when the body was empty, but did not return. The PubNub call still ran and called `callback.done(false)` a second time, and `process` returned `false` although the callback was already called. FIRE with a null body ended with the PubNub error `Message Missing` instead of `Can not fire empty message`. Changed: both methods now throw the `CamelException`, as `doPublish` does. `process` sets it on the exchange, calls the callback once and returns `true`. PubNub is not called. The exception messages are unchanged. ### 2. The consumer body had no type converter The consumer sets the body to the `PNMessageResult`. There was no type converter, so `${body}` or a conversion to `String` gave `PNMessageResult@hash`. Changed: a new `PubNubConverter` (`@Converter(generateLoader = true)`) converts `PNMessageResult` to `String`: a string message as its text (`"Hi"` gives `Hi`, not `"Hi"` with quotes), any other message (object, array, number, boolean) as its JSON. The body itself is unchanged, so `${body.message}` works as before. No logging in the converter. ### Tests - `PubNubEmptyBodyTest`: FIRE with a null body and SETSTATE with an empty Map fail with the `CamelException` and WireMock gets no request; calling the producer directly returns `true` with the callback called once, synchronously, for both operations. - `PubNubConverterTest`: string, object, array and number messages convert to the expected text. - `PubNubSubscriberTest`: the received body converts to `{"text":"Message"}`. - All 11 new assertions/tests failed before the fix. Module: 35 tests, 0 failures (`mvn clean install -Psourcecheck`). ### Docs and generated files - `pubnub-component.adoc`: says the `PNMessageResult` body converts to a `String`. - `@BodyTypes` consumerOut description updated (it said the body does not convert to the payload text); regenerated `pubnub.json` and copied it and the adoc into camel-catalog. - Upgrade guide 4.24: a `camel-pubnub` entry (FIRE with a null body now fails with a `CamelException` instead of the `PubNubException` `Message Missing`; the new String conversion). ### Not changed - The presence event body (`PNPresenceEventResult`, with `withPresence`) still has no converter; it was not part of the issue. - The SETSTATE message `Can not publish empty message` is kept as is. _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]
