You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Hossein <ma...@csc.com> on 2011/01/31 18:59:34 UTC

Patch - Aggregator EIP

Hi,
Wanted to submit a patch on link below. The given example produces NPE
because on first message, the oldExchange is null.
http://fusesource.com/docs/router/1.5/eip/MsgRout-Aggregator.html

--Hossein Amerkashi




package some.package;

import org.apache.camel.processor.aggregate.AggregationStrategy;
import org.apache.camel.Exchange;


public class MessageBatcher implements AggregationStrategy {
    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {

        //On every first batch message, the oldExchange will be null,
        // and as result, we just return the newExchange
        if (oldExchange == null)
        {
            return newExchange;
        }

        //Get the new and old message, then create a string that has old +
new
        String oldBody=oldExchange.getIn().getBody(String.class);
        String newBody = newExchange.getIn().getBody(String.class);
        String concatBody = oldBody.concat(newBody);

        // Now put into old, the new string
        oldExchange.getIn().setBody(concatBody);

        return oldExchange;
    }
}
-- 
View this message in context: http://camel.465427.n5.nabble.com/Patch-Aggregator-EIP-tp3364947p3364947.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Patch - Aggregator EIP

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Thanks for reporting.

The link you found is for MR 1.5 (eg Camel 1.x). And that code is correct.
The documentation for MR 2.x is having a minor issue, so I have created a ticket
http://fusesource.com/issues/browse/MR-412


On Mon, Jan 31, 2011 at 6:59 PM, Hossein <ma...@csc.com> wrote:
>
> Hi,
> Wanted to submit a patch on link below. The given example produces NPE
> because on first message, the oldExchange is null.
> http://fusesource.com/docs/router/1.5/eip/MsgRout-Aggregator.html
>
> --Hossein Amerkashi
>
>
>
>
> package some.package;
>
> import org.apache.camel.processor.aggregate.AggregationStrategy;
> import org.apache.camel.Exchange;
>
>
> public class MessageBatcher implements AggregationStrategy {
>    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
>
>        //On every first batch message, the oldExchange will be null,
>        // and as result, we just return the newExchange
>        if (oldExchange == null)
>        {
>            return newExchange;
>        }
>
>        //Get the new and old message, then create a string that has old +
> new
>        String oldBody=oldExchange.getIn().getBody(String.class);
>        String newBody = newExchange.getIn().getBody(String.class);
>        String concatBody = oldBody.concat(newBody);
>
>        // Now put into old, the new string
>        oldExchange.getIn().setBody(concatBody);
>
>        return oldExchange;
>    }
> }
> --
> View this message in context: http://camel.465427.n5.nabble.com/Patch-Aggregator-EIP-tp3364947p3364947.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



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

Re: Patch - Aggregator EIP

Posted by Willem Jiang <wi...@gmail.com>.
Yeah, the code is a bit old.
Which version of Camel are you using?
I'm assuming that you are using Camel 2.x.
There are some changes on the camel aggregate since Camel 2.0.

Can you check out the new version of document ?

Willem
On 2/1/11 1:59 AM, Hossein wrote:
>
> Hi,
> Wanted to submit a patch on link below. The given example produces NPE
> because on first message, the oldExchange is null.
> http://fusesource.com/docs/router/1.5/eip/MsgRout-Aggregator.html
>
> --Hossein Amerkashi
>
>
>
>
> package some.package;
>
> import org.apache.camel.processor.aggregate.AggregationStrategy;
> import org.apache.camel.Exchange;
>
>
> public class MessageBatcher implements AggregationStrategy {
>      public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
>
>          //On every first batch message, the oldExchange will be null,
>          // and as result, we just return the newExchange
>          if (oldExchange == null)
>          {
>              return newExchange;
>          }
>
>          //Get the new and old message, then create a string that has old +
> new
>          String oldBody=oldExchange.getIn().getBody(String.class);
>          String newBody = newExchange.getIn().getBody(String.class);
>          String concatBody = oldBody.concat(newBody);
>
>          // Now put into old, the new string
>          oldExchange.getIn().setBody(concatBody);
>
>          return oldExchange;
>      }
> }


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang