camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Pimlott (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CAMEL-9002) Headers set within velocity header are not saved when using custom VelocityContext
Date Wed, 29 Jul 2015 17:30:04 GMT

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

Chris Pimlott edited comment on CAMEL-9002 at 7/29/15 5:29 PM:
---------------------------------------------------------------

For reference, I found using SpEL to be the easiest way to define the context map when using
the Spring DSL:

{code}
    <setHeader headerName="CamelVelocitySupplementalContext">
      <spel>#{ {
        a: "apple",
        DateTimeFormat: T(org.joda.time.format.DateTimeFormat),
      } }</spel>
    </setHeader>
{code}

To add keys to an existing map, you can use the Guava map builder:
{code}
    <setHeader headerName="CamelVelocitySupplementalContext">
      <description>Add to context map, respective existing entries (if any)</description>
      <spel>#{ new com.google.common.collect.ImmutableMap.Builder()
                .putAll(request.headers[CamelVelocitySupplementalContext] ?: {:})
                .put("a", "apple")
                .put("DateTimeFormat", T(org.joda.time.format.DateTimeFormat))
                .build() }</spel>
    </setHeader>
{code}


was (Author: pimlottc):
For reference, I found using SpEL to be the easiest way to define the context map when using
the Spring DSL:

{code}
    <setHeader headerName="CamelVelocitySupplementalContext">
      <spel>#{ {
        DateTimeFormat: T(org.joda.time.format.DateTimeFormat),
        DateTimeZone: T(org.joda.time.DateTimeZone)
      } }</spel>
    </setHeader>
{code}

To add keys to an existing map, you can use the Guava map builder:
{code}
    <setHeader headerName="CamelVelocitySupplementalContext">
      <description>Add to context map, respective existing entries (if any)</description>
      <spel>#{ new com.google.common.collect.ImmutableMap.Builder()
                .putAll(request.headers[CamelVelocitySupplementalContext] ?: {:})
                .put("DateTimeFormat", T(org.joda.time.format.DateTimeFormat))
                .put("DateTimeZone", T(org.joda.time.DateTimeZone))
                .build() }</spel>
    </setHeader>
{code}

> 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: Improvement
>    Affects Versions: 2.15.2
>            Reporter: Chris Pimlott
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 2.16.0
>
>         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)

Mime
View raw message