[
https://issues.apache.org/jira/browse/CAMEL-20802?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17850942#comment-17850942
]
Raymond edited comment on CAMEL-20802 at 5/31/24 10:49 AM:
-----------------------------------------------------------
I dove a bit deeper into this issue yesterday. What I found out was:
1. This works (using ${headers} through simple, but not evaluating velocity):
{code:java}
<route id="myRoute">
<from uri="direct:in"/>
<setHeader name="CamelVelocityTemplate">
<simple>${headers}</simple>
</setHeader>
<!-- <to uri="velocity:generate"/>-->
</route> {code}
2. This works (using ${headers} through velocity, but not evaluating simple):
{code:java}
<route id="myRoute">
<from uri="direct:in"/>
<setHeader name="CamelVelocityTemplate">
<constant>${headers}</constant>
</setHeader>
<to uri="velocity:generate"/>
</route> {code}
3. This works (using a work-around by setBody first):
{code:java}
<route id="myRoute">
<from uri="direct:in"/>
<setBody>
<simple>${headers}</simple>
</setBody>
<setHeader name="CamelVelocityTemplate">
<simple>${body}</simple>
</setHeader>
<to uri="velocity:generate"/>
</route> {code}
However, when using simple to set the CamelVelocityTemplate first and then
apply velocity directly, it leads to the StackOverflow error.
Apparently the strange code with double evaluation (simple and then velocity)
was used because some evaluation was needed that velocity couldn't do, and some
evaluation was needed that simple couldn't do. This had always worked, but not
anymore in all cases. I advised the client to separate the evaluation into two
routes:
{code:java}
<route id="mySetBodyRoute">
<from uri="direct:in"/>
<setBody>
<simple>${headers}</simple>
</setBody>
<to uri="direct:velocity"/>
</route> {code}
{code:java}
<route id="myVelocityRoute">
<from uri="direct:velocity"/>
<setHeader name="CamelVelocityTemplate">
<constant>${headers}</constant>
</setHeader>
<to uri="velocity:generate"/>
</route> {code}
This made it clearer when to use simple and when to use velocity and when to
use both. Unfortunately, I couldn't create a reproducer with only main and
basic dependencies to trigger the error. This ticket can be closed. If I found
a reproducible case, I will create a new ticket.
was (Author: skin27):
I dove a bit deep into this issue yesterday. What I found out was:
1. This works (using ${headers} through simple, but not evaluating velocity):
{code:java}
<route id="myRoute">
<from uri="direct:in"/>
<setHeader name="CamelVelocityTemplate">
<simple>${headers}</simple>
</setHeader>
<!-- <to uri="velocity:generate"/>-->
</route> {code}
2. This works (using ${headers} through velocity, but not evaluating simple):
{code:java}
<route id="myRoute">
<from uri="direct:in"/>
<setHeader name="CamelVelocityTemplate">
<constant>${headers}</constant>
</setHeader>
<to uri="velocity:generate"/>
</route> {code}
3. This works (using a work-around by setBody first):
{code:java}
<route id="myRoute">
<from uri="direct:in"/>
<setBody>
<simple>${body}</simple>
</setBody>
<setHeader name="CamelVelocityTemplate">
<simple>${body}</simple>
</setHeader>
<to uri="velocity:generate"/>
</route> {code}
However, when using simple to set the CamelVelocityTemplate first and then
apply velocity directly, it leads to the StackOverflow error.
Apparently the strange code with double evaluation (simple and then velocity)
was used because some evaluation was needed that velocity couldn't do, and some
evaluation was needed that simple couldn't do. This had always worked, but not
anymore in all cases. I advised the client to separate the evaluation into two
routes:
{code:java}
<route id="mySetBodyRoute">
<from uri="direct:in"/>
<setBody>
<simple>${headers}</simple>
</setBody>
<to uri="direct:velocity"/>
</route> {code}
{code:java}
<route id="myVelocityRoute">
<from uri="direct:velocity"/>
<setHeader name="CamelVelocityTemplate">
<constant>${headers}</constant>
</setHeader>
<to uri="velocity:generate"/>
</route> {code}
This made it clearer when to use simple and when to use velocity and when to
use both. Unfortunately, I couldn't create a reproducer with only main and
basic dependencies to trigger the error. This ticket can be closed. If I found
a reproducible case, I will create a new ticket.
> Velocity shows error when using ${headers}
> ------------------------------------------
>
> Key: CAMEL-20802
> URL: https://issues.apache.org/jira/browse/CAMEL-20802
> Project: Camel
> Issue Type: Bug
> Components: camel-velocity
> Affects Versions: 4.6.0
> Reporter: Raymond
> Priority: Minor
> Attachments: main-xml.zip
>
>
> In Camel 3 (3.20.8) I have the following route:
> {code:java}
> <route id="myRoute">
> <from uri="direct:in"/>
> <setHeader headerName="CamelVelocityTemplate">
> <simple>${headers}</simple>
> </setHeader>
> <to uri="velocity:generate"/>
> <to
> uri="log:foo//?skipBodyLineSeparator=false&multiline=true&showHeaders=false&showBody=true&showBodyType=true&showFiles=true&showException=false&showStackTrace=false&showCaughtException=false"/>
> </route> {code}
> Then I get an output like this:
> {code:java}
> {Accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7,
> Accept-Encoding=gzip, deflate, br, zstd,
> Accept-Language=nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7,
> breadcrumbId=7FE304808A5EF7B-0000000000008538,
> CamelServletContextPath=/regressiontests/Velocity,
> CamelVelocityTemplate=(this Map), ComponentInitTime=1716561470224,
> Connection=close, Cookie=_ga=GA1.1.1085399545.1665049218;
> _ga_J0TKN8HXSY=GS1.1.1715979059.148.0.1715979059.0.0.0;
> nPT0%3D--35c503a9ecbf1d3922b78a7289ee8eb8f80e1d36, Host=assimbly-test:9001,
> sec-ch-ua="Google Chrome";v="125", "Chromium";v="125", "Not.A/Brand";v="24",
> sec-ch-ua-mobile=?0, sec-ch-ua-platform="Windows", Sec-Fetch-Dest=document,
> Sec-Fetch-Mode=navigate, Sec-Fetch-Site=none, Sec-Fetch-User=?1,
> Upgrade-Insecure-Requests=1, User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64;
> x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36}
> {code}
> However when running the route with Camel 4 (using 4.6.0 on JDK21) I get the
> following error:
> {code:java}
> java.lang.StackOverflowError: null
> at
> java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:806)
> at java.base/java.lang.StringBuffer.append(StringBuffer.java:425)
> at java.base/java.io.StringWriter.write(StringWriter.java:79)
> at org.apache.camel.util.json.Jsoner.serialize(Jsoner.java:963)
> at org.apache.camel.util.json.Jsoner.serialize(Jsoner.java:1004)
> at org.apache.camel.util.json.Jsoner.serialize(Jsoner.java:1006)
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)