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/55fe6ef1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/55fe6ef1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/55fe6ef1

Branch: refs/heads/master
Commit: 55fe6ef16abf50340ae984a4feb6be4d309c6d10
Parents: f40a200
Author: Claus Ibsen <davscl...@apache.org>
Authored: Sun May 10 11:46:48 2015 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Sun May 10 11:46:48 2015 +0200

----------------------------------------------------------------------
 .../handler/ErrorHandlerDefinitionParser.java   | 21 ++++++++--
 ...erChannelLogExhaustedMessageHistoryTest.java | 32 +++++++++++++++
 ...orHandlerLogExhaustedMessageHistoryTest.java | 32 +++++++++++++++
 ...terChannelLogExhaustedMessageHistoryTest.xml | 42 ++++++++++++++++++++
 ...rorHandlerLogExhaustedMessageHistoryTest.xml | 42 ++++++++++++++++++++
 5 files changed, 166 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/55fe6ef1/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java
 
b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java
index 65ae81a..dde1229 100644
--- 
a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java
+++ 
b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java
@@ -35,8 +35,7 @@ import org.springframework.util.StringUtils;
  * The DefinitionParser to deal with the ErrorHandler
  */
 public class ErrorHandlerDefinitionParser extends BeanDefinitionParser {
-    protected BeanDefinitionParser redeliveryPolicyParser = new 
RedeliveryPolicyDefinitionParser(CamelRedeliveryPolicyFactoryBean.class);
-    
+
     public ErrorHandlerDefinitionParser() {
         // need to override the default
         super(null, false);
@@ -94,6 +93,8 @@ public class ErrorHandlerDefinitionParser extends 
BeanDefinitionParser {
                             throw new IllegalArgumentException("Cannot set 
both redeliveryPolicyRef and redeliveryPolicy,"
                                     + " only one allowed, in error handler 
with id: " + id);
                         }
+                        boolean deadLetter = 
type.equals(ErrorHandlerType.DeadLetterChannel);
+                        BeanDefinitionParser redeliveryPolicyParser = new 
RedeliveryPolicyDefinitionParser(CamelRedeliveryPolicyFactoryBean.class, 
deadLetter);
                         BeanDefinition redeliveryPolicyDefinition = 
redeliveryPolicyParser.parse(childElement, parserContext);
                         builder.addPropertyValue(localName, 
redeliveryPolicyDefinition);
                     }
@@ -194,13 +195,27 @@ public class ErrorHandlerDefinitionParser extends 
BeanDefinitionParser {
     
     protected class RedeliveryPolicyDefinitionParser extends 
BeanDefinitionParser {
 
-        public RedeliveryPolicyDefinitionParser(Class<?> type) {
+        private final boolean deadLetter;
+
+        public RedeliveryPolicyDefinitionParser(Class<?> type, boolean 
deadLetter) {
             super(type, false);
+            this.deadLetter = deadLetter;
         }
 
         protected boolean shouldGenerateId() {
             return true;
         }
+
+        protected void doParse(Element element, ParserContext parserContext, 
BeanDefinitionBuilder builder) {
+            super.doParse(element, parserContext, builder);
+
+            // if dead letter then set logExhaustedMessageHistory default 
false if not explicit configured
+            boolean hasLogExhaustedMessageHistory = 
element.hasAttribute("logExhaustedMessageHistory");
+            if (deadLetter && !hasLogExhaustedMessageHistory) {
+                builder.addPropertyValue("logExhaustedMessageHistory", 
"false");
+            }
+        }
+
     }
     
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/55fe6ef1/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelLogExhaustedMessageHistoryTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelLogExhaustedMessageHistoryTest.java
 
b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelLogExhaustedMessageHistoryTest.java
new file mode 100644
index 0000000..ff1a861
--- /dev/null
+++ 
b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelLogExhaustedMessageHistoryTest.java
@@ -0,0 +1,32 @@
+/**
+ * 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.spring.processor;
+
+import org.apache.camel.CamelContext;
+import 
org.apache.camel.processor.DeadLetterChannelLogExhaustedMessageHistoryTest;
+
+import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+/**
+ * @version 
+ */
+public class SpringDeadLetterChannelLogExhaustedMessageHistoryTest extends 
DeadLetterChannelLogExhaustedMessageHistoryTest {
+
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, 
"org/apache/camel/spring/processor/DeadLetterChannelLogExhaustedMessageHistoryTest.xml");
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/55fe6ef1/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDefaultErrorHandlerLogExhaustedMessageHistoryTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDefaultErrorHandlerLogExhaustedMessageHistoryTest.java
 
b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDefaultErrorHandlerLogExhaustedMessageHistoryTest.java
new file mode 100644
index 0000000..01f1624
--- /dev/null
+++ 
b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDefaultErrorHandlerLogExhaustedMessageHistoryTest.java
@@ -0,0 +1,32 @@
+/**
+ * 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.spring.processor;
+
+import org.apache.camel.CamelContext;
+import 
org.apache.camel.processor.DefaultErrorHandlerLogExhaustedMessageHistoryTest;
+
+import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+/**
+ * @version 
+ */
+public class SpringDefaultErrorHandlerLogExhaustedMessageHistoryTest extends 
DefaultErrorHandlerLogExhaustedMessageHistoryTest {
+
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, 
"org/apache/camel/spring/processor/DefaultErrorHandlerLogExhaustedMessageHistoryTest.xml");
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/55fe6ef1/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/DeadLetterChannelLogExhaustedMessageHistoryTest.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/DeadLetterChannelLogExhaustedMessageHistoryTest.xml
 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/DeadLetterChannelLogExhaustedMessageHistoryTest.xml
new file mode 100644
index 0000000..00eef48
--- /dev/null
+++ 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/DeadLetterChannelLogExhaustedMessageHistoryTest.xml
@@ -0,0 +1,42 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <bean id="forced" class="java.lang.IllegalArgumentException">
+    <constructor-arg index="0" value="Forced"/>
+  </bean>
+
+  <camelContext errorHandlerRef="eh" 
xmlns="http://camel.apache.org/schema/spring";>
+
+    <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>
+
+</beans>

http://git-wip-us.apache.org/repos/asf/camel/blob/55fe6ef1/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/DefaultErrorHandlerLogExhaustedMessageHistoryTest.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/DefaultErrorHandlerLogExhaustedMessageHistoryTest.xml
 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/DefaultErrorHandlerLogExhaustedMessageHistoryTest.xml
new file mode 100644
index 0000000..7af32c1
--- /dev/null
+++ 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/DefaultErrorHandlerLogExhaustedMessageHistoryTest.xml
@@ -0,0 +1,42 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <bean id="forced" class="java.lang.IllegalArgumentException">
+    <constructor-arg index="0" value="Forced"/>
+  </bean>
+
+  <camelContext errorHandlerRef="eh" 
xmlns="http://camel.apache.org/schema/spring";>
+
+    <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>
+
+</beans>

Reply via email to