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 2012/03/11 16:48:26 UTC

svn commit: r1299383 - in /camel/trunk/components/camel-spring/src: main/java/org/apache/camel/spring/ main/java/org/apache/camel/spring/handler/ test/java/org/apache/camel/component/properties/ test/resources/org/apache/camel/component/properties/

Author: davsclaus
Date: Sun Mar 11 15:48:25 2012
New Revision: 1299383

URL: http://svn.apache.org/viewvc?rev=1299383&view=rev
Log:
CAMEL-5007: Fixed error handler with inlined redelivery policy to support Camel property placeholders.

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/MyErrorBean.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringErrorHandlerInlinedPropertiesPlaceholderTest.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringErrorHandlerPropertiesPlaceholderTest.java
      - copied, changed from r1299156, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesResolver2Test.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringErrorHandlerInlinedPropertiesPlaceholderTest.xml
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringErrorHandlerPropertiesPlaceholderTest.xml
      - copied, changed from r1299156, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesResolver2Test.xml
Modified:
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/ErrorHandlerDefinition.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/ErrorHandlerDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/ErrorHandlerDefinition.java?rev=1299383&r1=1299382&r2=1299383&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/ErrorHandlerDefinition.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/ErrorHandlerDefinition.java Sun Mar 11 15:48:25 2012
@@ -60,6 +60,6 @@ public class ErrorHandlerDefinition exte
     @XmlAttribute
     private String executorServiceRef;
     @XmlElement
-    private RedeliveryPolicyDefinition redeliveryPolicy;
+    private CamelRedeliveryPolicyFactoryBean redeliveryPolicy;
 
 }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java?rev=1299383&r1=1299382&r2=1299383&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java Sun Mar 11 15:48:25 2012
@@ -22,7 +22,7 @@ import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import org.apache.camel.processor.RedeliveryPolicy;
+import org.apache.camel.spring.CamelRedeliveryPolicyFactoryBean;
 import org.apache.camel.spring.ErrorHandlerType;
 import org.apache.camel.util.ObjectHelper;
 import org.springframework.beans.factory.config.BeanDefinition;
@@ -35,7 +35,7 @@ import org.springframework.util.StringUt
  * The DefinitionParser to deal with the ErrorHandler
  */
 public class ErrorHandlerDefinitionParser extends BeanDefinitionParser {
-    protected BeanDefinitionParser redeliveryPolicyParser = new RedeliveryPolicyDefinitionParser(RedeliveryPolicy.class);
+    protected BeanDefinitionParser redeliveryPolicyParser = new RedeliveryPolicyDefinitionParser(CamelRedeliveryPolicyFactoryBean.class);
     
     public ErrorHandlerDefinitionParser() {
         // need to override the default

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/MyErrorBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/MyErrorBean.java?rev=1299383&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/MyErrorBean.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/MyErrorBean.java Sun Mar 11 15:48:25 2012
@@ -0,0 +1,34 @@
+/**
+ * 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.component.properties;
+
+/**
+ *
+ */
+public class MyErrorBean {
+    
+    private int counter;
+    
+    public void doSomething(String body) {
+        counter++;
+        throw new IllegalArgumentException("Damn");
+    }
+
+    public int getCounter() {
+        return counter;
+    }
+}

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringErrorHandlerInlinedPropertiesPlaceholderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringErrorHandlerInlinedPropertiesPlaceholderTest.java?rev=1299383&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringErrorHandlerInlinedPropertiesPlaceholderTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringErrorHandlerInlinedPropertiesPlaceholderTest.java Sun Mar 11 15:48:25 2012
@@ -0,0 +1,46 @@
+/**
+ * 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.component.properties;
+
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version 
+ */
+public class SpringErrorHandlerInlinedPropertiesPlaceholderTest extends SpringTestSupport {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/properties/SpringErrorHandlerInlinedPropertiesPlaceholderTest.xml");
+    }
+    
+    public void testErrorHandler() throws Exception {
+        getMockEndpoint("mock:dead").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        MyErrorBean bean = context.getRegistry().lookup("errorBean", MyErrorBean.class);
+        assertNotNull(bean);
+        // 1 regular and 3 redeliveries
+        assertEquals(3 + 1, bean.getCounter());
+    }
+
+}
\ No newline at end of file

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringErrorHandlerPropertiesPlaceholderTest.java (from r1299156, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesResolver2Test.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringErrorHandlerPropertiesPlaceholderTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringErrorHandlerPropertiesPlaceholderTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesResolver2Test.java&r1=1299156&r2=1299383&rev=1299383&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesResolver2Test.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringErrorHandlerPropertiesPlaceholderTest.java Sun Mar 11 15:48:25 2012
@@ -16,17 +16,31 @@
  */
 package org.apache.camel.component.properties;
 
+import org.apache.camel.spring.SpringTestSupport;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
  * @version 
  */
-public class SpringPropertiesResolver2Test extends SpringPropertiesResolverTest {
+public class SpringErrorHandlerPropertiesPlaceholderTest extends SpringTestSupport {
 
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
-        return new ClassPathXmlApplicationContext("org/apache/camel/component/properties/SpringPropertiesResolver2Test.xml");
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/properties/SpringErrorHandlerPropertiesPlaceholderTest.xml");
+    }
+    
+    public void testErrorHandler() throws Exception {
+        getMockEndpoint("mock:dead").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        MyErrorBean bean = context.getRegistry().lookup("errorBean", MyErrorBean.class);
+        assertNotNull(bean);
+        // 1 regular and 3 redeliveries
+        assertEquals(3 + 1, bean.getCounter());
     }
 
 }
\ No newline at end of file

Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringErrorHandlerInlinedPropertiesPlaceholderTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringErrorHandlerInlinedPropertiesPlaceholderTest.xml?rev=1299383&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringErrorHandlerInlinedPropertiesPlaceholderTest.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringErrorHandlerInlinedPropertiesPlaceholderTest.xml Sun Mar 11 15:48:25 2012
@@ -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.
+-->
+<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="errorBean" class="org.apache.camel.component.properties.MyErrorBean"/>
+
+    <camelContext errorHandlerRef="dlc" xmlns="http://camel.apache.org/schema/spring">
+        <propertyPlaceholder id="properties"
+                             location="classpath:org/apache/camel/component/properties/cheese.properties"/>
+
+        <errorHandler id="dlc" deadLetterUri="mock:dead" type="DeadLetterChannel">
+          <redeliveryPolicy maximumRedeliveries="{{max}}" redeliveryDelay="0"/>
+        </errorHandler>
+
+        <route>
+            <from uri="direct:start"/>
+            <bean ref="errorBean"/>
+        </route>
+    </camelContext>
+
+</beans>

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringErrorHandlerPropertiesPlaceholderTest.xml (from r1299156, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesResolver2Test.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringErrorHandlerPropertiesPlaceholderTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringErrorHandlerPropertiesPlaceholderTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesResolver2Test.xml&r1=1299156&r2=1299383&rev=1299383&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesResolver2Test.xml (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringErrorHandlerPropertiesPlaceholderTest.xml Sun Mar 11 15:48:25 2012
@@ -21,16 +21,20 @@
        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="errorBean" class="org.apache.camel.component.properties.MyErrorBean"/>
 
-    <bean id="myResolver" class="org.apache.camel.component.properties.PropertiesResolverTest$MyCustomResolver"/>
-
-    <camelContext xmlns="http://camel.apache.org/schema/spring">
+    <camelContext errorHandlerRef="dlc" xmlns="http://camel.apache.org/schema/spring">
         <propertyPlaceholder id="properties"
-                             location="foo"
-                             propertiesResolverRef="myResolver"/>
+                             location="classpath:org/apache/camel/component/properties/cheese.properties"/>
+
+        <errorHandler id="dlc" deadLetterUri="mock:dead" type="DeadLetterChannel" redeliveryPolicyRef="myRedelivery"/>
+
+        <redeliveryPolicyProfile id="myRedelivery" maximumRedeliveries="{{max}}" redeliveryDelay="0"/>
+
         <route>
             <from uri="direct:start"/>
-            <to uri="properties:foo"/>
+            <bean ref="errorBean"/>
         </route>
     </camelContext>