[ 
https://issues.apache.org/jira/browse/CAMEL-25585?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-25585.
---------------------------------
    Resolution: Fixed

> camel-chunk - message body and header values are expanded as Chunk template 
> code instead of printed literally
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-25585
>                 URL: https://issues.apache.org/jira/browse/CAMEL-25585
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-chunk
>            Reporter: Andrea Cosentino
>            Assignee: Andrea Cosentino
>            Priority: Minor
>             Fix For: 4.24.0
>
>
> h3. Description
> When camel-chunk renders a template that outputs a message value, the Chunk 
> engine re-parses that value as template source and expands any Chunk tags 
> contained in it, instead of printing the value literally. For example a 
> template that prints the body:
> {noformat}
> This is the body {$body}
> {noformat}
> will, if the body itself contains Chunk markup, expand that markup rather 
> than output it verbatim.
> The cause is that ChunkEndpoint populates the engine with Chunk.putAll(...) 
> in ChunkEndpoint.onExchange 
> (components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkEndpoint.java,
>  around line 123). In the Chunk API a value set this way is parsed for tags 
> and expanded; only Chunk.setLiteral(...) keeps a value literal. Camel never 
> calls setLiteral.
> h3. Why this matters
> This is inconsistent with Camel's other template components 
> (camel-freemarker, camel-velocity, camel-mustache), which substitute message 
> data inertly: a body or header whose content happens to look like template 
> markup is printed verbatim. In camel-chunk the same data is interpreted as 
> template code.
> h3. Steps to reproduce
> Template themes/nested.chtml:
> {noformat}
> This is the body {$body}
> {noformat}
> Route:
> {noformat}
> from("direct:a").to("chunk://nested");
> {noformat}
> Send a message with header name=World and body:
> {noformat}
> {$headers.name}
> {noformat}
> h3. Expected
> {noformat}
> This is the body {$headers.name}
> {noformat}
> (the body printed literally)
> h3. Actual
> {noformat}
> This is the body World
> {noformat}
> (the body is re-parsed and the inner tag expanded)
> h3. Proposed fix
> Bind message data into the Chunk engine so values are treated literally (for 
> example, use setLiteral for String values), so that only the route author's 
> template file is parsed as template code. Add a regression test. While in 
> this code, review the reuse of a single cached Chunk instance across 
> exchanges.
> h3. Affected
> components/camel-chunk - main, camel-4.22.x, camel-4.18.x.



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

Reply via email to