Author: davsclaus
Date: Sat Dec  6 02:48:07 2008
New Revision: 723967

URL: http://svn.apache.org/viewvc?rev=723967&view=rev
Log:
Merged revisions 723966 via svnmerge from 
https://svn.apache.org/repos/asf/activemq/camel/trunk

........
  r723966 | davsclaus | 2008-12-06 11:34:03 +0100 (lo, 06 dec 2008) | 1 line
  
  CAMEL-1150: Fixed aggregator not working with onException in a route
........

Added:
    
activemq/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorAndOnExceptionTest.java
      - copied, changed from r723966, 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorAndOnExceptionTest.java
Modified:
    activemq/camel/branches/camel-1.x/   (props changed)
    
activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
    
activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java

Propchange: activemq/camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Dec  6 02:48:07 2008
@@ -1 +1 @@
-/activemq/camel/trunk:709850,711200,711206,711219-711220,711523,711531,711756,711784,711859,711874,711962,711971,712064,712119,712148,712662,712692,712925,713013,713107,713136,713273,713290,713292,713295,713314,713475,713625,713932,713944,714032,717965,717989,718242,718273,718312-718515,719163-719184,719334,719339,719524,719662,719848,719851,719855,719864,719978-719979,720207,720435-720437,720806,721272,721331,721333-721334,721360,721669,721764,721813,721985,722005,722070,722110,722415,722438,722726,722845,722878,723264,723314,723325-723327,723409,723835
+/activemq/camel/trunk:709850,711200,711206,711219-711220,711523,711531,711756,711784,711859,711874,711962,711971,712064,712119,712148,712662,712692,712925,713013,713107,713136,713273,713290,713292,713295,713314,713475,713625,713932,713944,714032,717965,717989,718242,718273,718312-718515,719163-719184,719334,719339,719524,719662,719848,719851,719855,719864,719978-719979,720207,720435-720437,720806,721272,721331,721333-721334,721360,721669,721764,721813,721985,722005,722070,722110,722415,722438,722726,722845,722878,723264,723314,723325-723327,723409,723835,723966

Propchange: activemq/camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: 
activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java?rev=723967&r1=723966&r2=723967&view=diff
==============================================================================
--- 
activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
 (original)
+++ 
activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
 Sat Dec  6 02:48:07 2008
@@ -62,6 +62,7 @@
 import org.apache.camel.spi.InterceptStrategy;
 import org.apache.camel.spi.Policy;
 import org.apache.camel.spi.RouteContext;
+import org.apache.camel.util.CollectionHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -754,8 +755,8 @@
      * together into a single invoice message.
      */
     public ExpressionClause<AggregatorType> aggregator() {
-        if (!getOutputs().isEmpty()) {
-            throw new IllegalArgumentException("Aggregator must be the only 
output added to the route: " + this);
+        if (CollectionHelper.filterList(getOutputs(), 
ExceptionType.class).isEmpty()) {
+            LOG.warn("Aggregator must be the only output added to the route: " 
+ this);
         }
         AggregatorType answer = new AggregatorType();
         addOutput(answer);
@@ -780,8 +781,8 @@
      * @param aggregationStrategy the strategy used for the aggregation
      */
     public ExpressionClause<AggregatorType> aggregator(AggregationStrategy 
aggregationStrategy) {
-        if (!getOutputs().isEmpty()) {
-            throw new IllegalArgumentException("Aggregator must be the only 
output added to the route: " + this);
+        if (CollectionHelper.filterList(getOutputs(), 
ExceptionType.class).isEmpty()) {
+            LOG.warn("Aggregator must be the only output added to the route: " 
+ this);
         }
         AggregatorType answer = new AggregatorType();
         answer.setAggregationStrategy(aggregationStrategy);
@@ -799,8 +800,8 @@
      * @param aggregationCollection the collection used to perform the 
aggregation
      */
     public AggregatorType aggregator(AggregationCollection 
aggregationCollection) {
-        if (!getOutputs().isEmpty()) {
-            throw new IllegalArgumentException("Aggregator must be the only 
output added to the route: " + this);
+        if (CollectionHelper.filterList(getOutputs(), 
ExceptionType.class).isEmpty()) {
+            LOG.warn("Aggregator must be the only output added to the route: " 
+ this);
         }
         AggregatorType answer = new AggregatorType();
         answer.setAggregationCollection(aggregationCollection);
@@ -829,8 +830,8 @@
      *                              <code>header("JMSCorrelationID")</code>
      */
     public AggregatorType aggregator(Expression correlationExpression) {
-        if (!getOutputs().isEmpty()) {
-            throw new IllegalArgumentException("Aggregator must be the only 
output added to the route: " + this);
+        if (CollectionHelper.filterList(getOutputs(), 
ExceptionType.class).isEmpty()) {
+            LOG.warn("Aggregator must be the only output added to the route: " 
+ this);
         }
         AggregatorType answer = new AggregatorType(correlationExpression);
         addOutput(answer);
@@ -858,8 +859,8 @@
      *                              <code>header("JMSCorrelationID")</code>
      */
     public AggregatorType aggregator(Expression correlationExpression, 
AggregationStrategy aggregationStrategy) {
-        if (!getOutputs().isEmpty()) {
-            throw new IllegalArgumentException("Aggregator must be the only 
output added to the route: " + this);
+        if (CollectionHelper.filterList(getOutputs(), 
ExceptionType.class).isEmpty()) {
+            LOG.warn("Aggregator must be the only output added to the route: " 
+ this);
         }
         AggregatorType answer = new AggregatorType(correlationExpression, 
aggregationStrategy);
         addOutput(answer);

Modified: 
activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java?rev=723967&r1=723966&r2=723967&view=diff
==============================================================================
--- 
activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
 (original)
+++ 
activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
 Sat Dec  6 02:48:07 2008
@@ -39,6 +39,9 @@
 
     /**
      * Returns the size of the collection if it can be determined to be a 
collection
+     *
+     * @param value the collection
+     * @return the size, or <tt>null</tt> if not a collection
      */
     public static Integer size(Object value) {
         if (value != null) {
@@ -71,7 +74,6 @@
      * @param value the value to put in the map
      */
     public static void appendValue(Map map, Object key, Object value) {
-
         Object oldValue = map.get(key);
         if (oldValue != null) {
             List list;
@@ -86,4 +88,23 @@
             map.put(key, value);
         }
     }
+
+    /**
+     * Filters the given list to skip instanceof filter objects.
+     * 
+     * @param list  the list
+     * @param filters  objects to skip
+     * @return a new list without the filtered objects
+     */
+    public static List filterList(List list, Object... filters) {
+        List answer = new ArrayList();
+        for (Object o : list) {
+            for (Object filter : filters) {
+                if (!o.getClass().isInstance(filter)) {
+                    answer.add(o);
+                }
+            }
+        }
+        return answer;
+    }
 }

Copied: 
activemq/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorAndOnExceptionTest.java
 (from r723966, 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorAndOnExceptionTest.java)
URL: 
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorAndOnExceptionTest.java?p2=activemq/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorAndOnExceptionTest.java&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorAndOnExceptionTest.java&r1=723966&r2=723967&rev=723967&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorAndOnExceptionTest.java
 (original)
+++ 
activemq/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorAndOnExceptionTest.java
 Sat Dec  6 02:48:07 2008
@@ -49,15 +49,15 @@
                 onException(CamelException.class).maximumRedeliveries(2);
 
                 from("seda:start")
-                        .aggregate(new 
PredicateAggregationCollection(header("id"),
-                                        new AggregationStrategy() {
-                                            public Exchange aggregate(Exchange 
oldExchange, Exchange newExchange) {
-                                                return newExchange;
-                                            }
-                                        },
-                                        
header(Exchange.AGGREGATED_COUNT).isEqualTo(2)))
-                        .batchTimeout(500L)
-                        .to("mock:result");
+                    .aggregator(new 
PredicateAggregationCollection(header("id"),
+                        new AggregationStrategy() {
+                            public Exchange aggregate(Exchange oldExchange, 
Exchange newExchange) {
+                                return newExchange;
+                            }
+                        },
+                        header(Exchange.AGGREGATED_COUNT).isEqualTo(2)))
+                    .batchTimeout(500L)
+                    .to("mock:result");
             }
         };
     }


Reply via email to