This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch fix/CAMEL-24931 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 11a55ca9ee0146bc8b046ae31bbe15978e185400 Author: Claus Ibsen <[email protected]> AuthorDate: Wed Sep 23 14:22:26 2026 +0200 CAMEL-24931: camel-jsonpath, camel-jq - the null body hint says how to read the data A route reached with direct: has the body of its caller, and when the caller has none - a REST GET, a timer - a jsonpath or jq step in it has nothing to read. The message said to read the JSON first and named the mechanisms, but "set it with setBody" does not say what to put in the setBody, which is the answer for the common case of a file the route knows the name of. It now carries the rule and both forms: setBody with constant: resource:file:data.json for a known file, or poll:, pollEnrich or a from: consumer for one that is not. In the AI route benchmark this failure produced 24 exceptions per run over five runs, with the message read every time and the read never added. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Bp3538HRBPMQkb5ta9xRaj --- .../src/main/java/org/apache/camel/language/jq/JqExpression.java | 6 ++++-- .../java/org/apache/camel/language/jq/JqNullBodyHintTest.java | 6 ++++-- .../src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java | 6 ++++-- .../java/org/apache/camel/jsonpath/JsonPathNullBodyHintTest.java | 8 ++++++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/components/camel-jq/src/main/java/org/apache/camel/language/jq/JqExpression.java b/components/camel-jq/src/main/java/org/apache/camel/language/jq/JqExpression.java index e955500c3072..6b9071447372 100644 --- a/components/camel-jq/src/main/java/org/apache/camel/language/jq/JqExpression.java +++ b/components/camel-jq/src/main/java/org/apache/camel/language/jq/JqExpression.java @@ -210,8 +210,10 @@ public class JqExpression extends ExpressionAdapter implements ExpressionResultT private String nullSourceHint() { if ("body".equals(source.toString())) { // a timer alone, or a jq step placed before the file was read: nothing to evaluate - return "the jq expression got no message body to evaluate, the body is null: read the JSON before the step" - + " with poll: file:..., pollEnrich or a from: consumer, or set it with setBody"; + return "the jq expression got no message body to evaluate, the body is null: a route reached with direct:" + + " has the body of its caller, so when the caller has none, read the data first - setBody with" + + " constant: resource:file:data.json for a known file, or poll:, pollEnrich or a from: consumer" + + " for one that is not"; } return "the jq expression got no input from " + source + " to evaluate, it is null: set it before the step," + " or leave source unset to use the message body"; diff --git a/components/camel-jq/src/test/java/org/apache/camel/language/jq/JqNullBodyHintTest.java b/components/camel-jq/src/test/java/org/apache/camel/language/jq/JqNullBodyHintTest.java index 8504c5046b8f..0155f8728908 100644 --- a/components/camel-jq/src/test/java/org/apache/camel/language/jq/JqNullBodyHintTest.java +++ b/components/camel-jq/src/test/java/org/apache/camel/language/jq/JqNullBodyHintTest.java @@ -52,8 +52,10 @@ public class JqNullBodyHintTest extends JqTestSupport { "should keep the original message, but was: " + message); assertTrue(message.contains("the jq expression got no message body to evaluate, the body is null"), "should say the body is null, but was: " + message); - assertTrue(message.contains("set it with setBody"), - "should say how to load a body, but was: " + message); + assertTrue(message.contains("constant: resource:file:"), + "should show the form for a known file, but was: " + message); + assertTrue(message.contains("poll:"), + "should offer poll for a file that is not known in advance, but was: " + message); } @Test diff --git a/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java b/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java index b8f72fd758b9..67cd783abe30 100644 --- a/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java +++ b/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java @@ -223,8 +223,10 @@ public class JsonPathEngine { // a timer alone, or a jsonpath step placed before the file was read: nothing to evaluate if (fromBody) { throw new CamelExchangeException( - "The jsonpath expression got no message body to evaluate (the body is null): read the JSON before" - + " the step with poll: file:..., pollEnrich or a from: consumer, or set it with setBody", + "The jsonpath expression got no message body to evaluate (the body is null): a route reached" + + " with direct: has the body of its caller, so when the caller has none, read the data" + + " first - setBody with constant: resource:file:data.json for a known file, or poll:," + + " pollEnrich or a from: consumer for one that is not", exchange); } throw new CamelExchangeException( diff --git a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathNullBodyHintTest.java b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathNullBodyHintTest.java index aa952fab1aab..da5d42df3d98 100644 --- a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathNullBodyHintTest.java +++ b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathNullBodyHintTest.java @@ -51,8 +51,12 @@ public class JsonPathNullBodyHintTest extends CamelTestSupport { assertTrue(message.contains("The jsonpath expression got no message body to evaluate (the body is null)"), "should say the body is null, but was: " + message); - assertTrue(message.contains("set it with setBody"), - "should say how to load a body, but was: " + message); + assertTrue(message.contains("constant: resource:file:"), + "should show the form for a known file, but was: " + message); + assertTrue(message.contains("poll:"), + "should offer poll for a file that is not known in advance, but was: " + message); + assertTrue(message.contains("has the body of its caller"), + "should say why the body is null in a direct: route, but was: " + message); } @Test
