Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-3677

When splitting inside another split, the custom aggregationStrategy is not used.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.5.0
    • 2.6.0
    • camel-core
    • None
    • Mac OS X 10.6.6, Eclipse Helios

    Description

      When splitting inside another split, the custom aggregationStrategy is not used. For example in the route:

      	    <route id="DoubleSplitRoute">
      	    	<from uri="direct:in" />
      	    	<setBody>
      	    		<constant>
      &lt;a&gt;
      	&lt;b&gt;
      		&lt;c&gt;Hello&lt;/c&gt;
      		&lt;c&gt;World&lt;/c&gt;
      	&lt;/b&gt;
      	&lt;b&gt;
      		&lt;c&gt;Hello&lt;/c&gt;
      		&lt;c&gt;again&lt;/c&gt;
      	&lt;/b&gt;
      &lt;/a&gt;
      	    		</constant>
      	    	</setBody>
      			<split>
      				<xpath>a/b</xpath>
      				<split strategyRef="concatWithSpaceStrategy">
      					<xpath>b/c/text()</xpath>
      					<setBody><simple>${bodyAs(java.lang.String)}</simple></setBody>
      					<log message="Got a part: ${body}"/>
      				</split>
      				<log message="Got a result: ${body}"/>
      			</split>
      		</route>
      

      (where the concatWithSpaceStrategy does nothing more than to concat the bodies with a space inbetween.)

      The expected results would be:

      Got a result: Hello World
      

      and

      Got a result: Hello again
      

      But that is not what happens. The actual results are two times the same:

      Got a result: 
      <a>
      	<b>
      		<c>Hello</c>
      		<c>World</c>
      	</b>
      	<b>
      		<c>Hello</c>
      		<c>again</c>
      	</b>
      </a>
      

      The reason is, that the strategy is not used. In the class org.apache.camel.processor.MulticastProcessor, in the method protected AggregationStrategy getAggregationStrategy(Exchange exchange), the first step is to find an aggregationStrategy in the Exchange. This is set to UseOriginalAggregationStrategy, and because it is not null, this aggregation strategy will be used, not the one declared for the splitter.

      A workaround would be to remove the AggregationStrategy of the Exchange, before it is aggregated, by using a processor with the following process method:

      	public void process(Exchange exchange) throws Exception {
      		if (exchange != null) {
      			exchange.removeProperty(Exchange.AGGREGATION_STRATEGY);
      		}
      	}
      

      After integrating this in my route, I got the desired results.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ojelinski Oliver Jelinski
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: