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: Question on splitter
Date Thu, 29 Apr 2010 04:47:14 GMT
On Thu, Apr 29, 2010 at 5:54 AM, DaHoopster <hwang@structuralinvest.com> wrote:
>
> Thanks for the reply Ashwin.
>
> No, MyObject is not  serializable but it's annotated with XML annotations.
> We are marshaling the object into XML messages and putting XML messages onto
> the queues.
>
> The examples on the page you gave me don't work because the syntax are not
> the same as the version of camel I am using, which is 2.2.6. So given that
> we are using XML messages, is there a quick solution to the problem?
>

The splitter wiki page have an XML based example using XPath.

> Here is what the message look like:
> <MyObject>
>  <MyNumbers>
>    <MyNumber>blaM/MyNumber>
>    <MyNumber>blaM/MyNumber>
>    <MyNumber>blaM/MyNumber>
>    <MyNumber>blaM/MyNumber>
>  </MyNumbers>
> </MyObject>
>

You may use an xpath expression, something like
    split(xpath("/MyObject/MyNumbers/MyNumber/text")).


>
> Thanks,
> Han
>
>
> Ashwin Karpe wrote:
>>
>> Hi,
>>
>> First of all, I assume that the MyObject class is serializable.
>>
>> Please check out the section "Using a Pojo to do the splitting" at the
>> link
>>  http://camel.apache.org/splitter.html
>> http://camel.apache.org/splitter.html
>>
>> There is a very good and straightforward example that can do the trick for
>> you.
>>
>> What you need is to to take the object, split its payload, create a list
>> of items and allow the splitter to take it from there.
>>
>> Cheers,
>>
>> Ashwin...
>>
>>
>>
>> DaHoopster wrote:
>>>
>>> Hi,
>>>
>>> I am having trouble using the splitter. I think it's a very simple
>>> problem but I just can't figure what. I have tried a couple of way to
>>> split but no luck. Here is what I have:
>>>
>>> Method 1:
>>> =====================================================================
>>> route config:
>>>
>>>         from("activemq:queue:inputQueue?jmsMessageType=Object").
>>>                 to("customSorter").
>>>                 split(body()).
>>>                 to("activemq:queue:outputQueue?jmsMessageType=Text");
>>>
>>> My customerSorter code:
>>>
>>> the object.getNumbers returns a list of MyNumber object
>>>
>>>     public void process(Exchange exchange) throws Exception
>>>     {
>>>         final MyObject object = exchange.getIn().getBody(MyObject.class);
>>>         final MyObject sorted = sort(object);
>>>         exchange.getIn().setBody(object.getNumbers());
>>>     }
>>>
>>> For some reason, I am not getting anything on the output queue.
>>>
>>>
>>> Method 2:
>>> =====================================================================
>>>
>>> Route config:
>>>
>>>         from("activemq:queue:inputQueue?jmsMessageType=Object").
>>>                 to("customSorter").
>>>                 split(new MySplitExpression()).
>>>                 to("activemq:queue:outputQueue?jmsMessageType=Text");
>>>
>>> MySplitExpression:
>>>
>>>     public <T> T evaluate(final Exchange exchange, final Class<T>
tClass)
>>>     {
>>>         final MyObject myObject =
>>> exchange.getIn().copy().getBody(MyObject.class);
>>>         final List<Message> answer = new LinkedList<Message>();
>>>         for (final MyNumber myNumber : inventory.getNumbers())
>>>         {
>>>             final Message answerMessage = exchange.getIn().copy();
>>>             answerMessage.setBody(myNumber, MyNumber.class);
>>>             System.out.println("=== splitting ===");
>>>         }
>>>         return (T) answer;
>>>     }
>>>
>>> I am seeing the message being printed out but I still don't have any
>>> messages on the output queue.
>>>
>>> Could you help me see what's going on here?
>>>
>>> Thanks,
>>> Han
>>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Question-on-splitter-tp28395839p28396442.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message