You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/09/30 13:08:55 UTC
[2/2] git commit: CAMEL-6802: Using stopOnException in splitter
should not copy result back as we should preserve original exchange
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/3040c83a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3040c83a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3040c83a
Branch: refs/heads/camel-2.11.x
Commit: 3040c83aee0b4fa9b06e8695d8f18ed8eb5cd7d4
Parents: 9bff1cc
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Sep 30 12:57:39 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Sep 30 13:08:37 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/3040c83a/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 3872d34..cdce14c 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/3040c83a/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");
+ }
+ };
+ }
+}