Claus Ibsen created CAMEL-27744:
-----------------------------------
Summary: camel-velocity: header URI replace, template header
precedence, include charset, log name
Key: CAMEL-27744
URL: https://issues.apache.org/jira/browse/CAMEL-27744
Project: Camel
Issue Type: Bug
Components: camel-velocity
Reporter: Claus Ibsen
Fix For: 4.24.0
Found while improving the option descriptions of camel-velocity for CAMEL-23832
(commit
https://github.com/apache/camel/commit/b82eef5b59e581059179cfd3aa240e1194ec9c8c).
These are separate problems of the component; the descriptions commit only
documents the current behavior.
h4. 1. CamelVelocityResourceUri replaces the resource URI in the whole endpoint
URI
{{VelocityEndpoint.findOrCreateEndpoint()}} builds the URI of the new endpoint
with {{uri.replace(getResourceUri(), newResourceUri)}}. {{String.replace}}
replaces every occurrence, also inside option values. With
{{velocity:letter.vm?propertiesFile=letter.vm.properties}} and the header
{{other.vm}}, the new endpoint gets {{propertiesFile=other.vm.properties}},
which does not exist, so the exchange fails.
Proposed change: build the new URI from the scheme, the new resource URI and
the query of the endpoint URI, so only the path changes.
h4. 2. CamelVelocityTemplate wins over CamelVelocityResourceUri when both are
set
{{VelocityEndpoint.onExchange()}} checks {{CamelVelocityResourceUri}} first,
removes it and calls {{onExchange()}} of the endpoint for the new URI. That
endpoint has {{allowTemplateFromHeader=true}} too (from the URI or the
component), so it reads {{CamelVelocityTemplate}} and renders that text. The
resource of the header is never rendered, although the order of the code
suggests that the resource URI should take precedence (as in camel-chunk).
Proposed change: decide the precedence and apply it in one place, for example
remove {{CamelVelocityTemplate}} too before handing over, or check it first.
h4. 3. Templates included from the classpath are read with the default charset
of the JVM
{{CamelVelocityClasspathResourceLoader.getResourceReader(name, encoding)}}
returns {{new InputStreamReader(is)}} and ignores the {{encoding}} that
Velocity passes ({{resource.default_encoding}}, UTF-8 by default). A template
that {{#parse}} or {{#include}} loads from the classpath is decoded with the
JVM default charset, while one from the file system uses the Velocity encoding.
Proposed change: use {{new InputStreamReader(is, encoding)}}.
h4. 4. The Velocity runtime log goes to a logger named
org.apache.camel.maven.Velocity
{{VelocityEndpoint.getVelocityEngine()}} sets {{runtime.log.name}} to
{{org.apache.camel.maven.Velocity}}. This component is not part of the Maven
tooling, so a user who configures logging for
{{org.apache.camel.component.velocity}} does not see the messages of Velocity.
Proposed change: use a logger below {{org.apache.camel.component.velocity}},
and mention it in the doc page.
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)