camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Splitting a POJO message into multiple messages containing values of a collection from a stored as a field on the POJO.
Date Mon, 08 Oct 2012 13:33:30 GMT
On Mon, Oct 8, 2012 at 2:28 PM, Mark Doyle <markjohndoyle@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 <claus.ibsen@gmail.com> wrote:
>
>> On Sun, Oct 7, 2012 at 5:09 PM, Mark Doyle <markjohndoyle@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

Mime
View raw message