2 Replies Latest reply on Aug 18, 2010 11:03 AM by dekk11

    custom aggregator strategy

    dekk11

      I implemented a custom AggregationStrategy that is aggregating "split" files based on a correlation of the original "pre-split" file id.  It will receive split files out of sequence and aggregate them into the original "pre-split" file. 

       

      My aggregate() method works for scenarios where it receives multiple files to aggregate, but it does not work where a single split file is the entire aggregate (CamelAggregatedSize=1).  My aggregate() method was only called once, in this case, because the completionSize=1 was met (CamelBatchComplete=true).

       

      On the first call to aggregate(), the newExchange.getIn().getBody() was null.  Shouldn't this have the body of the contents of the single split file that it received? 

       

      I get the following nested exception:

      "org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: java.io.File to the required type: byte[] ..."

       

      Any ideas?

       

      Steve

        • 1. Re: custom aggregator strategy
          davsclaus

          Can you post the code in the custom aggregator?

           

          And as a workaround can you try to convert to String first, and then byte[] as 2nd?

          • 2. Re: custom aggregator strategy
            dekk11

            Thanks for your help, you pointed me in the right direction.  I fixed it by setting the byte[] into the out message body. 

            For example:

            FileAggregationStrategy implements AggregationStrategy {

            public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {

            if (oldExchange == null) {

            byte[] newBytes = newExchange.getIn().getBody(byte[] newBytes = newExchange.getIn().getBody(byte[].class);

            newExchange.getOut().setBody(newBytes);

            return newExchange;

            }

            ...

            }

            }

             

            Why do I have to call getOut().setBody()?  I thought that this was call was done by camel when it receives the newExchange back from aggregate()?

             

            Edited by: dekk11 on Aug 18, 2010 3:02 PM

             

            Edited by: dekk11 on Aug 18, 2010 3:03 PM