This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 6345a2d5f855 CAMEL-24931: camel-jsonpath, camel-jq - the null body
hint says how to read the data (#26780)
6345a2d5f855 is described below
commit 6345a2d5f855c04aee744bde7f9d5afc86529d37
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Sep 23 21:21:02 2026 +0200
CAMEL-24931: camel-jsonpath, camel-jq - the null body hint says how to read
the data (#26780)
When a jsonpath or jq expression finds no body, the hint now says why and
what to do about it: a route reached with direct: has the body of its caller,
so when the caller has none the data has to be read first - setBody with
constant: resource:file:data.json for a known file, or poll:, pollEnrich or a
from: consumer for one that is not.
The wording came from watching a local model fail the same way repeatedly:
it wrote a jsonpath step in a direct: route whose caller never set a body, and
the old message said only that the body was null.
Closes #26780
---
.../src/main/java/org/apache/camel/language/jq/JqExpression.java | 6 ++++--
.../java/org/apache/camel/language/jq/JqNullBodyHintTest.java | 9 +++++++--
.../src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java | 6 ++++--
.../java/org/apache/camel/jsonpath/JsonPathNullBodyHintTest.java | 8 ++++++--
4 files changed, 21 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..cf410e11e9d6 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,13 @@ 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);
+
+ assertTrue(message.contains("has the body of its caller"),
+ "should say why the body is null in a direct: route, 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