You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by cmoulliard <cm...@gmail.com> on 2008/03/18 10:55:41 UTC

How can I add a property during a transformation step

Hi,

I would like to know if this is possible to enrich the message(s) (by adding
a property or a header) created during a transformation step. 

ex :
        from("file:///c:/temp/test?noop=true")
        .unmarshal().csv()
        .to("test-jms:queue:test.queue");

According to this DSL route, the files created in the dir c:/temp/test will
be read, parsed and transformed using a CsvDataFormat. Next, the result of
this tranformation will be placed into a queue (test.queue).

My question is the following ?

Is it possible to add a property/header to the messages posted in a queue ?

        from("file:///c:/temp/test?noop=true")
        .unmarshal().csv()
        .setProperty("Client", "Jack")
        .to("test-jms:queue:test.queue");

The idea is that in the next route, I can check the property/header name and
depending on the value I can process differently the messages.

Regards,

Charles

-- 
View this message in context: http://www.nabble.com/How-can-I-add-a-property-during-a-transformation-step-tp16117586s22882p16117586.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: How can I add a property during a transformation step

Posted by James Strachan <ja...@gmail.com>.
On 18/03/2008, cmoulliard <cm...@gmail.com> wrote:
>
>  The setHeader method does not accept as parameters (string, string) or
>  (string, object) but (string, expression)

Sorry - try

setHeader("Client").constant("Jack");

You could use something like

setHeader("Client").xpath("/order/customer");

if you need to use expressions etc

I've just added a setHeader(String name, String value) to avoid
further confusion.


>  The method setHeader(String, Expression) in the type
>  ProcessorType<ProcessorType> is not applicable for the arguments (String,
>  String)
>
>  What is purpose of "expression" when we want to place something in the
>  header ?

To support dynamic expressions at runtime - i.e. so based on the
Exchange / Message you get a different value.

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: How can I add a property during a transformation step

Posted by cmoulliard <cm...@gmail.com>.
The setHeader method does not accept as parameters (string, string) or
(string, object) but (string, expression)

The method setHeader(String, Expression) in the type
ProcessorType<ProcessorType> is not applicable for the arguments (String,
String)

What is purpose of "expression" when we want to place something in the
header ?

Regards,

Charles



James.Strachan wrote:
> 
> On 18/03/2008, cmoulliard <cm...@gmail.com> wrote:
>>
>>  Hi,
>>
>>  I would like to know if this is possible to enrich the message(s) (by
>> adding
>>  a property or a header) created during a transformation step.
>>
>>  ex :
>>         from("file:///c:/temp/test?noop=true")
>>         .unmarshal().csv()
>>         .to("test-jms:queue:test.queue");
>>
>>  According to this DSL route, the files created in the dir c:/temp/test
>> will
>>  be read, parsed and transformed using a CsvDataFormat. Next, the result
>> of
>>  this tranformation will be placed into a queue (test.queue).
>>
>>  My question is the following ?
>>
>>  Is it possible to add a property/header to the messages posted in a
>> queue ?
>>
>>         from("file:///c:/temp/test?noop=true")
>>         .unmarshal().csv()
>>         .setProperty("Client", "Jack")
>>         .to("test-jms:queue:test.queue");
>>
>>  The idea is that in the next route, I can check the property/header name
>> and
>>  depending on the value I can process differently the messages.
> 
> Absolutely!
> 
> We have properties on an Exchange which are intended to be transient
> things during the processing, then headers on a Message which are
> typically intended to travel over the wire (some endpoints might
> filter out or transform some headers).
> 
> So if you use
> 
> from("file:///c:/temp/test?noop=true")
>        .unmarshal().csv()
>        .setHeader("Client", "Jack")
>        .to("test-jms:queue:test.queue");
> 
> it will populate the JMS header "Client"
> 
> I guess part of the confusion is the JMS API refers to them as
> 'properties' :) We've kinda used HTTP/email style terminology for
> headers & properties which might cause confusion.
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/How-can-I-add-a-property-during-a-transformation-step-tp16117586s22882p16118590.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: How can I add a property during a transformation step

Posted by James Strachan <ja...@gmail.com>.
On 18/03/2008, cmoulliard <cm...@gmail.com> wrote:
>
>  Hi,
>
>  I would like to know if this is possible to enrich the message(s) (by adding
>  a property or a header) created during a transformation step.
>
>  ex :
>         from("file:///c:/temp/test?noop=true")
>         .unmarshal().csv()
>         .to("test-jms:queue:test.queue");
>
>  According to this DSL route, the files created in the dir c:/temp/test will
>  be read, parsed and transformed using a CsvDataFormat. Next, the result of
>  this tranformation will be placed into a queue (test.queue).
>
>  My question is the following ?
>
>  Is it possible to add a property/header to the messages posted in a queue ?
>
>         from("file:///c:/temp/test?noop=true")
>         .unmarshal().csv()
>         .setProperty("Client", "Jack")
>         .to("test-jms:queue:test.queue");
>
>  The idea is that in the next route, I can check the property/header name and
>  depending on the value I can process differently the messages.

Absolutely!

We have properties on an Exchange which are intended to be transient
things during the processing, then headers on a Message which are
typically intended to travel over the wire (some endpoints might
filter out or transform some headers).

So if you use

from("file:///c:/temp/test?noop=true")
       .unmarshal().csv()
       .setHeader("Client", "Jack")
       .to("test-jms:queue:test.queue");

it will populate the JMS header "Client"

I guess part of the confusion is the JMS API refers to them as
'properties' :) We've kinda used HTTP/email style terminology for
headers & properties which might cause confusion.

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com