You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Mark Doyle <ma...@gmail.com> on 2012/10/07 17:09:06 UTC

Splitting a POJO message into multiple messages containing values of a collection from a stored as a field on the POJO.

Hi all,

I there a simple way of taking a POJO from a message body and calling a
method on one of it's fields, e.g someMap.values() to return messages for
each element in a collection. I want to do this for a splitter.

I can do it with various other methods, beans, processors, transformers etc
but it all seems a bit long winded.

Re: Splitting a POJO message into multiple messages containing values of a collection from a stored as a field on the POJO.

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Oct 8, 2012 at 2:28 PM, Mark Doyle <ma...@gmail.com> wrote:
> Hi Claus,
>
> Nothing so complex actually. I simply want to call a method on the POJO's
> map field.
>
> Here's the full example:
>
> I have a POJO arriving in a message body. The POJO has a Map field, let's
> say someMap. I want to split the message into multiple messages, one for
> each value in the map. I don't care about the keys.
>
> Something like this (pseudo)
> <split>
>    ${body}.someMap.values()
> </split>
>

Ah okay yeah that should be doable using the simple language.
Or other languages like OGNL, Mvel, Groovy etc.

Simple has OGNL like method call:
http://camel.apache.org/simple

<split>
  <simple>${body.someMap().values()}</simple>
  ...
</split>

This will invoke a getter getSomeMap() on the method body, and invoke
its values() method.
And use that for the splitter.



> I created a simple utility/helper class that takes the POJO and returns the
> List of values which I can route through using camel:method. e.g:
> <camel:split>
>     <camel:method ref="myClassExtractor" method="extractValues"/>
>     <to uri="seda:parametersOut"/>
> </camel:split>
>
> But I wondered if there was a one-step method, completely in configuration.
>
> On 8 October 2012 10:00, Claus Ibsen <cl...@gmail.com> wrote:
>
>> On Sun, Oct 7, 2012 at 5:09 PM, Mark Doyle <ma...@gmail.com>
>> wrote:
>> > Hi all,
>> >
>> > I there a simple way of taking a POJO from a message body and calling a
>> > method on one of it's fields, e.g someMap.values() to return messages for
>> > each element in a collection. I want to do this for a splitter.
>> >
>> > I can do it with various other methods, beans, processors, transformers
>> etc
>> > but it all seems a bit long winded.
>>
>> You want to invoke a method on each value from a map? And should you
>> do something with their responses (eg if they are not void methods)?
>>
>> You can use an dynamic language like groovy, it should have extensions
>> to collections to do this.
>> http://camel.apache.org/groovy.html
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> FuseSource is now part of Red Hat
>> Email: cibsen@redhat.com
>> Web: http://fusesource.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Splitting a POJO message into multiple messages containing values of a collection from a stored as a field on the POJO.

Posted by Mark Doyle <ma...@gmail.com>.
Hi Claus,

Nothing so complex actually. I simply want to call a method on the POJO's
map field.

Here's the full example:

I have a POJO arriving in a message body. The POJO has a Map field, let's
say someMap. I want to split the message into multiple messages, one for
each value in the map. I don't care about the keys.

Something like this (pseudo)
<split>
   ${body}.someMap.values()
</split>

I created a simple utility/helper class that takes the POJO and returns the
List of values which I can route through using camel:method. e.g:
<camel:split>
    <camel:method ref="myClassExtractor" method="extractValues"/>
    <to uri="seda:parametersOut"/>
</camel:split>

But I wondered if there was a one-step method, completely in configuration.

On 8 October 2012 10:00, Claus Ibsen <cl...@gmail.com> wrote:

> On Sun, Oct 7, 2012 at 5:09 PM, Mark Doyle <ma...@gmail.com>
> wrote:
> > Hi all,
> >
> > I there a simple way of taking a POJO from a message body and calling a
> > method on one of it's fields, e.g someMap.values() to return messages for
> > each element in a collection. I want to do this for a splitter.
> >
> > I can do it with various other methods, beans, processors, transformers
> etc
> > but it all seems a bit long winded.
>
> You want to invoke a method on each value from a map? And should you
> do something with their responses (eg if they are not void methods)?
>
> You can use an dynamic language like groovy, it should have extensions
> to collections to do this.
> http://camel.apache.org/groovy.html
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cibsen@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>

Re: Splitting a POJO message into multiple messages containing values of a collection from a stored as a field on the POJO.

Posted by Claus Ibsen <cl...@gmail.com>.
On Sun, Oct 7, 2012 at 5:09 PM, Mark Doyle <ma...@gmail.com> wrote:
> Hi all,
>
> I there a simple way of taking a POJO from a message body and calling a
> method on one of it's fields, e.g someMap.values() to return messages for
> each element in a collection. I want to do this for a splitter.
>
> I can do it with various other methods, beans, processors, transformers etc
> but it all seems a bit long winded.

You want to invoke a method on each value from a map? And should you
do something with their responses (eg if they are not void methods)?

You can use an dynamic language like groovy, it should have extensions
to collections to do this.
http://camel.apache.org/groovy.html


-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen