You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by David Karlsen <da...@gmail.com> on 2011/10/10 22:26:12 UTC

Iterate over multivalued header

Hi.

I'd like to iterate over a header containing a list and doing a "to
uri" for each value.
Is this possible?

The splitter seems to only support body values, and camel:loop seems
to be count-oriented.

I could of course loop and use an expression for the list length and
access it by index - but maybe something cleaner and down to the point
exists OOTB?

-- 
--
David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen

Re: Iterate over multivalued header

Posted by "Kripalani, Raul" <ra...@fusesource.com>.
Hi,

Depending on the behaviour that you are pursuing, and assuming that at some
point you will want to send the exchange to the list of endpoints stored in
your header (either sequentially or in a multicast fashion), you could use
different the different enterprise integration patterns offered by Camel to
apply some routing logic.

You can take a look at Recipient List (
http://camel.apache.org/recipient-list.html) and Routing Slip (
http://camel.apache.org/routing-slip.html) as an example.

Regards,
Raúl.

On 10 October 2011 22:26, David Karlsen <da...@gmail.com> wrote:

> Hi.
>
> I'd like to iterate over a header containing a list and doing a "to
> uri" for each value.
> Is this possible?
>
> The splitter seems to only support body values, and camel:loop seems
> to be count-oriented.
>
> I could of course loop and use an expression for the list length and
> access it by index - but maybe something cleaner and down to the point
> exists OOTB?
>
> --
> --
> David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
>

Re: Iterate over multivalued header

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Oct 12, 2011 at 2:15 PM, David Karlsen <da...@gmail.com> wrote:
> Can I control where camel will put the splitted value - or will it
> always be the body?

If you iterator returns an org.apache.camel.Message instance then
Camel will use that as is. Any other value will be regarded as the
body.


>
> 2011/10/11 Claus Ibsen <cl...@gmail.com>:
>> On Mon, Oct 10, 2011 at 10:26 PM, David Karlsen <da...@gmail.com> wrote:
>>> Hi.
>>>
>>> I'd like to iterate over a header containing a list and doing a "to
>>> uri" for each value.
>>> Is this possible?
>>>
>>> The splitter seems to only support body values, and camel:loop seems
>>> to be count-oriented.
>>>
>>
>> The splitter supports using a custom expression, so you can refer to a header.
>> The splitter will then try to iterate that, so if the header is a
>> List/Collection etc. then it can do that out of the box.
>> I also believe if its a String value, then it will iterate using comma
>> separator.
>>
>> Alternative you can write your custom expression and use that, or use
>> a method call expression and return the list of values from the header
>> to split.
>>
>>> I could of course loop and use an expression for the list length and
>>> access it by index - but maybe something cleaner and down to the point
>>> exists OOTB?
>>>
>>> --
>>> --
>>> David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> FuseSource
>> Email: cibsen@fusesource.com
>> Web: http://fusesource.com
>> Twitter: davsclaus, fusenews
>> Blog: http://davsclaus.blogspot.com/
>> Author of Camel in Action: http://www.manning.com/ibsen/
>>
>
>
>
> --
> --
> David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Iterate over multivalued header

Posted by David Karlsen <da...@gmail.com>.
Can I control where camel will put the splitted value - or will it
always be the body?

2011/10/11 Claus Ibsen <cl...@gmail.com>:
> On Mon, Oct 10, 2011 at 10:26 PM, David Karlsen <da...@gmail.com> wrote:
>> Hi.
>>
>> I'd like to iterate over a header containing a list and doing a "to
>> uri" for each value.
>> Is this possible?
>>
>> The splitter seems to only support body values, and camel:loop seems
>> to be count-oriented.
>>
>
> The splitter supports using a custom expression, so you can refer to a header.
> The splitter will then try to iterate that, so if the header is a
> List/Collection etc. then it can do that out of the box.
> I also believe if its a String value, then it will iterate using comma
> separator.
>
> Alternative you can write your custom expression and use that, or use
> a method call expression and return the list of values from the header
> to split.
>
>> I could of course loop and use an expression for the list length and
>> access it by index - but maybe something cleaner and down to the point
>> exists OOTB?
>>
>> --
>> --
>> David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>



-- 
--
David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen

Re: Iterate over multivalued header

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Oct 10, 2011 at 10:26 PM, David Karlsen <da...@gmail.com> wrote:
> Hi.
>
> I'd like to iterate over a header containing a list and doing a "to
> uri" for each value.
> Is this possible?
>
> The splitter seems to only support body values, and camel:loop seems
> to be count-oriented.
>

The splitter supports using a custom expression, so you can refer to a header.
The splitter will then try to iterate that, so if the header is a
List/Collection etc. then it can do that out of the box.
I also believe if its a String value, then it will iterate using comma
separator.

Alternative you can write your custom expression and use that, or use
a method call expression and return the list of values from the header
to split.

> I could of course loop and use an expression for the list length and
> access it by index - but maybe something cleaner and down to the point
> exists OOTB?
>
> --
> --
> David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/