davsclaus commented on code in PR #29014:
URL: https://github.com/apache/camel/pull/29014#discussion_r4451923802


##########
components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdBinding.java:
##########
@@ -75,10 +83,26 @@ public ServerMessage.Mutable 
createCometdMessage(ServerChannel channel, ServerSe
             mutable.setClientId(serverSession.getId());
         }
         addHeadersToMessage(mutable, camelMessage);
-        mutable.setData(camelMessage.getBody());
+        Object body = camelMessage.getBody();
+        if (body == null) {
+            // publish a JSON null: setData(null) leaves out the data field, 
and the clients take a message without
+            // data for the reply of a publish, so their subscribers never 
receive it
+            mutable.put(DATA_FIELD, null);
+        } else {
+            if (isStreamOrFile(body)) {
+                // the JSON of the message has the toString of a stream or a 
file, so publish its content as text
+                body = camelMessage.getBody(String.class);
+            }

Review Comment:
   Done in 81cde17ffbf0: `getMandatoryBody(String.class)`, so a stream or file 
body that does not convert to text fails the exchange with an 
`InvalidPayloadException` instead of publishing a message without data. 
`createCometdMessage` now declares `throws InvalidPayloadException` (the 
consumer's `push` already throws `Exception`, and the producer's `process` now 
does too). In practice the converters for streams and files throw a 
`TypeConversionException` on an I/O error rather than return null, so this 
guards the no-converter case. Module: 44 tests, 0 failures.
   
   _Claude Code on behalf of Claus Ibsen (davsclaus)_



-- 
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