Skip to content

Commit

Permalink
CAMEL-7050: DeadLetterChannel should make more clear that it handles …
Browse files Browse the repository at this point in the history
…any new exception also. Added option to configure this behavior so ppl can turn that off and let new exceptions be unhandled, so transactions can rollback.
  • Loading branch information
davsclaus committed Jan 18, 2015
1 parent 37d4914 commit fb120df
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 2 deletions.
Expand Up @@ -31,7 +31,7 @@ public void onException(Exchange exchange, Exception exception) throws Exception
}
}

public void testDeadLetterChannelNewException() throws Exception {
public void testDeadLetterChannelNotHandleNewException() throws Exception {
try {
template.sendBody("direct:start", "Hello World");
fail("Should have thrown exception");
Expand Down
Expand Up @@ -67,7 +67,7 @@ public TransactionErrorHandler(CamelContext camelContext, Processor output, Came
TransactionTemplate transactionTemplate, Predicate retryWhile, ScheduledExecutorService executorService,
LoggingLevel rollbackLoggingLevel) {

super(camelContext, output, logger, redeliveryProcessor, redeliveryPolicy, null, null, false, retryWhile, executorService);
super(camelContext, output, logger, redeliveryProcessor, redeliveryPolicy, null, null, false, false, retryWhile, executorService);
setExceptionPolicy(exceptionPolicyStrategy);
this.transactionTemplate = transactionTemplate;
this.rollbackLoggingLevel = rollbackLoggingLevel;
Expand Down
@@ -0,0 +1,29 @@
/**
* 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.DeadLetterChannelNewExceptionTest;

import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;

public class SpringDeadLetterChannelNewExceptionTest extends DeadLetterChannelNewExceptionTest {

protected CamelContext createCamelContext() throws Exception {
return createSpringCamelContext(this, "org/apache/camel/spring/processor/DeadLetterChannelNewExceptionTest.xml");
}
}
@@ -0,0 +1,29 @@
/**
* 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.DeadLetterChannelNotHandleNewExceptionTest;

import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;

public class SpringDeadLetterChannelNotHandleNewExceptionTest extends DeadLetterChannelNotHandleNewExceptionTest {

protected CamelContext createCamelContext() throws Exception {
return createSpringCamelContext(this, "org/apache/camel/spring/processor/DeadLetterChannelNotHandleNewExceptionTest.xml");
}
}
@@ -0,0 +1,43 @@
<?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>

<bean id="badErrorHandler"
class="org.apache.camel.processor.DeadLetterChannelNotHandleNewExceptionTest.BadErrorHandler"/>

<camelContext xmlns="http://camel.apache.org/schema/spring" errorHandlerRef="dlc">

<errorHandler id="dlc" type="DeadLetterChannel" deadLetterUri="bean:badErrorHandler" deadLetterHandleNewException="true"/>

<route>
<from uri="direct:start"/>
<log message="Incoming ${body}"/>
<throwException ref="forced"/>
</route>
</camelContext>

</beans>
@@ -0,0 +1,43 @@
<?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>

<bean id="badErrorHandler"
class="org.apache.camel.processor.DeadLetterChannelNotHandleNewExceptionTest.BadErrorHandler"/>

<camelContext xmlns="http://camel.apache.org/schema/spring" errorHandlerRef="dlc">

<errorHandler id="dlc" type="DeadLetterChannel" deadLetterUri="bean:badErrorHandler" deadLetterHandleNewException="false"/>

<route>
<from uri="direct:start"/>
<log message="Incoming ${body}"/>
<throwException ref="forced"/>
</route>
</camelContext>

</beans>

0 comments on commit fb120df

Please sign in to comment.