CAMEL-9896: When using continued with onException then dead letter channel 
endpooint should not be invoked.


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

Branch: refs/heads/camel-2.16.x
Commit: bba477b1a47be05cca08bab2ac9fdb44b5e288ec
Parents: a6b710e
Author: Claus Ibsen <davscl...@apache.org>
Authored: Sat Apr 23 10:08:07 2016 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Sat Apr 23 11:04:24 2016 +0200

----------------------------------------------------------------------
 .../camel/processor/RedeliveryErrorHandler.java |   9 +-
 .../issues/OnExceptionContinuedIssueTest.java   | 107 +++++++++++++++++++
 ...xceptionContinuedNoFailureProcessorTest.java |   2 +-
 3 files changed, 115 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bba477b1/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
 
b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
index 9697dc6..50d90cb 100644
--- 
a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
@@ -876,8 +876,13 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport impleme
             decrementRedeliveryCounter(exchange);
         }
 
-        // is the a failure processor to process the Exchange
-        if (processor != null) {
+        // we should allow using the failure processor if we should not 
continue
+        // or in case of continue then the failure processor is NOT a dead 
letter channel
+        // because you can continue and still let the failure processor do 
some routing
+        // before continue in the main route.
+        boolean allowFailureProcessor = !shouldContinue || 
!isDeadLetterChannel;
+
+        if (allowFailureProcessor && processor != null) {
 
             // prepare original IN body if it should be moved instead of 
current body
             if (data.useOriginalInMessage) {

http://git-wip-us.apache.org/repos/asf/camel/blob/bba477b1/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java
 
b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java
new file mode 100644
index 0000000..5deca4f
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java
@@ -0,0 +1,107 @@
+/**
+ * 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.DeadLetterChannelBuilder;
+import org.apache.camel.builder.DefaultErrorHandlerBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class OnExceptionContinuedIssueTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testOnExceptionWrappedMatch() throws Exception {
+        final DefaultErrorHandlerBuilder defaultErrorHandlerBuilder = new 
DeadLetterChannelBuilder("direct:dead");
+        defaultErrorHandlerBuilder.redeliveryDelay(0); // run fast
+        defaultErrorHandlerBuilder.maximumRedeliveries(2);
+
+        context.setErrorHandlerBuilder(defaultErrorHandlerBuilder);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.setTracing(false);
+
+                onException(OrderFailedException.class)
+                        .maximumRedeliveries(0)
+                        .continued(true);
+
+                from("direct:dead").to("log:dead", "mock:dead");
+
+                from("direct:order")
+                        .to("mock:one")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws 
Exception {
+                                log.info("First Processor Invoked");
+                                throw new OrderFailedException("First 
Processor Failure");
+                            }
+                        })
+                        .to("mock:two")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws 
Exception {
+                                log.info("Second Processor Invoked");
+                            }
+                        })
+                        .to("mock:three")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws 
Exception {
+                                log.info("Third Processor Invoked");
+                                throw new RuntimeException("Some Runtime 
Exception");
+                            }
+                        })
+                        .to("mock:four")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws 
Exception {
+                                log.info("Fourth Processor Invoked");
+                            }
+                        });
+            }
+        });
+        context.start();
+
+        // we should only get 1 to the DLC when we hit the 3rd route that
+        // throws the runtime exception
+        getMockEndpoint("mock:dead").expectedMessageCount(1);
+        getMockEndpoint("mock:one").expectedMessageCount(1);
+        getMockEndpoint("mock:two").expectedMessageCount(1);
+        getMockEndpoint("mock:three").expectedMessageCount(1);
+        getMockEndpoint("mock:four").expectedMessageCount(0);
+
+        template.requestBody("direct:order", "Camel in Action");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public class OrderFailedException extends Exception {
+
+        public OrderFailedException(String s) {
+            super(s);
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/bba477b1/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
 
b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
index cad431e..8550425 100644
--- 
a/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
@@ -28,7 +28,7 @@ public class OnExceptionContinuedNoFailureProcessorTest 
extends ContextTestSuppo
 
     public void testOnException() throws Exception {
         getMockEndpoint("mock:end").expectedMessageCount(1);
-        getMockEndpoint("mock:error").expectedMessageCount(1);
+        getMockEndpoint("mock:error").expectedMessageCount(0);
 
         template.sendBody("direct:start", "Hello World");
 

Reply via email to