Author: davsclaus
Date: Mon Nov 30 09:33:18 2009
New Revision: 885364

URL: http://svn.apache.org/viewvc?rev=885364&view=rev
Log:
Fixed potential NPE in AggregationStrategy and updated its javadoc. Disabled 
AMQP testing as testing it is a bit unstable.

Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationStrategy.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/GroupedExchangeAggregationStrategy.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseLatestAggregationStrategy.java
    
camel/trunk/components/camel-amqp/src/test/java/org/apache/camel/component/amqp/AMQPRouteTest.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationStrategy.java?rev=885364&r1=885363&r2=885364&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationStrategy.java
 Mon Nov 30 09:33:18 2009
@@ -28,9 +28,12 @@
  * or remove some headers. And a more common use case is for instance to count 
some values from the body payload. That
  * could be to sum up a total amount etc.
  * <p/>
- * Possible implementations include performing some kind of combining or delta
- * processing, such as adding line items together into an invoice or just using
- * the newest exchange and removing old exchanges such as for state tracking or
+ * It is possible that <tt>newExchange</tt> is <tt>null</tt> which could 
happen if there was no data possible
+ * to acquire. Such as when using a {...@link 
org.apache.camel.processor.PollEnricher} to poll from a JMS queue which
+ * is empty and a timeout was set.
+ * <p/>
+ * Possible implementations include performing some kind of combining or delta 
processing, such as adding line items
+ * together into an invoice or just using the newest exchange and removing old 
exchanges such as for state tracking or
  * market data prices; where old values are of little use.
  * 
  * @version $Revision$
@@ -41,7 +44,7 @@
      * Aggregates an old and new exchange together to create a single combined 
exchange
      *
      * @param oldExchange the oldest exchange (is <tt>null</tt> on first 
aggregation as we only have the new exchange)
-     * @param newExchange the newest exchange
+     * @param newExchange the newest exchange (can be <tt>null</tt> if there 
was no data possible to acquire)
      * @return a combined composite of the two exchanges
      */
     Exchange aggregate(Exchange oldExchange, Exchange newExchange);

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/GroupedExchangeAggregationStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/GroupedExchangeAggregationStrategy.java?rev=885364&r1=885363&r2=885364&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/GroupedExchangeAggregationStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/GroupedExchangeAggregationStrategy.java
 Mon Nov 30 09:33:18 2009
@@ -44,7 +44,9 @@
             list = oldExchange.getProperty(Exchange.GROUPED_EXCHANGE, 
List.class);
         }
 
-        list.add(newExchange);
+        if (newExchange != null) {
+            list.add(newExchange);
+        }
         return answer;
     }
 

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseLatestAggregationStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseLatestAggregationStrategy.java?rev=885364&r1=885363&r2=885364&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseLatestAggregationStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseLatestAggregationStrategy.java
 Mon Nov 30 09:33:18 2009
@@ -28,6 +28,9 @@
 public class UseLatestAggregationStrategy implements AggregationStrategy {
 
     public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+        if (newExchange == null) {
+            return oldExchange;
+        }
         newExchange.setException(checkException(oldExchange, newExchange));
         return newExchange;
     }
@@ -44,6 +47,6 @@
 
     @Override
     public String toString() {
-        return "useLatestAggregationStrategy";
+        return "UseLatestAggregationStrategy";
     }
 }

Modified: 
camel/trunk/components/camel-amqp/src/test/java/org/apache/camel/component/amqp/AMQPRouteTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-amqp/src/test/java/org/apache/camel/component/amqp/AMQPRouteTest.java?rev=885364&r1=885363&r2=885364&view=diff
==============================================================================
--- 
camel/trunk/components/camel-amqp/src/test/java/org/apache/camel/component/amqp/AMQPRouteTest.java
 (original)
+++ 
camel/trunk/components/camel-amqp/src/test/java/org/apache/camel/component/amqp/AMQPRouteTest.java
 Mon Nov 30 09:33:18 2009
@@ -25,6 +25,7 @@
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.apache.camel.component.amqp.AMQPComponent.amqpComponent;
@@ -53,6 +54,7 @@
     
 
     @Test
+    @Ignore("AMQP testing is a bit unstable")
     public void testJmsRouteWithTextMessage() throws Exception {
         String expectedBody = "Hello there!";
 
@@ -78,6 +80,7 @@
     }
 
     @Test
+    @Ignore("AMQP testing is a bit unstable")
     public void testJmsRouteWithObjectMessage() throws Exception {
         PurchaseOrder expectedBody = new PurchaseOrder("Beer", 10);
 
@@ -90,6 +93,7 @@
     }
 
     @Test
+    @Ignore("AMQP testing is a bit unstable")
     public void testJmsRouteWithByteArrayMessage() throws Exception {
         PurchaseOrder aPO = new PurchaseOrder("Beer", 10);
         byte[] expectedBody = SerializationUtils.serialize(aPO);


Reply via email to