You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2009/01/05 21:06:13 UTC
svn commit: r731675 - in /activemq/camel/trunk/components/camel-spring/src:
main/java/org/apache/camel/spring/ main/java/org/apache/camel/spring/handler/
test/resources/org/apache/camel/spring/processor/onexception/
Author: janstey
Date: Mon Jan 5 12:06:12 2009
New Revision: 731675
URL: http://svn.apache.org/viewvc?rev=731675&view=rev
Log:
CAMEL-1220 - add ability to configure a single exception clause for multiple routes in Spring DSL
Modified:
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/RedeliveryPolicyRefTest.xml
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml
Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=731675&r1=731674&r2=731675&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java Mon Jan 5 12:06:12 2009
@@ -103,6 +103,8 @@
private List<EndpointFactoryBean> endpoints;
@XmlElement(name = "dataFormats", required = false)
private DataFormatsType dataFormats;
+ @XmlElement(name = "onException", required = false)
+ private List<ExceptionType> exceptionClauses = new ArrayList<ExceptionType>();
@XmlElement(name = "intercept", required = false)
private List<InterceptType> intercepts = new ArrayList<InterceptType>();
@XmlElement(name = "route", required = false)
@@ -185,6 +187,10 @@
// setup the intercepts
for (RouteType route : routes) {
+ if (exceptionClauses != null) {
+ route.getOutputs().addAll(exceptionClauses);
+ }
+
for (InterceptType intercept : intercepts) {
List<ProcessorType<?>> outputs = new ArrayList<ProcessorType<?>>();
List<ProcessorType<?>> exceptionHandlers = new ArrayList<ProcessorType<?>>();
@@ -201,7 +207,7 @@
// add exception handlers as top children
route.getOutputs().addAll(exceptionHandlers);
-
+
// add the interceptor
InterceptType proxy = intercept.createProxy();
route.addOutput(proxy);
@@ -220,8 +226,8 @@
if (dataFormats != null) {
getContext().setDataFormats(dataFormats.asMap());
- }
-
+ }
+
// lets force any lazy creation
getContext().addRouteDefinitions(routes);
@@ -520,4 +526,12 @@
public DataFormatsType getDataFormats() {
return dataFormats;
}
+
+ public void setExceptionClauses(List<ExceptionType> exceptionClauses) {
+ this.exceptionClauses = exceptionClauses;
+ }
+
+ public List<ExceptionType> getExceptionClauses() {
+ return exceptionClauses;
+ }
}
Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=731675&r1=731674&r2=731675&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java Mon Jan 5 12:06:12 2009
@@ -205,6 +205,7 @@
builder.addPropertyValue("routes", factoryBean.getRoutes());
builder.addPropertyValue("intercepts", factoryBean.getIntercepts());
builder.addPropertyValue("dataFormats", factoryBean.getDataFormats());
+ builder.addPropertyValue("exceptionClauses", factoryBean.getExceptionClauses());
builder.addPropertyValue("builderRefs", factoryBean.getBuilderRefs());
if (factoryBean.getPackages().length > 0) {
Modified: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/RedeliveryPolicyRefTest.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/RedeliveryPolicyRefTest.xml?rev=731675&r1=731674&r2=731675&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/RedeliveryPolicyRefTest.xml (original)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/RedeliveryPolicyRefTest.xml Mon Jan 5 12:06:12 2009
@@ -35,28 +35,26 @@
<!-- this is the camel context where we define the routes -->
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+ <onException>
+ <!-- the exception is full qualified names as plain strings -->
+ <!-- there can be more just add a 2nd, 3rd exception element (unbounded) -->
+ <exception>org.apache.camel.spring.processor.onexception.OrderFailedException</exception>
+ <exception>java.lang.IllegalArgumentException</exception>
+ <!-- here we reference our redelivy policy -->
+ <redeliveryPolicy ref="myRedeliveryPolicy"/>
+ <!-- mark this as handled -->
+ <handled>
+ <constant>true</constant>
+ </handled>
+ <!-- let our order service handle this exception, call the orderFailed method -->
+ <bean ref="orderService" method="orderFailed"/>
+ <!-- and since this is a unit test we use mock for assertions -->
+ <to uri="mock:error"/>
+ </onException>
+
<route>
<!-- the route -->
<from uri="direct:start"/>
-
- <!-- we must configure the on exception within the route, as opposed to Java DSL where we can do this outside -->
- <onException>
- <!-- the exception is full qualified names as plain strings -->
- <!-- there can be more just add a 2nd, 3rd exception element (unbounded) -->
- <exception>org.apache.camel.spring.processor.onexception.OrderFailedException</exception>
- <exception>java.lang.IllegalArgumentException</exception>
- <!-- here we reference our redelivy policy -->
- <redeliveryPolicy ref="myRedeliveryPolicy"/>
- <!-- mark this as handled -->
- <handled>
- <constant>true</constant>
- </handled>
- <!-- let our order service handle this exception, call the orderFailed method -->
- <bean ref="orderService" method="orderFailed"/>
- <!-- and since this is a unit test we use mock for assertions -->
- <to uri="mock:error"/>
- </onException>
-
<!-- in the normal route then route to our order service and call handleOrder method -->
<bean ref="orderService" method="handleOrder"/>
<!-- and since this is a unit test we use mock for assertions -->
Modified: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml?rev=731675&r1=731674&r2=731675&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml (original)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml Mon Jan 5 12:06:12 2009
@@ -30,27 +30,25 @@
<!-- this is the camel context where we define the routes -->
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+ <onException>
+ <!-- the exception is full qualified names as plain strings -->
+ <!-- there can be more just add a 2nd, 3rd exception element (unbounded) -->
+ <exception>org.apache.camel.spring.processor.onexception.OrderFailedException</exception>
+ <!-- we can set the redelivery policy here as well -->
+ <redeliveryPolicy maximumRedeliveries="1"/>
+ <!-- mark this as handled -->
+ <handled>
+ <constant>true</constant>
+ </handled>
+ <!-- let our order service handle this exception, call the orderFailed method -->
+ <bean ref="orderService" method="orderFailed"/>
+ <!-- and since this is a unit test we use mock for assertions -->
+ <to uri="mock:error"/>
+ </onException>
+
<route>
<!-- the route -->
<from uri="direct:start"/>
-
- <!-- we must configure the on exception within the route, as opposed to Java DSL where we can do this outside -->
- <onException>
- <!-- the exception is full qualified names as plain strings -->
- <!-- there can be more just add a 2nd, 3rd exception element (unbounded) -->
- <exception>org.apache.camel.spring.processor.onexception.OrderFailedException</exception>
- <!-- we can set the redelivery policy here as well -->
- <redeliveryPolicy maximumRedeliveries="1"/>
- <!-- mark this as handled -->
- <handled>
- <constant>true</constant>
- </handled>
- <!-- let our order service handle this exception, call the orderFailed method -->
- <bean ref="orderService" method="orderFailed"/>
- <!-- and since this is a unit test we use mock for assertions -->
- <to uri="mock:error"/>
- </onException>
-
<!-- in the normal route then route to our order service and call handleOrder method -->
<bean ref="orderService" method="handleOrder"/>
<!-- and since this is a unit test we use mock for assertions -->
Modified: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml?rev=731675&r1=731674&r2=731675&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml (original)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml Mon Jan 5 12:06:12 2009
@@ -38,37 +38,36 @@
<!-- this is the camel context where we define the routes -->
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring" errorHandlerRef="dlc">
- <route>
- <from uri="direct:a"/>
+ <onException>
+ <exception>java.lang.NullPointerException</exception>
+ <redeliveryPolicy maximumRedeliveries="0"/>
+ <setHeader headerName="messageInfo">
+ <constant>Damm a NPE</constant>
+ </setHeader>
+ <to uri="mock:error"/>
+ </onException>
+
+ <!-- START SNIPPET: e1 -->
+ <onException>
+ <exception>java.io.IOException</exception>
+ <redeliveryPolicy
+ redeliveryDelay="1000"
+ maximumRedeliveries="3"
+ maximumRedeliveryDelay="10000"
+ backOffMultiplier="1.0"
+ useExponentialBackOff="true"
+ retryAttemptedLogLevel="TRACE"
+ retriesExhaustedLogLevel="FATAL"
+ />
+ <setHeader headerName="messageInfo">
+ <constant>Damm somekind of IO exception</constant>
+ </setHeader>
+ <to uri="mock:error"/>
+ </onException>
+ <!-- END SNIPPET: e1 -->
- <!-- we must configure the on exception within the route, as opposed to Java DSL where we can do this outside -->
- <onException>
- <exception>java.lang.NullPointerException</exception>
- <redeliveryPolicy maximumRedeliveries="0"/>
- <setHeader headerName="messageInfo">
- <constant>Damm a NPE</constant>
- </setHeader>
- <to uri="mock:error"/>
- </onException>
- <!-- START SNIPPET: e1 -->
- <onException>
- <exception>java.io.IOException</exception>
- <redeliveryPolicy
- redeliveryDelay="1000"
- maximumRedeliveries="3"
- maximumRedeliveryDelay="10000"
- backOffMultiplier="1.0"
- useExponentialBackOff="true"
- retryAttemptedLogLevel="TRACE"
- retriesExhaustedLogLevel="FATAL"
- />
- <setHeader headerName="messageInfo">
- <constant>Damm somekind of IO exception</constant>
- </setHeader>
- <to uri="mock:error"/>
- </onException>
- <!-- END SNIPPET: e1 -->
-
+ <route>
+ <from uri="direct:a"/>
<process ref="myExceptionThrowingProcessor"/>
<to uri="mock:result"/>
</route>