Updated Branches:
  refs/heads/camel-2.12.x b5a54186c -> c26cc9860

CAMEL-6802: Using stopOnException in splitter should not copy result back as we 
should preserve original exchange


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c26cc986
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c26cc986
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c26cc986

Branch: refs/heads/camel-2.12.x
Commit: c26cc9860083a6fddd6af3ec5ce40005cd4df824
Parents: b5a5418
Author: Claus Ibsen <davscl...@apache.org>
Authored: Mon Sep 30 12:57:39 2013 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Mon Sep 30 13:09:06 2013 +0200

----------------------------------------------------------------------
 .../camel/processor/MulticastProcessor.java     | 14 +++-
 .../issues/SplitStopOnExceptionIssueTest.java   | 75 ++++++++++++++++++++
 2 files changed, 87 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c26cc986/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java 
b/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
index 550a23e..a3bca76 100644
--- 
a/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
@@ -750,15 +750,25 @@ public class MulticastProcessor extends ServiceSupport 
implements AsyncProcessor
 
         // cleanup any per exchange aggregation strategy
         removeAggregationStrategyFromExchange(original);
+
+        boolean stoppedOnException = false;
         if (original.getException() != null || subExchange != null && 
subExchange.getException() != null) {
+            // there was an exception and we stopped
+            stoppedOnException = isStopOnException();
             // multicast uses error handling on its output processors and they 
have tried to redeliver
             // so we shall signal back to the other error handlers that we are 
exhausted and they should not
             // also try to redeliver as we will then do that twice
             original.setProperty(Exchange.REDELIVERY_EXHAUSTED, exhaust);
         }
+
         if (subExchange != null) {
-            // and copy the current result to original so it will contain this 
result of this eip
-            ExchangeHelper.copyResults(original, subExchange);
+            if (stoppedOnException) {
+                // if we stopped due an exception then only propagte the 
exception
+                original.setException(subExchange.getException());
+            } else {
+                // copy the current result to original so it will contain this 
result of this eip
+                ExchangeHelper.copyResults(original, subExchange);
+            }
         }
         callback.done(doneSync);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/c26cc986/camel-core/src/test/java/org/apache/camel/issues/SplitStopOnExceptionIssueTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/issues/SplitStopOnExceptionIssueTest.java
 
b/camel-core/src/test/java/org/apache/camel/issues/SplitStopOnExceptionIssueTest.java
new file mode 100644
index 0000000..c968835
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/issues/SplitStopOnExceptionIssueTest.java
@@ -0,0 +1,75 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version 
+ */
+public class SplitStopOnExceptionIssueTest extends ContextTestSupport {
+
+    public void testSplit() throws Exception {
+        getMockEndpoint("mock:line").expectedBodiesReceived("Hello", "World", 
"Kaboom");
+        
getMockEndpoint("mock:line").allMessages().property("foo").isEqualTo("changed");
+
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+
+        Exchange out = template.request("direct:start", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("Hello,World,Kaboom");
+            }
+        });
+        assertNotNull(out);
+        assertTrue(out.isFailed());
+        assertFalse(out.hasOut());
+
+        // when we use stopOnException the exchange should not be affected 
during the splitter
+        // eg the foo property should have the before value
+        assertEquals("before", out.getProperty("foo"));
+        assertEquals("Hello,World,Kaboom", out.getIn().getBody());
+
+        IllegalArgumentException iae = 
out.getException(IllegalArgumentException.class);
+        assertNotNull(iae);
+        assertEquals("Forced exception", iae.getMessage());
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .setProperty("foo", constant("before"))
+                    .split().tokenize(",")
+                        .setProperty("foo", constant("changed"))
+                        .to("mock:line")
+                        .filter(body().contains("Kaboom"))
+                            .throwException(new 
IllegalArgumentException("Forced exception"))
+                        .end()
+                    .end()
+                    .to("mock:result");
+            }
+        };
+    }
+}

Reply via email to