camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r809819 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/model/ main/java/org/apache/camel/processor/ test/java/org/apache/camel/processor/
Date Tue, 01 Sep 2009 05:17:08 GMT
Author: davsclaus
Date: Tue Sep  1 05:17:08 2009
New Revision: 809819

URL: http://svn.apache.org/viewvc?rev=809819&view=rev
Log:
Fixed potential NPE with enricher where the source did not return an exchange.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListBeanTest.java
      - copied, changed from r809810, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExpressionSubElementDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Enricher.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/PollEnricher.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExpressionSubElementDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExpressionSubElementDefinition.java?rev=809819&r1=809818&r2=809819&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExpressionSubElementDefinition.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExpressionSubElementDefinition.java
Tue Sep  1 05:17:08 2009
@@ -90,4 +90,17 @@
         }
         return getPredicate();
     }
+
+    @Override
+    public String toString() {
+        if (expression != null) {
+            return expression.toString();
+        } else if (expressionType != null) {
+            return expressionType.toString();
+        } else if (predicate != null) {
+            return predicate.toString();
+        }
+        return super.toString();
+    }
 }
+

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Enricher.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Enricher.java?rev=809819&r1=809818&r2=809819&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Enricher.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Enricher.java Tue Sep
 1 05:17:08 2009
@@ -115,8 +115,10 @@
                 // prepare the exchanges for aggregation
                 ExchangeHelper.prepareAggregation(exchange, resourceExchange);
                 Exchange aggregatedExchange = aggregationStrategy.aggregate(exchange, resourceExchange);
-                // copy aggregation result onto original exchange (preserving pattern)
-                copyResultsPreservePattern(exchange, aggregatedExchange);
+                if (aggregatedExchange != null) {
+                    // copy aggregation result onto original exchange (preserving pattern)
+                    copyResultsPreservePattern(exchange, aggregatedExchange);
+                }
             } else {
                 if (LOG.isTraceEnabled()) {
                     LOG.trace("Cannot aggregate exchange as its filtered: " + resourceExchange);
@@ -166,7 +168,9 @@
     private static class CopyAggregationStrategy implements AggregationStrategy {
 
         public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
-            copyResultsPreservePattern(oldExchange, newExchange);
+            if (newExchange != null) {
+                copyResultsPreservePattern(oldExchange, newExchange);
+            }
             return oldExchange;
         }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/PollEnricher.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/PollEnricher.java?rev=809819&r1=809818&r2=809819&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/PollEnricher.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/PollEnricher.java Tue
Sep  1 05:17:08 2009
@@ -182,7 +182,7 @@
             boolean fileBasedConsumer = edpc.getEndpoint().getEndpointKey().startsWith("file")
|| edpc.getEndpoint().getEndpointKey().startsWith("ftp");
             boolean fileBasedExchange = exchange.getFromEndpoint().getEndpointUri().startsWith("file")
|| exchange.getFromEndpoint().getEndpointUri().startsWith("ftp");
             if (fileBasedConsumer && fileBasedExchange) {
-                throw new IllegalArgumentException("Camel durrently does not support pollEnrich
from a file/ftp endpoint"
+                throw new IllegalArgumentException("Camel currently does not support pollEnrich
from a file/ftp endpoint"
                         + " when the route also started from a file/ftp endpoint."
                         + " Started from: " + exchange.getFromEndpoint().getEndpointUri()
+ " pollEnrich: " + edpc.getEndpoint().getEndpointUri());
             }
@@ -230,7 +230,9 @@
     private static class CopyAggregationStrategy implements AggregationStrategy {
 
         public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
-            copyResultsPreservePattern(oldExchange, newExchange);
+            if (newExchange != null) {
+                copyResultsPreservePattern(oldExchange, newExchange);
+            }
             return oldExchange;
         }
 

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListBeanTest.java
(from r809810, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListBeanTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListBeanTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListTest.java&r1=809810&r2=809819&rev=809819&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListBeanTest.java
Tue Sep  1 05:17:08 2009
@@ -19,41 +19,46 @@
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
 
 /**
  * @version $Revision$
  */
-public class RecipientListTest extends ContextTestSupport {
+public class RecipientListBeanTest extends ContextTestSupport {
 
-    public void testSendingAMessageUsingMulticastReceivesItsOwnExchange() throws Exception
{
-        MockEndpoint x = getMockEndpoint("mock:x");
-        MockEndpoint y = getMockEndpoint("mock:y");
-        MockEndpoint z = getMockEndpoint("mock:z");
-
-        x.expectedBodiesReceived("answer");
-        y.expectedBodiesReceived("answer");
-        z.expectedBodiesReceived("answer");
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("myBean", new MyBean());
+        return jndi;
+    }
 
-        sendBody();
+    public void testRecipientListWithBean() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello c");
 
-        assertMockEndpointsSatisfied();
-    }
+        String out = template.requestBody("direct:start", "direct:a,direct:b,direct:c", String.class);
+        assertEquals("Hello c", out);
 
-    protected void sendBody() {
-        template.sendBodyAndHeader("direct:a", "answer", "recipientListHeader",
-                "mock:x,mock:y,mock:z");
+        assertMockEndpointsSatisfied();
     }
-
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                // START SNIPPET: example
-                from("direct:a").recipientList(
-                        header("recipientListHeader").tokenize(","));
-                // END SNIPPET: example
+                from("direct:start").recipientList(bean("myBean", "foo")).to("mock:result");
+
+                from("direct:a").transform(constant("Hello a"));
+                from("direct:b").transform(constant("Hello b"));
+                from("direct:c").transform(constant("Hello c"));
             }
         };
+    }
+
+    public class MyBean {
 
+        public String[] foo(String body) {
+            return body.split(",");
+        }
     }
 
-}
+}
\ No newline at end of file



Mime
View raw message