You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Olivier Roger <ol...@bsb.com> on 2010/06/08 17:53:26 UTC

Expression Attributes

Hello Camel,

I had a question about the attributes that can be added in the expression as
explained with $user in: http://camel.apache.org/groovy.html

> Attributes
>
> You can add your own attributes with the attribute(name, value) DSL
> method, such as:
> 
> In the sample below we add an attribute user that is an object we already
> have instantiated as myUser. 
> This object has a getFirstName() method that we want to set as header on
> the message. We use the 
> groovy language to concat the first and last name into a single string
> that is returned.
> 
> from("direct:in").setHeader("name").groovy("'$user.firstName
> $user.lastName'").attribute("user", myUser").to("seda:users");

If I got this right, the user bean is dependent to the message payload.
Otherwise every message would have the same name.

I was wondering how I could instantiate that bean. I could not find
information about that in the online documentation. I would also like to use
it with Spring DSL.

Any help on this would be welcome,

Thanks in advance

Olivier
-- 
View this message in context: http://old.nabble.com/Expression-Attributes-tp28819757p28819757.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Expression Attributes

Posted by Olivier Roger <ol...@bsb.com>.
Thank you Willem,

Maybe there is an other way to do what I am trying to do:

My route receives XML-based messages containing a Metadata element.
This element can contain any number of <entry name="" value" /> just like a
Map data structure.
An XMLBeans class is available to deserialize the element into a POJO
Metadata Object.

I would like to write an expression to perform a computation on the metadata
POJO object.
Any script language would do, best would be for it to be parameterizable.

The result of the expression would be stored in the message header for later
usage.

    <from uri="direct:in"/>
    <setHeader headerName="returnValue">
        <expression language="${lang}">${expr}</expression> // I do not know
if using a placeholder ${lang} there is supported
    </setHeader>
    <to uri="direct:out"/>

With the following externalized property file:

lang=groovy
expr=metadata.value

I guess this can be done inside a bean, best would be to do it in the route
declaration in Spring DSL.

Any idea is welcome,

Olivier


willem.jiang wrote:
> 
> Hi,
> 
> I just went through the camel-groovy code and wrote some test code, I 
> don't think the attribut() DSL is working out of box.
> 
> Please feel free to create a JIRA[1] for it.
> [1]https://issues.apache.org/activemq/browse/CAMEL
> 
> Willem
> 
> Olivier Roger wrote:
>> Hello Camel,
>> 
>> I had a question about the attributes that can be added in the expression
>> as
>> explained with $user in: http://camel.apache.org/groovy.html
>> 
>>> Attributes
>>>
>>> You can add your own attributes with the attribute(name, value) DSL
>>> method, such as:
>>>
>>> In the sample below we add an attribute user that is an object we
>>> already
>>> have instantiated as myUser. 
>>> This object has a getFirstName() method that we want to set as header on
>>> the message. We use the 
>>> groovy language to concat the first and last name into a single string
>>> that is returned.
>>>
>>> from("direct:in").setHeader("name").groovy("'$user.firstName
>>> $user.lastName'").attribute("user", myUser").to("seda:users");
>> 
>> If I got this right, the user bean is dependent to the message payload.
>> Otherwise every message would have the same name.
>> 
>> I was wondering how I could instantiate that bean. I could not find
>> information about that in the online documentation. I would also like to
>> use
>> it with Spring DSL.
>> 
>> Any help on this would be welcome,
>> 
>> Thanks in advance
>> 
>> Olivier
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Expression-Attributes-tp28819757p28827053.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Expression Attributes

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

I just went through the camel-groovy code and wrote some test code, I 
don't think the attribut() DSL is working out of box.

Please feel free to create a JIRA[1] for it.
[1]https://issues.apache.org/activemq/browse/CAMEL

Willem

Olivier Roger wrote:
> Hello Camel,
> 
> I had a question about the attributes that can be added in the expression as
> explained with $user in: http://camel.apache.org/groovy.html
> 
>> Attributes
>>
>> You can add your own attributes with the attribute(name, value) DSL
>> method, such as:
>>
>> In the sample below we add an attribute user that is an object we already
>> have instantiated as myUser. 
>> This object has a getFirstName() method that we want to set as header on
>> the message. We use the 
>> groovy language to concat the first and last name into a single string
>> that is returned.
>>
>> from("direct:in").setHeader("name").groovy("'$user.firstName
>> $user.lastName'").attribute("user", myUser").to("seda:users");
> 
> If I got this right, the user bean is dependent to the message payload.
> Otherwise every message would have the same name.
> 
> I was wondering how I could instantiate that bean. I could not find
> information about that in the online documentation. I would also like to use
> it with Spring DSL.
> 
> Any help on this would be welcome,
> 
> Thanks in advance
> 
> Olivier