[ 
https://issues.apache.org/jira/browse/CAMEL-24838?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18117218#comment-18117218
 ] 

Adriano Machado commented on CAMEL-24838:
-----------------------------------------

PR: https://github.com/apache/camel/pull/26618

Both messages were reproduced first on a timer-style route with no body, then 
changed in the style of the xslt message from CAMEL-24698.

*camel-jsonpath*, null body:
{code}
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
{code}

*camel-jsonpath*, body present but not JSON - the current message, plus the 
type:
{code}
Cannot read body as supported JSON value (the body has type: java.lang.Integer)
{code}

*camel-jq*, null body - InvalidPayloadException is kept, with the hint appended 
the way ExpectedBodyTypeException has taken one since CAMEL-24698:
{code}
No body available of type: com.fasterxml.jackson.databind.JsonNode on: Message
(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)
{code}

Two things worth a look during review:

* A non-body source is named instead of being told to setBody: "got no input 
from variable(input) to evaluate, it is null: set it before the step, or leave 
source unset to use the message body". header: and property: sources cannot 
reach that path - singleInputExpression builds them as mandatory, so they 
already throw NoSuchHeaderException/NoSuchPropertyException first.
* The source == null branch in JsonPathEngine was dead (the language always 
supplies a body expression, whose toString() is "body"; only the deprecated 
single-argument constructor leaves the source unset, and that means the body 
too), so it is folded into the body case. That is also why the reported text 
was "Cannot read body as ..." and not "Cannot read message body as ...".

Exception types are unchanged, so onException(InvalidPayloadException.class) 
and friends keep working. No docs or upgrade-guide entry: exception text only, 
and the new camel-api constructor is additive.

_Claude Code on behalf of Adriano Machado (@ammachado)_

_This was generated by an AI agent and may contain inaccuracies. Please verify 
before relying on it._

> jsonpath and jq: say that the body is null (and how to load one) instead of 
> 'Cannot read body as supported JSON value'
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-24838
>                 URL: https://issues.apache.org/jira/browse/CAMEL-24838
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-jq, camel-jsonpath
>            Reporter: Claus Ibsen
>            Assignee: Adriano Machado
>            Priority: Major
>
> On a route with no body (a timer route, a step before the file was read), a 
> jsonpath expression fails with
> {code}
> org.apache.camel.ExpressionEvaluationException: 
> org.apache.camel.CamelExchangeException: Cannot read body as supported JSON 
> value. Exchange[...]
> {code}
> and jq with
> {code}
> org.apache.camel.InvalidPayloadException: No body available of type: 
> com.fasterxml.jackson.databind.JsonNode on: Message. Exchange[...]
> {code}
> Neither says the one thing that matters: the body is null. Both should, in 
> the style of the xslt message from CAMEL-24698: "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." 
> When the body is not null but not JSON, keep the current message and add the 
> body's type.
> Found in the round-2 local-model benchmark on the camel-jbang-examples ladder 
> (json-transform: a timer route with jsonpath and jq steps and no body). A 
> person who puts the jsonpath step before the file read gets the same two 
> messages.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to