CAMEL-8755: No Message History on deadLetterChannel

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

Branch: refs/heads/master
Commit: d3b56df6665b05a71f44b5e27745cc3697ff8213
Parents: 55fe6ef
Author: Claus Ibsen <davscl...@apache.org>
Authored: Sun May 10 12:41:03 2015 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Sun May 10 12:41:03 2015 +0200

----------------------------------------------------------------------
 .../camel/processor/RedeliveryErrorHandler.java | 33 ++++++++++------
 .../camel/processor/RedeliveryPolicy.java       | 13 ++++++-
 ...erChannelLogExhaustedMessageHistoryTest.java | 33 ++++++++++++++++
 ...orHandlerLogExhaustedMessageHistoryTest.java | 38 ++++++++++++++++++
 ...terChannelLogExhaustedMessageHistoryTest.xml | 41 ++++++++++++++++++++
 ...rorHandlerLogExhaustedMessageHistoryTest.xml | 41 ++++++++++++++++++++
 6 files changed, 187 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d3b56df6/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 e4cf1b5..dbb87da 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
@@ -362,7 +362,7 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport impleme
             // did previous processing cause an exception?
             boolean handle = shouldHandleException(exchange);
             if (handle) {
-                handleException(exchange, data);
+                handleException(exchange, data, isDeadLetterChannel());
             }
 
             // compute if we are exhausted, and whether redelivery is allowed
@@ -536,7 +536,7 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport impleme
         // did previous processing cause an exception?
         boolean handle = shouldHandleException(exchange);
         if (handle) {
-            handleException(exchange, data);
+            handleException(exchange, data, isDeadLetterChannel());
         }
 
         // compute if we are exhausted or not
@@ -695,7 +695,7 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport impleme
         return null;
     }
 
-    protected void prepareExchangeForContinue(Exchange exchange, 
RedeliveryData data) {
+    protected void prepareExchangeForContinue(Exchange exchange, 
RedeliveryData data, boolean isDeadLetterChannel) {
         Exception caught = exchange.getException();
 
         // we continue so clear any exceptions
@@ -718,7 +718,7 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport impleme
         msg = msg + ". Handled and continue routing.";
 
         // log that we failed but want to continue
-        logFailedDelivery(false, false, false, true, exchange, msg, data, 
null);
+        logFailedDelivery(false, false, false, isDeadLetterChannel, true, 
exchange, msg, data, null);
     }
 
     protected void prepareExchangeForRedelivery(Exchange exchange, 
RedeliveryData data) {
@@ -760,7 +760,7 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport impleme
         }
     }
 
-    protected void handleException(Exchange exchange, RedeliveryData data) {
+    protected void handleException(Exchange exchange, RedeliveryData data, 
boolean isDeadLetterChannel) {
         Exception e = exchange.getException();
 
         // store the original caused exception in a property, so we can 
restore it later
@@ -802,7 +802,7 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport impleme
         if (!ExchangeHelper.isFailureHandled(exchange) && 
!ExchangeHelper.isUnitOfWorkExhausted(exchange)) {
             String msg = "Failed delivery for " + 
ExchangeHelper.logIds(exchange)
                     + ". On delivery attempt: " + data.redeliveryCounter + " 
caught: " + e;
-            logFailedDelivery(true, false, false, false, exchange, msg, data, 
e);
+            logFailedDelivery(true, false, false, false, isDeadLetterChannel, 
exchange, msg, data, e);
         }
 
         data.redeliveryCounter = incrementRedeliveryCounter(exchange, e, data);
@@ -961,7 +961,7 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport impleme
         }
 
         // log that we failed delivery as we are exhausted
-        logFailedDelivery(false, false, handled, false, exchange, msg, data, 
null);
+        logFailedDelivery(false, false, handled, false, isDeadLetterChannel, 
exchange, msg, data, null);
 
         return sync;
     }
@@ -992,7 +992,7 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport impleme
         if (shouldContinue) {
             log.trace("This exchange is continued: {}", exchange);
             // okay we want to continue then prepare the exchange for that as 
well
-            prepareExchangeForContinue(exchange, data);
+            prepareExchangeForContinue(exchange, data, isDeadLetterChannel);
         } else if (shouldHandle) {
             log.trace("This exchange is handled so its marked as not failed: 
{}", exchange);
             exchange.setProperty(Exchange.ERRORHANDLER_HANDLED, Boolean.TRUE);
@@ -1015,7 +1015,7 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport impleme
                     } else {
                         msg += ". The new exception is not handled as 
deadLetterHandleNewException=false.";
                     }
-                    logFailedDelivery(false, true, handled, false, exchange, 
msg, data, newException);
+                    logFailedDelivery(false, true, handled, false, 
isDeadLetterChannel, exchange, msg, data, newException);
                 }
 
                 if (handled) {
@@ -1044,7 +1044,7 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport impleme
         }
     }
 
-    private void logFailedDelivery(boolean shouldRedeliver, boolean 
newException, boolean handled, boolean continued,
+    private void logFailedDelivery(boolean shouldRedeliver, boolean 
newException, boolean handled, boolean continued, boolean isDeadLetterChannel,
                                    Exchange exchange, String message, 
RedeliveryData data, Throwable e) {
         if (logger == null) {
             return;
@@ -1057,7 +1057,18 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport impleme
             }
 
             // if we should not rollback, then check whether logging is enabled
-            if (!newException && handled && 
(!data.currentRedeliveryPolicy.isLogHandled() && 
!data.currentRedeliveryPolicy.isLogExhaustedMessageHistory())) {
+
+            // depending on what kind of error handler we should
+            boolean logExhausted;
+            if (isDeadLetterChannel) {
+                // if DLC then log exhausted should not be default
+                logExhausted = 
data.currentRedeliveryPolicy.getLogExhaustedMessageHistory() != null && 
data.currentRedeliveryPolicy.isLogExhaustedMessageHistory();
+            } else {
+                // for any other error handler log exhausted should be default
+                logExhausted = 
data.currentRedeliveryPolicy.getLogExhaustedMessageHistory() == null || 
data.currentRedeliveryPolicy.isLogExhaustedMessageHistory();
+            }
+
+            if (!newException && handled && 
(!data.currentRedeliveryPolicy.isLogHandled() && !logExhausted)) {
                 // do not log handled (but log exhausted message history can 
overrule log handled)
                 return;
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/d3b56df6/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java 
b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
index b8bb24c..4b33a4b 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
@@ -97,7 +97,7 @@ public class RedeliveryPolicy implements Cloneable, 
Serializable {
     protected boolean logContinued;
     protected boolean logExhausted = true;
     protected boolean logNewException = true;
-    protected boolean logExhaustedMessageHistory = true;
+    protected Boolean logExhaustedMessageHistory;
     protected boolean logRetryAttempted = true;
     protected String delayPattern;
     protected boolean asyncDelayedRedelivery;
@@ -687,6 +687,17 @@ public class RedeliveryPolicy implements Cloneable, 
Serializable {
     }
 
     public boolean isLogExhaustedMessageHistory() {
+        // should default be enabled
+        return logExhaustedMessageHistory == null || 
logExhaustedMessageHistory;
+    }
+
+    /**
+     * Whether the option logExhaustedMessageHistory has been configured or not
+     *
+     * @return <tt>null</tt> if not configured, or the configured value as 
true or false
+     * @see #isLogExhaustedMessageHistory()
+     */
+    public Boolean getLogExhaustedMessageHistory() {
         return logExhaustedMessageHistory;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/d3b56df6/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DeadLetterChannelLogExhaustedMessageHistoryTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DeadLetterChannelLogExhaustedMessageHistoryTest.java
 
b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DeadLetterChannelLogExhaustedMessageHistoryTest.java
new file mode 100644
index 0000000..00bd095
--- /dev/null
+++ 
b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DeadLetterChannelLogExhaustedMessageHistoryTest.java
@@ -0,0 +1,33 @@
+/**
+ * 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.test.blueprint;
+
+import org.junit.Test;
+
+public class DeadLetterChannelLogExhaustedMessageHistoryTest extends 
CamelBlueprintTestSupport {
+
+    @Override
+    protected String getBlueprintDescriptor() {
+        return 
"org/apache/camel/test/blueprint/DeadLetterChannelLogExhaustedMessageHistoryTest.xml";
+    }
+
+    @Test
+    public void testLogExhaustedMessageHistory() throws Exception {
+        template.sendBody("direct:start", "Hello World");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d3b56df6/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DefaultErrorHandlerLogExhaustedMessageHistoryTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DefaultErrorHandlerLogExhaustedMessageHistoryTest.java
 
b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DefaultErrorHandlerLogExhaustedMessageHistoryTest.java
new file mode 100644
index 0000000..6680d09
--- /dev/null
+++ 
b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DefaultErrorHandlerLogExhaustedMessageHistoryTest.java
@@ -0,0 +1,38 @@
+/**
+ * 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.test.blueprint;
+
+import org.junit.Test;
+
+public class DefaultErrorHandlerLogExhaustedMessageHistoryTest extends 
CamelBlueprintTestSupport {
+
+    @Override
+    protected String getBlueprintDescriptor() {
+        return 
"org/apache/camel/test/blueprint/DefaultErrorHandlerLogExhaustedMessageHistoryTest.xml";
+    }
+
+    @Test
+    public void testLogExhaustedMessageHistory() throws Exception {
+        try {
+            template.sendBody("direct:start", "Hello World");
+            fail("Should fail");
+        } catch (Exception e) {
+            // ignore
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d3b56df6/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/DeadLetterChannelLogExhaustedMessageHistoryTest.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/DeadLetterChannelLogExhaustedMessageHistoryTest.xml
 
b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/DeadLetterChannelLogExhaustedMessageHistoryTest.xml
new file mode 100644
index 0000000..d6a925e
--- /dev/null
+++ 
b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/DeadLetterChannelLogExhaustedMessageHistoryTest.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+           xsi:schemaLocation="
+             http://www.osgi.org/xmlns/blueprint/v1.0.0 
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd";>
+
+  <bean id="forced" class="java.lang.IllegalArgumentException">
+    <argument index="0" value="Forced"/>
+  </bean>
+
+  <camelContext errorHandlerRef="eh" 
xmlns="http://camel.apache.org/schema/blueprint";>
+
+    <errorHandler id="eh" type="DeadLetterChannel" deadLetterUri="mock:dead">
+      <redeliveryPolicy maximumRedeliveries="3" redeliveryDelay="0" 
logExhaustedMessageHistory="true"/>
+    </errorHandler>
+
+    <route>
+      <from uri="direct:start"/>
+      <log message="Incoming ${body}"/>
+      <throwException ref="forced"/>
+    </route>
+  </camelContext>
+
+</blueprint>
+

http://git-wip-us.apache.org/repos/asf/camel/blob/d3b56df6/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/DefaultErrorHandlerLogExhaustedMessageHistoryTest.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/DefaultErrorHandlerLogExhaustedMessageHistoryTest.xml
 
b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/DefaultErrorHandlerLogExhaustedMessageHistoryTest.xml
new file mode 100644
index 0000000..ffb3f8a
--- /dev/null
+++ 
b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/DefaultErrorHandlerLogExhaustedMessageHistoryTest.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+           xsi:schemaLocation="
+             http://www.osgi.org/xmlns/blueprint/v1.0.0 
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd";>
+
+  <bean id="forced" class="java.lang.IllegalArgumentException">
+    <argument index="0" value="Forced"/>
+  </bean>
+
+  <camelContext errorHandlerRef="eh" 
xmlns="http://camel.apache.org/schema/blueprint";>
+
+    <errorHandler id="eh">
+      <redeliveryPolicy maximumRedeliveries="3" redeliveryDelay="0" 
logExhaustedMessageHistory="true"/>
+    </errorHandler>
+
+    <route>
+      <from uri="direct:start"/>
+      <log message="Incoming ${body}"/>
+      <throwException ref="forced"/>
+    </route>
+  </camelContext>
+
+</blueprint>
+

Reply via email to