8 Replies Latest reply on Aug 17, 2009 10:09 AM by Robert Yetman

    Aggregator and NPE

    Robert Yetman Newbie

      Given the following route drawn in the EIP Editor (version 1.2.1):

       

      file -> multicast ->  xslt -> aggregator -> file

                            ->  xslt ->

       

      When I attempt to run a message through (using Fuse ESB 3.4.0.3), I get the following:

       

      ERROR - Aggregator    -

      java.lang.NullPointerException

      at org.apache.camel.processor.BatchProcessor.processExchange(BatchProcessor.java:151)

      at org.apache.camel.processor.BatchProcessor$BatchSender.sendExchanges(BatchProcessor.java:288)

      at org.apache.camel.processor.BatchProcessor$BatchSender.run(BatchProcessor.java:235)

       

      And only 1 of the XSLT transforms make it to the file output.

       

      The generated camel route looks like (greatly abbreviated):

       

       

       

      Any ideas?

       

      Edited by: bobyetman on Aug 17, 2009 11:33 AM

        • 1. Re: Aggregator and NPE
          Sailaja P Newbie

          Hi,

           

          Aggregator should contain a component inside it. So, I have placed the File Endpoint component inside the aggregator as shown below.

           

           

          <to uri="file:///c:/temp/output">

          </to>

          </aggregator>

          </route>

          </camelContext>

           

          Thanks,

          Sailaja.

          • 2. Re: Aggregator and NPE
            Robert Yetman Newbie

            So how do you do that in the EIP Diagram editor?

            • 3. Re: Aggregator and NPE
              Sailaja P Newbie

              Drag and drop the File Endpoint inside the Aggregator pattern.

               

              See the attached screen shot

               

              • 4. Re: Aggregator and NPE
                Robert Yetman Newbie

                Okay, gotcha, that's done, no more NPE, but only one of the XLST transforms is making it to the output file.   I'm struggling with the correct expression to just re-aggregate the 2 messages back into a single message.

                • 5. Re: Aggregator and NPE
                  Sailaja P Newbie

                  The default strategy for aggregator is to take the latest document.

                  So, if you want to reaggregate the messages then you need to write a custom strategy bean.

                   

                  I have give an example, which will aggregate incoming bids and return the highest bid.

                   

                  Source Code logic.

                  private static class MyAggregationStrategy implements AggregationStrategy {

                   

                      public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {

                          if (oldExchange == null) {

                              // the first time we only have the new exchange so it wins the first round

                              return newExchange;

                          }

                          int oldPrice = oldExchange.getIn().getBody(Integer.class);

                          int newPrice = newExchange.getIn().getBody(Integer.class);

                          // return the "winner" that has the highest price

                          return newPrice > oldPrice ? newExchange : oldExchange;

                      }

                  }

                   

                  Thanks,

                  Sailaja.

                  • 6. Re: Aggregator and NPE
                    Robert Yetman Newbie

                    Thanks, that's what I figured, after doing some more reading on the Camel web site.   In the multicast page, I see a ref to BodyOutAggregatingStrategy and BodyInAggregatingStrategy, I may try using those.

                    • 7. Re: Aggregator and NPE
                      Dinesh Reddy Newbie

                      Camel website always maintains the information that is supported with the latest camel version. The current camel version is 2.0. But FID 1.2.1 supports 1.5 version of camel. So you may not find some attributes in FID 1.2.1 that are introduced in 2.0 version of camel.

                      • 8. Re: Aggregator and NPE
                        Robert Yetman Newbie

                        Thanks for the heads up.   The BodyInAggregatingStrategy and BodyOutAggregatingStrategy are part of the camel junit tests, I found them in the 1.6.1 version of camel, and have imported them into my EIP project, and they're working fine.