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 2017/11/01 12:44:34 UTC

[camel] branch camel-2.19.x updated: CAMEL-11045: Fixed OnCompletion would not be triggered from a route using Splitter and an exception was thrown during splitting.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-2.19.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.19.x by this push:
     new ba06a14  CAMEL-11045: Fixed OnCompletion would not be triggered from a route using Splitter and an exception was thrown during splitting.
ba06a14 is described below

commit ba06a14c8e55bbf06b8d003880d2afdb74665e01
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Nov 1 13:32:56 2017 +0100

    CAMEL-11045: Fixed OnCompletion would not be triggered from a route using Splitter and an exception was thrown during splitting.
---
 .../camel/processor/OnCompletionProcessor.java     |  5 ++
 .../camel/processor/SplitterOnCompletionTest.java  | 78 ++++++++++++++++++++++
 2 files changed, 83 insertions(+)

diff --git a/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
index f0835b9..4579235 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
@@ -143,6 +143,8 @@ public class OnCompletionProcessor extends ServiceSupport implements AsyncProces
         Object errorhandlerHandled = exchange.removeProperty(Exchange.ERRORHANDLER_HANDLED);
         Object rollbackOnly = exchange.removeProperty(Exchange.ROLLBACK_ONLY);
         Object rollbackOnlyLast = exchange.removeProperty(Exchange.ROLLBACK_ONLY_LAST);
+        // and we should not be regarded as exhausted as we are in a onCompletion block
+        Object exhausted = exchange.removeProperty(Exchange.REDELIVERY_EXHAUSTED);
 
         Exception cause = exchange.getException();
         exchange.setException(null);
@@ -168,6 +170,9 @@ public class OnCompletionProcessor extends ServiceSupport implements AsyncProces
             if (rollbackOnlyLast != null) {
                 exchange.setProperty(Exchange.ROLLBACK_ONLY_LAST, rollbackOnlyLast);
             }
+            if (exhausted != null) {
+                exchange.setProperty(Exchange.REDELIVERY_EXHAUSTED, exhausted);
+            }
             if (cause != null) {
                 exchange.setException(cause);
             }
diff --git a/camel-core/src/test/java/org/apache/camel/processor/SplitterOnCompletionTest.java b/camel-core/src/test/java/org/apache/camel/processor/SplitterOnCompletionTest.java
new file mode 100644
index 0000000..80e809f
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/SplitterOnCompletionTest.java
@@ -0,0 +1,78 @@
+/**
+ * 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 org.apache.camel.CamelExecutionException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version
+ */
+public class SplitterOnCompletionTest extends ContextTestSupport {
+
+    public void testSplitOk() throws Exception {
+        getMockEndpoint("mock:done").expectedBodiesReceived("Hello World,Bye World");
+        getMockEndpoint("mock:split").expectedBodiesReceived("Hello World", "Bye World");
+
+        template.sendBody("direct:start", "Hello World,Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testSplitException() throws Exception {
+        getMockEndpoint("mock:done").expectedBodiesReceived("Hello World,Kaboom,Bye World");
+        getMockEndpoint("mock:split").expectedBodiesReceived("Hello World", "Bye World");
+
+        try {
+            template.sendBody("direct:start", "Hello World,Kaboom,Bye World");
+            fail("Should thrown an exception");
+        } catch (CamelExecutionException e) {
+            IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+            assertEquals("Forced", iae.getMessage());
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                onCompletion().to("log:done", "mock:done");
+
+                from("direct:start")
+                    .split(body().tokenize(","))
+                        .process(new MyProcessor())
+                        .to("mock:split");
+            }
+        };
+    }
+
+    public static class MyProcessor implements Processor {
+
+        public void process(Exchange exchange) throws Exception {
+            String body = exchange.getIn().getBody(String.class);
+            if ("Kaboom".equals(body)) {
+                throw new IllegalArgumentException("Forced");
+            }
+        }
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].