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

Raymond edited comment on CAMEL-20802 at 5/27/24 11:17 AM:
-----------------------------------------------------------

I tried to make a reproducer based on xml-main, but it works as expected. It 
works like before (in Camel 2 and Camel 3).

I do however found what was the issue was. The problem was not so much in the 
Velocity, but that the header was set with a simple expression:
{code:java}
<setHeader name="CamelVelocityTemplate">
     <simple>${headers}</simple>
</setHeader> {code}
This code was always used this way (don't know why, not written by me). I 
wonder: Is (or was) the CamelVelocityTemplate header as a Camel header 
evaluated differently than a normal header? 

Now it seems that it first evaluates it as simple, before it evaluate it as 
velocity template (but then it's already a string).

The error occurs thus occurs when it evaluates the expression ${headers} in 
simple. When I set CamelVelocityTemplate as a constant, like it also done in 
the Velocity documentation, it works.


was (Author: skin27):
I tried to make a reproducer based on xml-main, but it works as expected. It 
works like before (in Camel 2 and Camel 3).

I do however found what was the issue was. The problem was not so much in the 
Velocity, but that the header was set with a simple expression:
{code:java}
<setHeader name="CamelVelocityTemplate">
     <simple>${headers}</simple>
</setHeader> {code}
This code was always used this way (don't know why, not written by me). Is (or 
was) the CamelVelocityTemplate header as a Camel header evaluated differently 
than a normal header. Now it seems that it first evaluates it as simple, before 
it evaluate it as velocity template (but then it's already a string).

When it first evaluates it ${headers} in simple is where the error occurs. When 
I set CamelVelocityTemplate as a constant, like it also done in the 
documentation, it works.

> 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&amp;multiline=true&amp;showHeaders=false&amp;showBody=true&amp;showBodyType=true&amp;showFiles=true&amp;showException=false&amp;showStackTrace=false&amp;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)

Reply via email to