camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] camel git commit: CAMEL-9555: Setting deadLetterHandleNewException to false breaks DeadLetterChannel default exception handling.
Date Sat, 06 Feb 2016 08:47:18 GMT
CAMEL-9555: Setting deadLetterHandleNewException to false breaks DeadLetterChannel default
exception handling.


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

Branch: refs/heads/camel-2.16.x
Commit: 6a5a4b4838680101de3a5b0a13e796e7e5d6d5a5
Parents: 8617e14
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Feb 6 09:41:39 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Feb 6 09:45:38 2016 +0100

----------------------------------------------------------------------
 .../camel/processor/RedeliveryErrorHandler.java |  7 +-
 ...DeadLetterChannelHandleNewExceptionTest.java | 73 ++++++++++++++++++++
 2 files changed, 77 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6a5a4b48/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 d99e5cf..ff94da7 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
@@ -1007,8 +1007,9 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport
impleme
             // special situations when using dead letter channel
             if (isDeadLetterChannel) {
 
-                // use the handled option from the DLC
-                boolean handled = data.handleNewException;
+                // DLC is always handling the first thrown exception,
+                // but if its a new exception then use the configured option
+                boolean handled = newException == null || data.handleNewException;
 
                 // when using DLC then log new exception whether its being handled or not,
as otherwise it may appear as
                 // the DLC swallow new exceptions by default (which is by design to ensure
the DLC always complete,
@@ -1021,7 +1022,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport
impleme
                     } else {
                         msg += ". The new exception is not handled as deadLetterHandleNewException=false.";
                     }
-                    logFailedDelivery(false, true, handled, false, isDeadLetterChannel, exchange,
msg, data, newException);
+                    logFailedDelivery(false, true, handled, false, true, exchange, msg, data,
newException);
                 }
 
                 if (handled) {

http://git-wip-us.apache.org/repos/asf/camel/blob/6a5a4b48/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelHandleNewExceptionTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelHandleNewExceptionTest.java
b/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelHandleNewExceptionTest.java
new file mode 100644
index 0000000..8770099
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelHandleNewExceptionTest.java
@@ -0,0 +1,73 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class DeadLetterChannelHandleNewExceptionTest extends ContextTestSupport {
+
+    // should not log any exceptions in the log as they are all handled
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testDeadLetterChannelHandleNewException() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                errorHandler(deadLetterChannel("mock:dead")
+                        .deadLetterHandleNewException(true));
+
+                from("direct:start")
+                        .log("Incoming ${body}")
+                        .throwException(new IllegalArgumentException("Forced"));
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:dead").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testDeadLetterChannelNotHandleNewException() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                errorHandler(deadLetterChannel("mock:dead")
+                        .deadLetterHandleNewException(false));
+
+                from("direct:start")
+                        .log("Incoming ${body}")
+                        .throwException(new IllegalArgumentException("Forced"));
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:dead").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}
\ No newline at end of file


Mime
View raw message