camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r932938 - in /camel/trunk/components/camel-spring/src: main/java/org/apache/camel/spring/ main/java/org/apache/camel/spring/handler/ main/java/org/apache/camel/spring/spi/ test/java/org/apache/camel/spring/handler/ test/resources/org/apache...
Date Sun, 11 Apr 2010 17:03:07 GMT
Author: davsclaus
Date: Sun Apr 11 17:03:07 2010
New Revision: 932938

URL: http://svn.apache.org/viewvc?rev=932938&view=rev
Log:
Added missing options to ErrorHandler Spring XML style.

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/ErrorHandlerType.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/handler/ErrorHandlerDefintionParserTest.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/ErrorHandlerDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/ErrorHandlerDefinition.java?rev=932938&r1=932937&r2=932938&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 Apr 11 17:03:07 2010
@@ -33,23 +33,26 @@ import org.apache.camel.model.config.Pro
 /**
  * The <errorHandler> tag element.
  *
+ * @version $Revision$
  */
 @XmlRootElement(name = "errorHandler")
 @XmlAccessorType(XmlAccessType.FIELD)
 public class ErrorHandlerDefinition extends IdentifiedType {
-    @XmlAttribute(required = false)
-    private ErrorHandlerType type;
-    @XmlAttribute(required = false)
+    @XmlAttribute
+    private ErrorHandlerType type = ErrorHandlerType.DefaultErrorHandler;
+    @XmlAttribute
     private String deadLetterUri;
-    @XmlAttribute(required = false)
-    private LoggingLevel level;
-    @XmlAttribute(required = false)
+    @XmlAttribute
+    private LoggingLevel level = LoggingLevel.ERROR;
+    @XmlAttribute
     private Boolean useOriginalMessage;
-    @XmlAttribute(required = false)
+    @XmlAttribute
     private String transactionTemplateRef;
-    @XmlAttribute(required = false)
+    @XmlAttribute
+    private String transactionManagerRef;
+    @XmlAttribute
     private String onRedeliveryRef;
-    @XmlElement(name = "redeliveryPolicy", required = false)
+    @XmlElement(name = "redeliveryPolicy")
     private RedeliveryPolicyDefinition redeliveryPolicy;
    
 }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/ErrorHandlerType.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/ErrorHandlerType.java?rev=932938&r1=932937&r2=932938&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/ErrorHandlerType.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/ErrorHandlerType.java
Sun Apr 11 17:03:07 2010
@@ -17,13 +17,45 @@
 package org.apache.camel.spring;
 
 import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlType;
+
+import org.apache.camel.builder.DeadLetterChannelBuilder;
+import org.apache.camel.builder.DefaultErrorHandlerBuilder;
+import org.apache.camel.builder.LoggingErrorHandlerBuilder;
+import org.apache.camel.builder.NoErrorHandlerBuilder;
+import org.apache.camel.spring.spi.TransactionErrorHandlerBuilder;
 
 /**
  * Used to configure the errorHandler type
  *
  * @version $Revision$
  */
-@XmlEnum
+@XmlType
+@XmlEnum(String.class)
 public enum ErrorHandlerType {
-   DefaultErrorHandler, DeadLetterChannel, LoggingErrorHandler, NoErrorHandler, TransactionErrorHandler
+
+    DefaultErrorHandler, DeadLetterChannel, LoggingErrorHandler, NoErrorHandler, TransactionErrorHandler;
+
+    /**
+     * Get the type as class.
+     *
+     * @return the class which represents the selected type.
+     */
+    public Class getTypeAsClass() {
+        switch (this) {
+        case DefaultErrorHandler:
+            return DefaultErrorHandlerBuilder.class;
+        case DeadLetterChannel:
+            return DeadLetterChannelBuilder.class;
+        case LoggingErrorHandler:
+            return LoggingErrorHandlerBuilder.class;
+        case NoErrorHandler:
+            return NoErrorHandlerBuilder.class;
+        case TransactionErrorHandler:
+            return TransactionErrorHandlerBuilder.class;
+        default:
+            throw new IllegalArgumentException("Unknown error handler: " + this);
+        }
+    }
+
 }

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=932938&r1=932937&r2=932938&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 Apr 11 17:03:07 2010
@@ -17,32 +17,18 @@
 
 package org.apache.camel.spring.handler;
 
-import java.lang.reflect.Method;
-
 import org.w3c.dom.Attr;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import org.apache.camel.builder.DeadLetterChannelBuilder;
-import org.apache.camel.builder.DefaultErrorHandlerBuilder;
-import org.apache.camel.builder.LoggingErrorHandlerBuilder;
-import org.apache.camel.builder.NoErrorHandlerBuilder;
 import org.apache.camel.processor.RedeliveryPolicy;
-import org.apache.camel.spring.CamelEndpointFactoryBean;
 import org.apache.camel.spring.ErrorHandlerType;
-import org.apache.camel.spring.spi.TransactionErrorHandlerBuilder;
 import org.apache.camel.util.ObjectHelper;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+
 import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.BeanDefinitionHolder;
-import org.springframework.beans.factory.config.RuntimeBeanReference;
-import org.springframework.beans.factory.parsing.BeanComponentDefinition;
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
-import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
 import org.springframework.beans.factory.xml.ParserContext;
 import org.springframework.util.Assert;
 import org.springframework.util.StringUtils;
@@ -51,42 +37,23 @@ import org.springframework.util.StringUt
  * The DefinitionParser to deal with the ErrorHandler
  */
 public class ErrorHandlerDefinitionParser extends BeanDefinitionParser {
-    private static final Log LOG = LogFactory.getLog(ErrorHandlerDefinitionParser.class);
+
+    // TODO: use a FactoryBean instead to create a ErrorHandlerBuilder object
+
     protected BeanDefinitionParser redeliveryPolicyParser = new RedeliveryPolicyDefinitionParser(RedeliveryPolicy.class);
     
     public ErrorHandlerDefinitionParser() {
-        // Need to override the default 
+        // need to override the default
         super(null);
-        
     }
 
     protected Class getBeanClass(Element element) {
         ErrorHandlerType type = ErrorHandlerType.DefaultErrorHandler;
-        
+
         if (ObjectHelper.isNotEmpty(element.getAttribute("type"))) {
             type = ErrorHandlerType.valueOf(element.getAttribute("type"));
         }
-        Class clazz = null;
-        if (type.equals(ErrorHandlerType.NoErrorHandler)) {
-            clazz = NoErrorHandlerBuilder.class;
-        }
-        if (type.equals(ErrorHandlerType.DeadLetterChannel)) {
-            clazz = DeadLetterChannelBuilder.class;
-            
-        }
-        if (type.equals(ErrorHandlerType.LoggingErrorHandler)) {
-            clazz = LoggingErrorHandlerBuilder.class;
-        }
-        if (type.equals(ErrorHandlerType.DefaultErrorHandler)) {
-            clazz = DefaultErrorHandlerBuilder.class;
-        }
-        if (type.equals(ErrorHandlerType.TransactionErrorHandler)) {
-            clazz = TransactionErrorHandlerBuilder.class;
-        }
-        if (clazz == null) {
-            throw new IllegalArgumentException("Cannot find the ErrorHandle with type " +
type);
-        }
-        return clazz;
+        return type.getTypeAsClass();
     }
     
     protected boolean isEligibleAttribute(String attributeName) {
@@ -95,8 +62,7 @@ public class ErrorHandlerDefinitionParse
                 && !attributeName.equals("type") && !attributeName.equals("onRedeliveryRef")
                 && !attributeName.equals("transactionTemplateRef");
     }
-   
-    
+
     @Override
     protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder
builder) {
         super.doParse(element, parserContext, builder);
@@ -131,6 +97,7 @@ public class ErrorHandlerDefinitionParse
         if (type.equals(ErrorHandlerType.TransactionErrorHandler)) {
             // deal with transactionTemplateRef
             parserRefAttribute(element, "transactionTemplateRef", "transactionTemplate",
builder);
+            parserRefAttribute(element, "transactionManagerRef", "transactionManager", builder);
         }
     }
 

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java?rev=932938&r1=932937&r2=932938&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java
Sun Apr 11 17:03:07 2010
@@ -125,6 +125,10 @@ public class TransactionErrorHandlerBuil
         this.transactionTemplate = policy.getTransactionTemplate();
     }
 
+    public void setTransactionManager(PlatformTransactionManager transactionManager) {
+        this.transactionTemplate = new TransactionTemplate(transactionManager);
+    }
+
     // Builder methods
     // -------------------------------------------------------------------------
 

Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/handler/ErrorHandlerDefintionParserTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/handler/ErrorHandlerDefintionParserTest.java?rev=932938&r1=932937&r2=932938&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/handler/ErrorHandlerDefintionParserTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/handler/ErrorHandlerDefintionParserTest.java
Sun Apr 11 17:03:07 2010
@@ -22,11 +22,7 @@ import org.apache.camel.Processor;
 import org.apache.camel.builder.DeadLetterChannelBuilder;
 import org.apache.camel.builder.DefaultErrorHandlerBuilder;
 import org.apache.camel.builder.LoggingErrorHandlerBuilder;
-import org.apache.camel.component.direct.DirectEndpoint;
-import org.apache.camel.processor.DefaultErrorHandler;
 import org.apache.camel.processor.RedeliveryPolicy;
-import org.apache.camel.processor.exceptionpolicy.DefaultExceptionPolicyStrategy;
-import org.apache.camel.processor.exceptionpolicy.ExceptionPolicyStrategy;
 import org.apache.camel.spring.CamelContextFactoryBean;
 import org.apache.camel.spring.spi.TransactionErrorHandlerBuilder;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -38,7 +34,6 @@ public class ErrorHandlerDefintionParser
         ctx =  new ClassPathXmlApplicationContext("org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.xml");
     }
 
-    
     public void tearDown() throws Exception {
         ctx.close();        
     }
@@ -60,7 +55,6 @@ public class ErrorHandlerDefintionParser
         
         errorHandler = (DefaultErrorHandlerBuilder) ctx.getBean("errorHandler");
         assertNotNull(errorHandler);
-        
     }
     
     public void testTransactionErrorHandler() {
@@ -71,6 +65,12 @@ public class ErrorHandlerDefintionParser
         assertTrue("It should be MyErrorProcessor", processor instanceof MyErrorProcessor);
     }
     
+    public void testTXErrorHandler() {
+        TransactionErrorHandlerBuilder errorHandler = (TransactionErrorHandlerBuilder) ctx.getBean("txEH");
+        assertNotNull(errorHandler);
+        assertNotNull(errorHandler.getTransactionTemplate());
+    }
+
     public void testDeadLetterErrorHandler() {
         DeadLetterChannelBuilder errorHandler = (DeadLetterChannelBuilder) ctx.getBean("deadLetterErrorHandler");
         assertNotNull(errorHandler);
@@ -83,7 +83,7 @@ public class ErrorHandlerDefintionParser
     }
     
     public void testErrorHandlerInsideCamelContext() {
-        CamelContextFactoryBean factoryBean = (CamelContextFactoryBean)ctx.getBean("&camel");
+        CamelContextFactoryBean factoryBean = (CamelContextFactoryBean) ctx.getBean("&camel");
         assertNotNull(factoryBean);
         assertEquals("Wrong ErrorHandlerRef", "noErrorHandler", factoryBean.getErrorHandlerRef());
     }

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=932938&r1=932937&r2=932938&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
Sun Apr 11 17:03:07 2010
@@ -23,33 +23,36 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-<!-- START SNIPPET: example -->
-    
-    <errorHandler id="loggingErrorHandler" xmlns="http://camel.apache.org/schema/spring"
type="LoggingErrorHandler" level="INFO" />
-    
+    <!-- START SNIPPET: example -->
+    <errorHandler id="loggingErrorHandler" type="LoggingErrorHandler" level="INFO" xmlns="http://camel.apache.org/schema/spring"/>
+
     <!-- If don't specify type attribute, the type value will be set to DefaultErrorHandler
-->
-    <errorHandler id="errorHandler" xmlns="http://camel.apache.org/schema/spring" />
-    
+    <errorHandler id="errorHandler" xmlns="http://camel.apache.org/schema/spring"/>
+
     <!-- You can define the redeliveryPolicy inside of the errorHandler -->
     <camel:errorHandler id="defaultErrorHandler" type="DefaultErrorHandler">
-       <camel:redeliveryPolicy maximumRedeliveries="2" redeliveryDelay="0" logStackTrace="false"
/>
+        <camel:redeliveryPolicy maximumRedeliveries="2" redeliveryDelay="0" logStackTrace="false"/>
     </camel:errorHandler>
-    
+
     <camel:errorHandler id="deadLetterErrorHandler" type="DeadLetterChannel" deadLetterUri="log:dead">
-       <camel:redeliveryPolicy maximumRedeliveries="2" redeliveryDelay="1000" logHandled="true"
/>
+        <camel:redeliveryPolicy maximumRedeliveries="2" redeliveryDelay="1000" logHandled="true"/>
     </camel:errorHandler>
-    
+
     <bean id="myErrorProcessor" class="org.apache.camel.spring.handler.MyErrorProcessor"/>
-    
-    <camel:errorHandler id="transactionErrorHandler" type="TransactionErrorHandler" transactionTemplateRef="PROPAGATION_REQUIRED"
onRedeliveryRef="myErrorProcessor" />
-    
+
+    <!-- TX error handler can be configured using a template -->
+    <camel:errorHandler id="transactionErrorHandler" type="TransactionErrorHandler"
+                        transactionTemplateRef="PROPAGATION_REQUIRED" onRedeliveryRef="myErrorProcessor"/>
+
+    <!-- or using a transaction manager -->
+    <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">
-    	<errorHandler id="noErrorHandler" type="NoErrorHandler"/>
+        <errorHandler id="noErrorHandler" type="NoErrorHandler"/>
     </camelContext>
- 
- <!-- END SNIPPET: example -->     
-    
+    <!-- END SNIPPET: example -->
+
     <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
         <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
         <property name="url" value="jdbc:hsqldb:mem:camel"/>
@@ -66,5 +69,4 @@
         <property name="transactionManager" ref="txManager"/>
     </bean>
 
-
 </beans>



Mime
View raw message