davsclaus opened a new pull request, #29751:
URL: https://github.com/apache/camel/pull/29751

   Fixes https://issues.apache.org/jira/browse/CAMEL-25979
   
   With `allowTemplateFromHeader=true`, the language producer takes the script 
from the `CamelLanguageScript` header. Three problems:
   
   - a String script was compiled twice;
   - with `cacheScript=true` the second compile was stored as the cached 
expression of the endpoint. With a `resource:` script (content cache on, the 
default), later exchanges **without** the header ran the header's script. With 
an inline script, the endpoint's expression was dropped and compiled again on 
every exchange;
   - the header stayed on the message, so the next language endpoint with 
`allowTemplateFromHeader` ran the same script again.
   
   ## Change
   
   `LanguageProducer` now handles a header script on its own path: it compiles 
the script once (with the result type), evaluates it for this exchange only, 
stops it after use, and removes the header first. The velocity, freemarker and 
xslt components handle their template headers the same way. The endpoint's 
script, its cache and the `contentResolvedFromResource` flag are no longer 
touched by a header script. An `Expression` given as the header is used as 
before; the header is removed too.
   
   Docs: the header description (component JSON, catalog, endpoint DSL) and the 
component page say the header is used once and removed. The 4.24 upgrade guide 
has a note: a route that relied on the header staying on the message must set 
it again.
   
   ## Tests
   
   New `LanguageScriptInHeaderCacheTest` in camel-core. All four tests failed 
before the fix:
   - resource script with `cacheScript=true`, header on exchange 2 of 4: 
exchanges 3 and 4 run the endpoint script (before: `Bye D`);
   - inline script with `cacheScript=true`: the endpoint's cached expression is 
the same instance after a header exchange (before: `null`);
   - two language endpoints in a row: the second runs its own script and the 
header is gone (before: `Bye Bye B`);
   - a counting language: the header script is compiled once (before: 2).
   
   `mvn test 
-Dtest='org.apache.camel.component.language.*Test,XPathLanguageEndpointTest'` 
in camel-core: 21 tests, all pass.
   
   _Claude Code on behalf of davsclaus_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to