title: How does one Set the "Pick" Expression for Apache Camel's FlexibleAggregationStrategy in Spring XML?
body: <p>I am attempting to configure an Apache Camel route in Spring XML using Apache Camel 2.14. The route will involve either an <code>&lt;aggregator&gt;</code> or an <code>&lt;enrich&gt;</code>/<code>&lt;pollEnrich&gt;</code>; I'm not yet experienced enough with Camel to know which EIP will be most useful. Either way, I'm going to need an <code>aggregationStrategy</code>. My end goal involves creating a Camel route for a client who wants the routes configured in XML.</p>
  
  <p>By searching around the Internet, I learned of the existence of a Camel class called <code>FlexibleAggregationStrategy</code>. The things I found claim, and I quote, "It allows you to quickly 
  whip up an AggregationStrategy that is capable of performing the most typical aggregation duties, with zero Java code." This sounds useful to me, since we want as much of the configuration in XML as possible. As such, it would be nice to avoid writing my own <code>AggregationStrategy</code> in Java. The problem is, I can't figure out how to use a <code>FlexibleAggregationStrategy</code>.</p>
  
  <p>From what I can tell, the <code>FlexibleAggregationStrategy</code> picks elements from messages to aggregate using an <code>Expression</code> called <code>pickExpression</code>, and filters out messages that match the <code>Predicate</code> <code>conditionPredicate</code>. So, I assume I need to have a way to set these values in my Spring XML. Unfortunately, I haven't been able to get the following blocks of code work:</p>
  
  <p>Property name set to <code>pickExpression</code>, value as element:</p>
  
  <pre><code>&lt;bean id="FlexibleAggregationStrategy"
      class="org.apache.camel.util.toolbox.FlexibleAggregationStrategy"&gt;
      &lt;property name="pickExpression"&gt;
          &lt;xpath&gt;
              //ID
          &lt;/xpath&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Property name set to <code>pick</code>, value as element:</p>
  
  <pre><code>&lt;bean id="FlexibleAggregationStrategy"
      class="org.apache.camel.util.toolbox.FlexibleAggregationStrategy"&gt;
      &lt;property name="pick"&gt;
          &lt;xpath&gt;
              //ID
          &lt;/xpath&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Property name set to <code>pickExpression</code>, value as attribute:</p>
  
  <pre><code>&lt;bean id="FlexibleAggregationStrategy"
      class="org.apache.camel.util.toolbox.FlexibleAggregationStrategy"&gt;
      &lt;property name="pickExpression" value="&amp;lt;xpath&amp;gt;//ID&amp;lt;/xpath&amp;gt;"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Property name set to <code>pick</code>, value as attribute:</p>
  
  <pre><code>&lt;bean id="FlexibleAggregationStrategy"
      class="org.apache.camel.util.toolbox.FlexibleAggregationStrategy"&gt;
      &lt;property name="pick" value="&amp;lt;xpath&amp;gt;//ID&amp;lt;/xpath&amp;gt;"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Each time, I get an error complaining that it's unable to find the property descriptor with the name I give it. The reason I try both <code>pick</code> and <code>pickExpression</code> is that, in <a href="https://github.com/apache/camel/blob/master/camel-core/src/main/java/org/apache/camel/util/toolbox/FlexibleAggregationStrategy.java" rel="nofollow">what appears to be the source code for FlexibleAggregationStrategy</a>, the variable holding the pick expression in the class is named <code>pickExpression</code>, but the method to set it is simply called <code>pick()</code>.</p>
  
  <p>I don't have a perfect understanding of Spring XML, but based on what I know, using the <code>&lt;property&gt;</code> tag to set a variable value requires the bean to have getters and setters for that variable. Since <code>FlexibleAggregationStrategy</code> does not have getters and setters for <code>pickExpression</code>, I'm following the wrong approach anyway. However, if I'm reading <a href="http://www.springframework.org/schema/beans/spring-beans.xsd" rel="nofollow">the XML Schema Definition for the <code>&lt;bean&gt;</code> tag</a> correctly, the only way to send information to a bean is with the <code>&lt;property&gt;</code> tag or with constructor parameters. Since <code>FlexibleAggregationStrategy</code> has no constructors that set <code>pickExpression</code>, I haven't found a way to configure a <code>FlexibleAggregationStrategy</code> without writing Java code.</p>
  
  <p>I've found references to something called "method injection" that might allow me to configure a <code>FlexibleAggregationStrategy</code>. However, the only instructions I've found involve writing a bean in Java. As such, this technique also involves writing Java code; in addition, it seems like it would be faster and more direct to just write my own <code>AggregationStrategy</code>.</p>
  
  <p>As of now, neither the old nor new Apache Camel Wiki pages documenting the <code>&lt;aggregator&gt;</code> pattern does not mention <code>FlexibleAggregationStrategy</code> at all. </p>
  
  <p>I have attempted a Google search for the term <code>FlexibleAggregationStrategy</code> to see if anybody has written any tutorials or documentation for using a <code>FlexibleAggregationStrategy</code>. As of now, the first two Google results I get are automatically-generated Javadoc for the <code>FlexibleAggregationStrategy</code> class. The third result is the github-hosted sourcecode I linked above. The fourth result is another question on this topic that I posted; this question was closed because I didn't understand how to write proper StackOverflow questions. The fifth result is the source code hosted on grepcode.com. The sixth result is the Javadoc for an interface I don't understand. The seventh result is a question somebody else asked on grokbase.com; the question has no answers. The eigth result is a question somebody else asked on qnalist.com that also has no answers. The ninth result seems to be from a mailing list involving committing the source code for the <code>FlexibleAggregationStrategy</code> class. The tenth result is the question from grokbase posted to osdir.com. Similar searches return mostly the same results; the other new results I find are equally unhelpful. I think that, if somebody had written a good guide for using <code>FlexibleAggregationStrategy</code>, it would come up in those searches.</p>
  
  <p>Is there anybody who has used a <code>FlexibleAggregationStrategy</code> who can tell me how to set the <code>pickExpression</code> and <code>conditionPredicate</code> so I can use a <code>FlexibleAggregationStrategy</code>? If you know of anything else I would need to configure it, or any other common pitfalls surrounding it, that information would also be appreciated.</p>
  
  <p>Thank you for your time.</p>