gnodet-bot commented on code in PR #29014:
URL: https://github.com/apache/camel/pull/29014#discussion_r4451757822
##########
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:
`getBody(String.class)` is `@Nullable` and returns `null` on conversion
failure (I/O error, missing converter). When that happens, `body` is `null` and
`mutable.setData(null)` silently drops `DATA_FIELD` from the message — the
exact bug the `null` branch above guards against.
Use `getMandatoryBody(String.class)` to surface the error as an
`InvalidPayloadException` instead of silently losing data.
```suggestion
body = camelMessage.getMandatoryBody(String.class);
```
--
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]