gnodet-bot commented on code in PR #26627:
URL: https://github.com/apache/camel/pull/26627#discussion_r4056819269
##########
core/camel-support/src/main/java/org/apache/camel/support/MessageHelper.java:
##########
@@ -1109,6 +1110,17 @@ public static JsonObject dumpAsJSonObject(
jb.put("size", size);
}
}
+ if (!jb.containsKey("size") && message.getExchange() != null &&
message.getExchange().getContext() != null) {
+ // the size of a text or byte body, from the message size
strategy when it is enabled (the dev
+ // profile does): lengths only, nothing is read or converted
(CAMEL-24844)
+ MessageSizeStrategy sizeStrategy =
message.getExchange().getContext().getMessageSizeStrategy();
+ if (sizeStrategy != null && sizeStrategy.isEnabled()) {
+ long size = sizeStrategy.computeBodySize(message);
+ if (size >= 0) {
Review Comment:
**Bug: null body gets `"size": 0` in the dump.**
`DefaultMessageSizeStrategy.computeBodySize` returns `0` when the body is
null (see its Javadoc and implementation). So the guard `size >= 0` passes and
`"size": 0` is written into the JSON even when the body is null. A consumer
(including the MCP `get_history` summary which calls `historySummary()` and
surfaces `bodySize`) sees `{"type": "null", "size": 0}`, which is redundant —
`"null"` already conveys absence — and inconsistent with the `StreamCache`
handling above, which only emits `size` when `size > 0`.
Change the guard to exclude zero:
```suggestion
if (size > 0) {
```
Also extend the `testDumpAsJSonBodySizeAndNull` test: after
`message.setBody(null)` assert `!out.contains("\"size\"")` to pin the contract.
##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HistoryTab.java:
##########
@@ -1388,7 +1388,7 @@ private void renderTraceStepDetail(Frame frame, Rect
area, List<TraceEntry> step
headersChanged, prev != null ? prev.headers : null);
}
if (showTraceBody) {
- addBodyLines(lines, entry.body, entry.bodyType, bodyChanged);
+ addBodyLines(lines, entry.body, entry.bodyType, entry.bodySize,
bodyChanged);
Review Comment:
**Propagation gap: `renderDiagramInfoPanel` and `ErrorsTab.renderDetail`
silently drop `bodySize`.**
`renderTraceStepDetail` (this line) and `renderHistoryDetail` (line 1676)
now correctly pass `entry.bodySize` to `addBodyLines`. But two other render
paths that read the same `TraceEntry`/`HistoryEntry` objects do not:
1. **`renderDiagramInfoPanel`** (line 894): loads `body` and `bodyType` from
the entry but has no `bodySize` local. Its inline body render (around line
1055) shows `(bodyType)` without size. Fix: add `long bodySize = -1;` alongside
the other locals, populate it from `e.bodySize` in both `TraceEntry` and
`HistoryEntry` branches, then use the same `detail` string that `addBodyLines`
builds:
```java
String detail = bodySize >= 0 ? bodyType + ", " +
HeapHistogramTab.formatBytes(bodySize) : bodyType;
```
2. **`ErrorsTab.renderDetail`**: calls `HistoryTab.addBodyLines(lines,
ei.body, ei.bodyType, false)` — the 4-arg shim — so `ei.bodySize` (populated by
the PR in `StatusParser.parseErrors`) is never displayed. Either call the 5-arg
overload directly, or update the 4-arg shim to accept the size.
--
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]