[
https://issues.apache.org/jira/browse/CAMEL-23377?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18076999#comment-18076999
]
Raymond edited comment on CAMEL-23377 at 4/29/26 8:45 AM:
----------------------------------------------------------
Did a short investigation, and apparently the escape was done on Windows, and
then /r/n was used. However when I used /n (Unix way) like for example:
$init{\n$price :=
$\{xpath(\/\/food[name='food1']\/price\/text())};\n}init$\n\{\n\"price\":
\"$price\"\n}
It works as expected.
Note as you update the docs you can close it (or let it open if you want to
allow multiple statements on one line). For that you do parsing like strip all
spaces/returns/newlines etc, split by the ; endline and then evaluate every
statement.
was (Author: skin27):
Did a short investigation, and apparently the escape was done on Windows, and
then /r/n was used. However when I used /n (Unix way) like for example:
$init\{\n$price :=
${xpath(\/\/food[name='food1']\/price\/text())};\n}init$\n\{\n\"price\":
\"$price\"\n}
It works as expected.
Note as you update the docs you can close it (or let it open if you want to
allow multiple statements on one line).
> simple language - Multiline init blocks aren't initialized properly
> -------------------------------------------------------------------
>
> Key: CAMEL-23377
> URL: https://issues.apache.org/jira/browse/CAMEL-23377
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 4.20.0
> Reporter: Raymond
> Assignee: Claus Ibsen
> Priority: Minor
> Fix For: 4.21.0
>
>
> I was following the latest (Next) documentation of Simple expressions:
> [https://camel.apache.org/components/next/languages/simple-language.html#_init_blocks]
> I used the following example:
>
> {code:java}
> $init{
> $greeting := ${upper('Hello $body}'}
> $level := ${header.code > 999 ? 'Gold' : 'Silver'}
> }init$
> {
> "message": "$greeting",
> "status": "$level"
> }
> {code}
> The example still seems from 4.18.x, and has several issues:
> 1. upper --> uppercase
> 2. uppercase function is not properly closed with a )
> 3. No ; after the variable declaration
> After the correction it looks like this:
>
> {code:java}
> $init{
> $greeting := ${uppercase('Hello $body')};
> $level := ${header.code > 999 ? 'Gold' : 'Silver'};
> }init$
> {
> "message": "$greeting",
> "status": "$level"
> } {code}
> However, even when running this code I don't get the expected result.
> *Expected:*
> {code:java}
> {
> "message": "HELLO JOE",
> "status": "Silver"
> }{code}
> *Actual:*
> {code:java}
> {
> "message": "HELLO JOE;
> $level := Silver;
> ",
> "status": "$level"
> } {code}
> So it seems that multiline variable declaration aren't evaluated separately.
> BTW as now ; is used to indicate the end of a line, I would expect that this
> also works (all declaration on one line):
> {code:java}
> $init{$greeting := ${uppercase('Hello $body')}; $level := ${header.code > 999
> ? 'Gold' : 'Silver'};}init$
> {
> "message": "$greeting",
> "status": "$level"
> }{code}
> Maybe good to check this case also.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)