Author: davsclaus Date: Tue Apr 13 11:11:00 2010 New Revision: 933551 URL: http://svn.apache.org/viewvc?rev=933551&view=rev Log: CAMEL-2637: Fixed errorHandler tag in Spring XML to not work properly with fallback.
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringErrorHandlerConfigFallbackTest.java (with props) camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.java (with props) camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringErrorHandlerConfigFallbackTest.xml - copied, changed from r933492, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/DefaultErrorHandlerConfigTest-context.xml camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.xml (with props) Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.xml Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=933551&r1=933550&r2=933551&view=diff ============================================================================== --- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java (original) +++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java Tue Apr 13 11:11:00 2010 @@ -265,9 +265,6 @@ public class CamelNamespaceHandler exten // set the camel context definition.getPropertyValues().addPropertyValue("camelContext", new RuntimeBeanReference(contextId)); } - if (localName.equals("errorHandler")) { - builder.addPropertyValue("errorHandlerRef", id); - } } } } 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=933551&r1=933550&r2=933551&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 Tue Apr 13 11:11:00 2010 @@ -36,7 +36,6 @@ import org.springframework.util.StringUt * The DefinitionParser to deal with the ErrorHandler */ public class ErrorHandlerDefinitionParser extends BeanDefinitionParser { - protected BeanDefinitionParser redeliveryPolicyParser = new RedeliveryPolicyDefinitionParser(RedeliveryPolicy.class); public ErrorHandlerDefinitionParser() { @@ -114,7 +113,7 @@ public class ErrorHandlerDefinitionParse } } - class RedeliveryPolicyDefinitionParser extends BeanDefinitionParser { + private final class RedeliveryPolicyDefinitionParser extends BeanDefinitionParser { public RedeliveryPolicyDefinitionParser(Class type) { super(type); } Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringErrorHandlerConfigFallbackTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringErrorHandlerConfigFallbackTest.java?rev=933551&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringErrorHandlerConfigFallbackTest.java (added) +++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringErrorHandlerConfigFallbackTest.java Tue Apr 13 11:11:00 2010 @@ -0,0 +1,55 @@ +/** + * 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.config; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @version $Revision$ + */ +public class SpringErrorHandlerConfigFallbackTest extends SpringErrorHandlerConfigTest { + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/spring/config/SpringErrorHandlerConfigFallbackTest.xml"); + } + + public void testDefaultEH() throws Exception { + // TODO: delete me when working + + getMockEndpoint("mock:result").expectedMessageCount(0); + getMockEndpoint("mock:dlc").expectedMessageCount(0); + + Exchange exchange = template.send("direct:start", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setBody("Damn"); + } + }); + + assertMockEndpointsSatisfied(); + + assertTrue(exchange.isFailed()); + assertEquals("Damn cannot do this", exchange.getException(IllegalArgumentException.class).getMessage()); + assertEquals(true, exchange.getIn().getHeader(Exchange.REDELIVERED)); + assertEquals(2, exchange.getIn().getHeader(Exchange.REDELIVERY_COUNTER)); + } + + +} Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringErrorHandlerConfigFallbackTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringErrorHandlerConfigFallbackTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.java?rev=933551&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.java (added) +++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.java Tue Apr 13 11:11:00 2010 @@ -0,0 +1,71 @@ +/** + * 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.config; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.spring.SpringTestSupport; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @version $Revision$ + */ +public class SpringErrorHandlerConfigTest extends SpringTestSupport { + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/spring/config/SpringErrorHandlerConfigTest.xml"); + } + + public void testOk() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); + getMockEndpoint("mock:dlc").expectedMessageCount(0); + + template.sendBody("direct:start", "Hello World"); + + assertMockEndpointsSatisfied(); + } + + public void testDLC() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(0); + getMockEndpoint("mock:dlc").expectedBodiesReceived("Kaboom"); + + template.sendBody("direct:start", "Kaboom"); + + assertMockEndpointsSatisfied(); + } + + public void testDefaultEH() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(0); + getMockEndpoint("mock:dlc").expectedMessageCount(0); + + Exchange exchange = template.send("direct:start", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setBody("Damn"); + } + }); + + assertMockEndpointsSatisfied(); + + assertTrue(exchange.isFailed()); + assertEquals("Damn cannot do this", exchange.getException(IllegalArgumentException.class).getMessage()); + assertEquals(true, exchange.getIn().getHeader(Exchange.REDELIVERED)); + assertEquals(2, exchange.getIn().getHeader(Exchange.REDELIVERY_COUNTER)); + } + +} \ No newline at end of file Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringErrorHandlerConfigFallbackTest.xml (from r933492, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/DefaultErrorHandlerConfigTest-context.xml) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringErrorHandlerConfigFallbackTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringErrorHandlerConfigFallbackTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/DefaultErrorHandlerConfigTest-context.xml&r1=933492&r2=933551&rev=933551&view=diff ============================================================================== --- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/DefaultErrorHandlerConfigTest-context.xml (original) +++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringErrorHandlerConfigFallbackTest.xml Tue Apr 13 11:11:00 2010 @@ -22,21 +22,46 @@ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd "> - <camelContext xmlns="http://camel.apache.org/schema/spring"> - <template id="myTemplate"/> + <bean id="kaboom" class="java.net.ConnectException"> + <constructor-arg index="0" value="Cannot connect"/> + </bean> + + <bean id="damn" class="java.lang.IllegalArgumentException"> + <constructor-arg index="0" value="Damn cannot do this"/> + </bean> + + <camelContext errorHandlerRef="defaultEH" xmlns="http://camel.apache.org/schema/spring"> + + <errorHandler id="defaultEH"> + <redeliveryPolicy maximumRedeliveries="2" redeliveryDelay="0"/> + </errorHandler> + + <errorHandler id="dlc" type="DeadLetterChannel" deadLetterUri="mock:dlc"> + <redeliveryPolicy maximumRedeliveries="3" redeliveryDelay="0"/> + </errorHandler> <route> - <from uri="direct:foo"/> - <to uri="mock:foo"/> + <from uri="direct:start"/> + <choice> + <when> + <simple>${body} == 'Damn'</simple> + <throwException ref="damn"/> + </when> + </choice> + <to uri="direct:bar"/> </route> + <route errorHandlerRef="dlc"> <from uri="direct:bar"/> - <to uri="mock:bar"/> + <choice> + <when> + <simple>${body} == 'Kaboom'</simple> + <throwException ref="kaboom"/> + </when> + </choice> + <to uri="mock:result"/> </route> - </camelContext> - <bean id="dlc" class="org.apache.camel.builder.DeadLetterChannelBuilder"> - <property name="deadLetterUri" value="mock:dead"/> - </bean> + </camelContext> </beans> Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.xml?rev=933551&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.xml (added) +++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.xml Tue Apr 13 11:11:00 2010 @@ -0,0 +1,67 @@ +<?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-2.5.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <bean id="kaboom" class="java.net.ConnectException"> + <constructor-arg index="0" value="Cannot connect"/> + </bean> + + <bean id="damn" class="java.lang.IllegalArgumentException"> + <constructor-arg index="0" value="Damn cannot do this"/> + </bean> + + <camelContext xmlns="http://camel.apache.org/schema/spring"> + + <errorHandler id="defaultEH"> + <redeliveryPolicy maximumRedeliveries="2" redeliveryDelay="0"/> + </errorHandler> + + <errorHandler id="dlc" type="DeadLetterChannel" deadLetterUri="mock:dlc"> + <redeliveryPolicy maximumRedeliveries="3" redeliveryDelay="0"/> + </errorHandler> + + <route errorHandlerRef="defaultEH"> + <from uri="direct:start"/> + <choice> + <when> + <simple>${body} == 'Damn'</simple> + <throwException ref="damn"/> + </when> + </choice> + <to uri="direct:bar"/> + </route> + + <route errorHandlerRef="dlc"> + <from uri="direct:bar"/> + <choice> + <when> + <simple>${body} == 'Kaboom'</simple> + <throwException ref="kaboom"/> + </when> + </choice> + <to uri="mock:result"/> + </route> + + </camelContext> + +</beans> Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.xml ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringErrorHandlerConfigTest.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Modified: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.xml?rev=933551&r1=933550&r2=933551&view=diff ============================================================================== --- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.xml (original) +++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.xml Tue Apr 13 11:11:00 2010 @@ -48,7 +48,7 @@ <camel:errorHandler id="txEH" type="TransactionErrorHandler" transactionManagerRef="txManager"/> <!-- You can also define the errorHandler inside the camelContext --> - <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + <camelContext id="camel" errorHandlerRef="noErrorHandler" xmlns="http://camel.apache.org/schema/spring"> <errorHandler id="noErrorHandler" type="NoErrorHandler"/> </camelContext> <!-- END SNIPPET: example -->