camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1239045 - in /camel/trunk/components: camel-jms/src/test/resources/org/apache/camel/component/jms/tx/ camel-spring/src/main/java/org/apache/camel/spring/ camel-spring/src/main/java/org/apache/camel/spring/handler/ camel-spring/src/main/jav...
Date Wed, 01 Feb 2012 10:43:13 GMT
Author: davsclaus
Date: Wed Feb  1 10:43:12 2012
New Revision: 1239045

URL: http://svn.apache.org/viewvc?rev=1239045&view=rev
Log:
CAMEL-4965: Allow to configure transaction error handler rollback logging level.

Modified:
    camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml
    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
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java

Modified: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml?rev=1239045&r1=1239044&r2=1239045&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml
(original)
+++ camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml
Wed Feb  1 10:43:12 2012
@@ -46,8 +46,8 @@
 
     <camelContext xmlns="http://camel.apache.org/schema/spring">
 
-      <!-- we do not want any exceptions to be logged -->
-      <errorHandler id="txEH" type="TransactionErrorHandler">
+      <!-- we do not want any exceptions to be logged, neither that a rollback occurred
-->
+      <errorHandler id="txEH" type="TransactionErrorHandler" rollbackLoggingLevel="ERROR">
         <redeliveryPolicy logStackTrace="false" logExhausted="false"/>
       </errorHandler>
 

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=1239045&r1=1239044&r2=1239045&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
Wed Feb  1 10:43:12 2012
@@ -42,6 +42,8 @@ public class ErrorHandlerDefinition exte
     @XmlAttribute
     private LoggingLevel level = LoggingLevel.ERROR;
     @XmlAttribute
+    private LoggingLevel rollbackLoggingLevel = LoggingLevel.WARN;
+    @XmlAttribute
     private String logName;
     @XmlAttribute
     private Boolean useOriginalMessage;
@@ -60,5 +62,4 @@ public class ErrorHandlerDefinition exte
     @XmlElement
     private RedeliveryPolicyDefinition 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=1239045&r1=1239044&r2=1239045&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
Wed Feb  1 10:43:12 2012
@@ -102,7 +102,6 @@ public class ErrorHandlerDefinitionParse
             parserRefAttribute(element, "onRetryWhileRef", "onRetryWhile", builder);
             parserRefAttribute(element, "redeliveryPolicyRef", "redeliveryPolicy", builder);
             if (type.equals(ErrorHandlerType.TransactionErrorHandler)) {
-                // deal with transactionTemplateRef
                 parserRefAttribute(element, "transactionTemplateRef", "transactionTemplate",
builder);
                 parserRefAttribute(element, "transactionManagerRef", "transactionManager",
builder);
             }
@@ -125,6 +124,11 @@ public class ErrorHandlerDefinitionParse
             throw new IllegalArgumentException("Attribute transactionManagerRef can only
be used if type is "
                     + ErrorHandlerType.TransactionErrorHandler.name() + ", in error handler
with id: " + id);
         }
+        String rollbackLoggingLevel = element.getAttribute("rollbackLoggingLevel");
+        if (ObjectHelper.isNotEmpty(rollbackLoggingLevel) && (!type.equals(ErrorHandlerType.TransactionErrorHandler)))
{
+            throw new IllegalArgumentException("Attribute rollbackLoggingLevel can only be
used if type is "
+                    + ErrorHandlerType.TransactionErrorHandler.name() + ", in error handler
with id: " + id);
+        }
         String useOriginalMessage = element.getAttribute("useOriginalMessage");
         if (ObjectHelper.isNotEmpty(useOriginalMessage) && (type.equals(ErrorHandlerType.LoggingErrorHandler)
|| type.equals(ErrorHandlerType.NoErrorHandler))) {
             throw new IllegalArgumentException("Attribute useOriginalMessage is not supported
by error handler type: "

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java?rev=1239045&r1=1239044&r2=1239045&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
Wed Feb  1 10:43:12 2012
@@ -19,6 +19,7 @@ package org.apache.camel.spring.spi;
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
+import org.apache.camel.LoggingLevel;
 import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
 import org.apache.camel.processor.RedeliveryErrorHandler;
@@ -42,6 +43,7 @@ public class TransactionErrorHandler ext
 
     private final TransactionTemplate transactionTemplate;
     private final String transactionKey;
+    private final LoggingLevel rollbackLoggingLevel;
 
     /**
      * Creates the transaction error handler.
@@ -55,14 +57,17 @@ public class TransactionErrorHandler ext
      * @param transactionTemplate     the transaction template
      * @param retryWhile              retry while
      * @param executorServiceRef      reference to a {@link java.util.concurrent.ScheduledExecutorService}
to be used for redelivery thread pool. Can be <tt>null</tt>.
+     * @param rollbackLoggingLevel    logging level to use for logging transaction rollback
occurred
      */
     public TransactionErrorHandler(CamelContext camelContext, Processor output, CamelLogger
logger, 
             Processor redeliveryProcessor, RedeliveryPolicy redeliveryPolicy, ExceptionPolicyStrategy
exceptionPolicyStrategy,
-            TransactionTemplate transactionTemplate, Predicate retryWhile, String executorServiceRef)
{
+            TransactionTemplate transactionTemplate, Predicate retryWhile, String executorServiceRef,
+            LoggingLevel rollbackLoggingLevel) {
 
         super(camelContext, output, logger, redeliveryProcessor, redeliveryPolicy, null,
null, false, retryWhile, executorServiceRef);
         setExceptionPolicy(exceptionPolicyStrategy);
         this.transactionTemplate = transactionTemplate;
+        this.rollbackLoggingLevel = rollbackLoggingLevel;
         this.transactionKey = ObjectHelper.getIdentityHashCode(transactionTemplate);
     }
 
@@ -136,8 +141,8 @@ public class TransactionErrorHandler ext
                 log.debug("Transaction rollback ({}) redelivered({}) for {} due exchange
was marked for rollbackOnly", new Object[]{transactionKey, redelivered, ids});
             }
         } catch (Throwable e) {
-            log.warn("Transaction rollback ({}) redelivered({}) for {} caught: {}", new Object[]{transactionKey,
redelivered, ids, e.getMessage()});
             exchange.setException(e);
+            logTransactionRollback(redelivered, ids, e);
         } finally {
             // mark the end of this transaction boundary
             exchange.getUnitOfWork().endTransactedBy(transactionKey);
@@ -146,6 +151,7 @@ public class TransactionErrorHandler ext
         // if it was a local rollback only then remove its marker so outer transaction wont
see the marker
         Boolean onlyLast = (Boolean) exchange.removeProperty(Exchange.ROLLBACK_ONLY_LAST);
         if (onlyLast != null && onlyLast) {
+            // we only want this logged at debug level
             if (log.isDebugEnabled()) {
                 // log exception if there was a cause exception so we have the stack trace
                 Exception cause = exchange.getException();
@@ -222,6 +228,25 @@ public class TransactionErrorHandler ext
         });
     }
 
+    /**
+     * Logs the transaction rollback
+     */
+    private void logTransactionRollback(String redelivered, String ids, Throwable e) {
+        if (rollbackLoggingLevel == LoggingLevel.OFF) {
+            return;
+        } else if (rollbackLoggingLevel == LoggingLevel.ERROR && log.isErrorEnabled())
{
+            log.error("Transaction rollback ({}) redelivered({}) for {} caught: {}", new
Object[]{transactionKey, redelivered, ids, e.getMessage()});
+        } else if (rollbackLoggingLevel == LoggingLevel.WARN && log.isWarnEnabled())
{
+            log.warn("Transaction rollback ({}) redelivered({}) for {} caught: {}", new Object[]{transactionKey,
redelivered, ids, e.getMessage()});
+        } else if (rollbackLoggingLevel == LoggingLevel.INFO && log.isInfoEnabled())
{
+            log.info("Transaction rollback ({}) redelivered({}) for {} caught: {}", new Object[]{transactionKey,
redelivered, ids, e.getMessage()});
+        } else if (rollbackLoggingLevel == LoggingLevel.DEBUG && log.isDebugEnabled())
{
+            log.debug("Transaction rollback ({}) redelivered({}) for {} caught: {}", new
Object[]{transactionKey, redelivered, ids, e.getMessage()});
+        } else if (rollbackLoggingLevel == LoggingLevel.TRACE && log.isTraceEnabled())
{
+            log.trace("Transaction rollback ({}) redelivered({}) for {} caught: {}", new
Object[]{transactionKey, redelivered, ids, e.getMessage()});
+        }
+    }
+
     private static String propagationBehaviorToString(int propagationBehavior) {
         String rc;
         switch (propagationBehavior) {

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=1239045&r1=1239044&r2=1239045&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
Wed Feb  1 10:43:12 2012
@@ -40,6 +40,7 @@ public class TransactionErrorHandlerBuil
     private static final transient Logger LOG = LoggerFactory.getLogger(TransactionErrorHandlerBuilder.class);
     private static final String PROPAGATION_REQUIRED = "PROPAGATION_REQUIRED";
     private TransactionTemplate transactionTemplate;
+    private LoggingLevel rollbackLoggingLevel = LoggingLevel.WARN;
 
     public TransactionErrorHandlerBuilder() {
         // no-arg constructor used by Spring DSL
@@ -108,7 +109,7 @@ public class TransactionErrorHandlerBuil
 
         TransactionErrorHandler answer = new TransactionErrorHandler(routeContext.getCamelContext(),
processor,
             getLogger(), getOnRedelivery(), getRedeliveryPolicy(), getExceptionPolicyStrategy(),
transactionTemplate, 
-            getRetryWhilePolicy(routeContext.getCamelContext()), getExecutorServiceRef());
+            getRetryWhilePolicy(routeContext.getCamelContext()), getExecutorServiceRef(),
getRollbackLoggingLevel());
         // configure error handler before we can use it
         configure(routeContext, answer);
         return answer;
@@ -126,9 +127,39 @@ public class TransactionErrorHandlerBuil
         this.transactionTemplate = new TransactionTemplate(transactionManager);
     }
 
+    public LoggingLevel getRollbackLoggingLevel() {
+        return rollbackLoggingLevel;
+    }
+
+    /**
+     * Sets the logging level to use for logging transactional rollback.
+     * <p/>
+     * This option is default WARN.
+     *
+     * @param rollbackLoggingLevel the logging level
+     */
+    public void setRollbackLoggingLevel(LoggingLevel rollbackLoggingLevel) {
+        this.rollbackLoggingLevel = rollbackLoggingLevel;
+    }
+
     // Builder methods
     // -------------------------------------------------------------------------
 
+    /**
+     * Sets the logging level to use for logging transactional rollback.
+     * <p/>
+     * This option is default WARN.
+     *
+     * @param rollbackLoggingLevel the logging level
+     */
+    public TransactionErrorHandlerBuilder rollbackLoggingLevel(LoggingLevel rollbackLoggingLevel)
{
+        setRollbackLoggingLevel(rollbackLoggingLevel);
+        return this;
+    }
+
+    // Implementation
+    // -------------------------------------------------------------------------
+
     protected CamelLogger createLogger() {
         return new CamelLogger(LoggerFactory.getLogger(TransactionErrorHandler.class), LoggingLevel.ERROR);
     }



Mime
View raw message