[
https://issues.apache.org/jira/browse/CAMEL-9002?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14639145#comment-14639145
]
Chris Pimlott edited comment on CAMEL-9002 at 7/23/15 5:11 PM:
---------------------------------------------------------------
I am using velocity templates to format email messages. Being able to set
headers is very handy in order to generate the subject line.
{code}
#set( $headers.subject = "[$client] New project created: $projectName" )
{code}
However, I also have to put a lot of boilerplate in the template to initialize
variables depending on the domain object message body:
{code}
#set( $request = $body )
#set( $client = $request.client[0] )
#set( $requestNumber = $request.parts[0].requestNumber )
#set( $projectName = $request.parts[0].projectName )
#set( $sourceLocale = $request.parts[0].sourceLocale )
{code}
Have all these initializations in the template is confusing for the users and
invites potential errors. So I was looking for a way to pre-initialize the
context with my domain-specific variables, while still waiting to be able to
get values "out" of the template for subject, from, etc. I really don't
specific care about making a new velocity context, just adding a few variables.
was (Author: pimlottc):
I am using velocity templates to format email messages. Being able to set
headers is very handy in order to generate the subject line.
{code}
#set( $headers.subject = "[$client] New project created: $projectName" )
{code}
However, I also have to put a lot of boilerplate in the template to initialize
variables depending on the domain object message body:
{code}
#set( $request = $body )
#set( $client = $request.client[0] )
#set( $requestNumber = $request.parts[0].requestNumber )
#set( $projectName = $request.parts[0].projectName )
#set( $sourceLocale = $request.parts[0].sourceLocale )
{code}
Have all these initializations in the template is confusing for the users and
invites potential errors. So I was looking for a way to pre-initialize the
context with my domain-specific variables, while still waiting to be able to
get values "out" of the template for subject, from, etc. I really don't
specific care about making a new velocity context, just adding a few new
variables.
> Headers set within velocity header are not saved when using custom
> VelocityContext
> ----------------------------------------------------------------------------------
>
> Key: CAMEL-9002
> URL: https://issues.apache.org/jira/browse/CAMEL-9002
> Project: Camel
> Issue Type: Bug
> Affects Versions: 2.15.2
> Reporter: Chris Pimlott
> Priority: Minor
> Attachments: VelocityContextHeaderSetHeaderTest.java
>
>
> Normally, any headers set within the velocity header are preserved as headers
> on the out message. However, this does not work if you use your own
> VelocityContext via the CamelVelocityContext. This is because
> VelocityEndpoint relies on the fact that the "headers" entry in the velocity
> context normally points directly to the current Exchange's in headers. This
> is not likely true when using an existing velocity context.
> A more foolproof solution might be to look for and explicitly copy any
> updated headers from the velocity context to the out message.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)