camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1175139 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/processor/MulticastProcessor.java main/java/org/apache/camel/processor/Splitter.java test/java/org/apache/camel/processor/SplitterThrowExceptionFromExpressionTest.java
Date Sat, 24 Sep 2011 09:44:16 GMT
Author: davsclaus
Date: Sat Sep 24 09:44:16 2011
New Revision: 1175139

URL: http://svn.apache.org/viewvc?rev=1175139&view=rev
Log:
CAMEL-4482: Fixed issue when exception thrown from using custom expression with Splitter EIP,
not being triggered by onException.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterThrowExceptionFromExpressionTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java?rev=1175139&r1=1175138&r2=1175139&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
Sat Sep 24 09:44:16 2011
@@ -797,6 +797,12 @@ public class MulticastProcessor extends 
             result.add(createProcessorExchangePair(index++, processor, copy, routeContext));
         }
 
+        if (exchange.getException() != null) {
+            // force any exceptions occurred during creation of exchange paris to be thrown
+            // before returning the answer;
+            throw exchange.getException();
+        }
+
         return result;
     }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java?rev=1175139&r1=1175138&r2=1175139&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java Sat Sep
24 09:44:16 2011
@@ -98,14 +98,26 @@ public class Splitter extends MulticastP
     }
 
     @Override
-    protected Iterable<ProcessorExchangePair> createProcessorExchangePairs(Exchange
exchange) {
+    protected Iterable<ProcessorExchangePair> createProcessorExchangePairs(Exchange
exchange) throws Exception {
         Object value = expression.evaluate(exchange, Object.class);
+        if (exchange.getException() != null) {
+            // force any exceptions occurred during evaluation to be thrown
+            throw exchange.getException();
+        }
 
+        Iterable<ProcessorExchangePair> answer;
         if (isStreaming()) {
-            return createProcessorExchangePairsIterable(exchange, value);
+            answer = createProcessorExchangePairsIterable(exchange, value);
         } else {
-            return createProcessorExchangePairsList(exchange, value);
+            answer = createProcessorExchangePairsList(exchange, value);
+        }
+        if (exchange.getException() != null) {
+            // force any exceptions occurred during creation of exchange paris to be thrown
+            // before returning the answer;
+            throw exchange.getException();
         }
+
+        return answer;
     }
 
     @SuppressWarnings("unchecked")

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterThrowExceptionFromExpressionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterThrowExceptionFromExpressionTest.java?rev=1175139&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterThrowExceptionFromExpressionTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterThrowExceptionFromExpressionTest.java
Sat Sep 24 09:44:16 2011
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor;
+
+import java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExpressionEvaluationException;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class SplitterThrowExceptionFromExpressionTest extends ContextTestSupport {
+
+    public void testSplitterAndVerifyException() throws Exception {
+        getMockEndpoint("mock:error").expectedMessageCount(1);
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                onException(ExpressionEvaluationException.class)
+                    .handled(true)
+                    .to("mock://error");
+
+                from("direct://start")
+                    .split().method(SplitterThrowExceptionFromExpressionTest.class, "splitMe")
+                        .to("mock://result")
+                    .end();
+            }
+        };
+    }
+
+    public List<String> splitMe(Exchange exchange) throws ExpressionEvaluationException
{
+        throw new ExpressionEvaluationException(null, exchange, null);
+    }
+
+}



Mime
View raw message