camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1238239 - in /camel/branches/camel-2.9.x: ./ camel-core/src/main/java/org/apache/camel/impl/ components/camel-jaxb/ components/camel-jaxb/src/test/ components/camel-jms/ components/camel-jms/src/main/java/org/apache/camel/component/jms/ co...
Date Tue, 31 Jan 2012 08:20:24 GMT
Author: davsclaus
Date: Tue Jan 31 08:20:23 2012
New Revision: 1238239

URL: http://svn.apache.org/viewvc?rev=1238239&view=rev
Log:
CAMEL-4958: Added spring errorHandler to JMS listener, to avoid Spring complaining, and allow
to configure logging levels to tune verbosity.

Added:
    camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultSpringErrorHandler.java
      - copied unchanged from r1238225, camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultSpringErrorHandler.java
    camel/branches/camel-2.9.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionRollbackTest.java
      - copied unchanged from r1238225, camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionRollbackTest.java
    camel/branches/camel-2.9.x/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionRollbackTest.xml
      - copied unchanged from r1238225, camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionRollbackTest.xml
Modified:
    camel/branches/camel-2.9.x/   (props changed)
    camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/LoggingExceptionHandler.java
    camel/branches/camel-2.9.x/components/camel-jaxb/   (props changed)
    camel/branches/camel-2.9.x/components/camel-jaxb/src/test/   (props changed)
    camel/branches/camel-2.9.x/components/camel-jms/   (props changed)
    camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
    camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
    camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
    camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
    camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/PersistentQueueReplyManager.java
    camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/TemporaryQueueReplyManager.java
    camel/branches/camel-2.9.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionErrorHandlerTest.java
    camel/branches/camel-2.9.x/components/camel-jms/src/test/resources/log4j.properties

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan 31 08:20:23 2012
@@ -1 +1 @@
-/camel/trunk:1235643,1236639,1236667,1237666,1237807
+/camel/trunk:1235643,1236639,1236667,1237666,1237807,1238225

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/LoggingExceptionHandler.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/LoggingExceptionHandler.java?rev=1238239&r1=1238238&r2=1238239&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/LoggingExceptionHandler.java
(original)
+++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/LoggingExceptionHandler.java
Tue Jan 31 08:20:23 2012
@@ -62,7 +62,11 @@ public class LoggingExceptionHandler imp
                 // do not log stacktrace for intended rollbacks
                 logger.log(msg);
             } else {
-                logger.log(msg, exception);
+                if (exception != null) {
+                    logger.log(msg, exception);
+                } else {
+                    logger.log(msg);
+                }
             }
         } catch (Throwable e) {
             // the logging exception handler must not cause new exceptions to occur
@@ -70,6 +74,9 @@ public class LoggingExceptionHandler imp
     }
 
     protected boolean isCausedByRollbackExchangeException(Throwable exception) {
+        if (exception == null) {
+            return false;
+        }
         if (exception instanceof RollbackExchangeException) {
             return true;
         } else if (exception.getCause() != null) {

Propchange: camel/branches/camel-2.9.x/components/camel-jaxb/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan 31 08:20:23 2012
@@ -1 +1 @@
-/camel/trunk/components/camel-jaxb:1235643,1236403-1236663,1236667,1237148,1237666,1237807
+/camel/trunk/components/camel-jaxb:1235643,1236403-1236663,1236667,1237148,1237666,1237807,1238225

Propchange: camel/branches/camel-2.9.x/components/camel-jaxb/src/test/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan 31 08:20:23 2012
@@ -1 +1 @@
-/camel/trunk/components/camel-jaxb/src/test:1235643,1236403-1236663,1236667,1237148,1237230,1237666,1237807
+/camel/trunk/components/camel-jaxb/src/test:1235643,1236403-1236663,1236667,1237148,1237230,1237666,1237807,1238225

Propchange: camel/branches/camel-2.9.x/components/camel-jms/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan 31 08:20:23 2012
@@ -1 +1 @@
-/camel/trunk/components/camel-jms:1235643,1236639,1236667,1237666,1237807,1238060
+/camel/trunk/components/camel-jms:1235643,1236639,1236667,1237666,1237807,1238060,1238225

Modified: camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java?rev=1238239&r1=1238238&r2=1238239&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
Tue Jan 31 08:20:23 2012
@@ -29,7 +29,6 @@ import org.apache.camel.ExchangePattern;
 import org.apache.camel.Processor;
 import org.apache.camel.RollbackExchangeException;
 import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.impl.LoggingExceptionHandler;
 import org.apache.camel.spi.ExceptionHandler;
 import org.apache.camel.util.AsyncProcessorConverterHelper;
 import org.apache.camel.util.AsyncProcessorHelper;
@@ -125,9 +124,12 @@ public class EndpointMessageListener imp
         }
 
         // an exception occurred so rethrow to trigger rollback on JMS listener
+        // the JMS listener will use the error handler to handle the uncaught exception
         if (rce != null) {
-            handleException(rce);
             LOG.trace("onMessage END throwing exception: {}", rce.getMessage());
+            // Spring message listener container will handle uncaught exceptions
+            // being thrown from this onMessage, and will us the ErrorHandler configured
+            // on the JmsEndpoint to handle the exception
             throw rce;
         }
 
@@ -213,8 +215,10 @@ public class EndpointMessageListener imp
                     // method and rethrow it
                     exchange.setException(rce);
                 } else {
-                    // we were done async, so use the Camel built in exception handler to
deal with it
-                    handleException(rce);
+                    // we were done async, so use the endpoint error handler
+                    if (endpoint.getErrorHandler() != null) {
+                        endpoint.getErrorHandler().handleError(rce);
+                    }
                 }
             }
         }
@@ -256,9 +260,6 @@ public class EndpointMessageListener imp
     }
 
     public ExceptionHandler getExceptionHandler() {
-        if (exceptionHandler == null) {
-            exceptionHandler = new LoggingExceptionHandler(getClass());
-        }
         return exceptionHandler;
     }
 
@@ -398,15 +399,6 @@ public class EndpointMessageListener imp
         return destination;
     }
 
-    /**
-     * Handles the given exception using the {@link #getExceptionHandler()}
-     *
-     * @param t the exception to handle
-     */
-    protected void handleException(Throwable t) {
-        getExceptionHandler().handleException(t);
-    }
-
     @Override
     public String toString() {
         return "EndpointMessageListener[" + endpoint + "]";

Modified: camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java?rev=1238239&r1=1238238&r2=1238239&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
Tue Jan 31 08:20:23 2012
@@ -23,6 +23,7 @@ import javax.jms.Session;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
+import org.apache.camel.LoggingLevel;
 import org.apache.camel.impl.DefaultComponent;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.spi.HeaderFilterStrategyAware;
@@ -210,8 +211,16 @@ public class JmsComponent extends Defaul
 
     public void setErrorHandler(ErrorHandler errorHandler) {
         getConfiguration().setErrorHandler(errorHandler);
-    }    
-    
+    }
+
+    public void setErrorHandlerLoggingLevel(LoggingLevel errorHandlerLoggingLevel) {
+        getConfiguration().setErrorHandlerLoggingLevel(errorHandlerLoggingLevel);
+    }
+
+    public void setErrorHandlerLogStackTrace(boolean errorHandlerLogStackTrace) {
+        getConfiguration().setErrorHandlerLogStackTrace(errorHandlerLogStackTrace);
+    }
+
     public void setExplicitQosEnabled(boolean explicitQosEnabled) {
         getConfiguration().setExplicitQosEnabled(explicitQosEnabled);
     }

Modified: camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java?rev=1238239&r1=1238238&r2=1238239&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
Tue Jan 31 08:20:23 2012
@@ -24,6 +24,7 @@ import javax.jms.Message;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
 
+import org.apache.camel.LoggingLevel;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
@@ -68,7 +69,9 @@ public class JmsConfiguration implements
     // Used to configure the spring Container
     private ExceptionListener exceptionListener;
     private ConsumerType consumerType = ConsumerType.Default;
-    private ErrorHandler errorHandler;    
+    private ErrorHandler errorHandler;
+    private LoggingLevel errorHandlerLoggingLevel = LoggingLevel.WARN;
+    private boolean errorHandlerLogStackTrace = true;
     private boolean autoStartup = true;
     private boolean acceptMessagesWhileStopping;
     private String clientId;
@@ -494,7 +497,23 @@ public class JmsConfiguration implements
     public ErrorHandler getErrorHandler() {
         return errorHandler;
     }
-    
+
+    public LoggingLevel getErrorHandlerLoggingLevel() {
+        return errorHandlerLoggingLevel;
+    }
+
+    public void setErrorHandlerLoggingLevel(LoggingLevel errorHandlerLoggingLevel) {
+        this.errorHandlerLoggingLevel = errorHandlerLoggingLevel;
+    }
+
+    public boolean isErrorHandlerLogStackTrace() {
+        return errorHandlerLogStackTrace;
+    }
+
+    public void setErrorHandlerLogStackTrace(boolean errorHandlerLogStackTrace) {
+        this.errorHandlerLogStackTrace = errorHandlerLogStackTrace;
+    }
+
     @Deprecated
     public boolean isSubscriptionDurable() {
         return subscriptionDurable;
@@ -876,6 +895,9 @@ public class JmsConfiguration implements
 
         if (errorHandler != null) {
             container.setErrorHandler(errorHandler);
+        } else {
+            ErrorHandler handler = new DefaultSpringErrorHandler(EndpointMessageListener.class,
getErrorHandlerLoggingLevel(), isErrorHandlerLogStackTrace());
+            container.setErrorHandler(handler);
         }
 
         container.setAcceptMessagesWhileStopping(acceptMessagesWhileStopping);

Modified: camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java?rev=1238239&r1=1238238&r2=1238239&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
Tue Jan 31 08:20:23 2012
@@ -34,6 +34,7 @@ import javax.jms.Topic;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
+import org.apache.camel.LoggingLevel;
 import org.apache.camel.MultipleConsumersSupport;
 import org.apache.camel.PollingConsumer;
 import org.apache.camel.Processor;
@@ -548,8 +549,23 @@ public class JmsEndpoint extends Default
     public ErrorHandler getErrorHandler() {
         return getConfiguration().getErrorHandler();
     }
+
+    @ManagedAttribute
+    public LoggingLevel getErrorHandlerLoggingLevel() {
+        return getConfiguration().getErrorHandlerLoggingLevel();
+    }
     
     @ManagedAttribute
+    public boolean isErrorHandlerLogStackTrace() {
+        return getConfiguration().isErrorHandlerLogStackTrace();
+    }
+
+    @ManagedAttribute
+    public void setErrorHandlerLogStackTrace(boolean errorHandlerLogStackTrace) {
+        getConfiguration().setErrorHandlerLogStackTrace(errorHandlerLogStackTrace);
+    }
+
+    @ManagedAttribute
     public int getIdleTaskExecutionLimit() {
         return getConfiguration().getIdleTaskExecutionLimit();
     }

Modified: camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/PersistentQueueReplyManager.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/PersistentQueueReplyManager.java?rev=1238239&r1=1238238&r2=1238239&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/PersistentQueueReplyManager.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/PersistentQueueReplyManager.java
Tue Jan 31 08:20:23 2012
@@ -25,6 +25,7 @@ import javax.jms.Session;
 
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.Exchange;
+import org.apache.camel.component.jms.DefaultSpringErrorHandler;
 import org.apache.camel.component.jms.ReplyToType;
 import org.springframework.jms.listener.AbstractMessageListenerContainer;
 import org.springframework.jms.listener.DefaultMessageListenerContainer;
@@ -184,6 +185,8 @@ public class PersistentQueueReplyManager
         }
         if (endpoint.getErrorHandler() != null) {
             answer.setErrorHandler(endpoint.getErrorHandler());
+        } else {
+            answer.setErrorHandler(new DefaultSpringErrorHandler(PersistentQueueReplyManager.class,
endpoint.getErrorHandlerLoggingLevel(), endpoint.isErrorHandlerLogStackTrace()));
         }
         if (endpoint.getReceiveTimeout() >= 0) {
             answer.setReceiveTimeout(endpoint.getReceiveTimeout());

Modified: camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/TemporaryQueueReplyManager.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/TemporaryQueueReplyManager.java?rev=1238239&r1=1238238&r2=1238239&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/TemporaryQueueReplyManager.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/TemporaryQueueReplyManager.java
Tue Jan 31 08:20:23 2012
@@ -24,6 +24,7 @@ import javax.jms.TemporaryQueue;
 
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.Exchange;
+import org.apache.camel.component.jms.DefaultSpringErrorHandler;
 import org.springframework.jms.listener.AbstractMessageListenerContainer;
 import org.springframework.jms.listener.DefaultMessageListenerContainer;
 import org.springframework.jms.support.destination.DestinationResolver;
@@ -113,7 +114,9 @@ public class TemporaryQueueReplyManager 
         }
         if (endpoint.getErrorHandler() != null) {
             answer.setErrorHandler(endpoint.getErrorHandler());
-        }        
+        } else {
+            answer.setErrorHandler(new DefaultSpringErrorHandler(TemporaryQueueReplyManager.class,
endpoint.getErrorHandlerLoggingLevel(), endpoint.isErrorHandlerLogStackTrace()));
+        }
         if (endpoint.getReceiveTimeout() >= 0) {
             answer.setReceiveTimeout(endpoint.getReceiveTimeout());
         }

Modified: camel/branches/camel-2.9.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionErrorHandlerTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionErrorHandlerTest.java?rev=1238239&r1=1238238&r2=1238239&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionErrorHandlerTest.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionErrorHandlerTest.java
Tue Jan 31 08:20:23 2012
@@ -44,7 +44,7 @@ public class JMSTransactionErrorHandlerT
         mock.expectedBodiesReceived("Bye World");
         // success at 3rd attempt
         mock.message(0).header("count").isEqualTo(3);
-        // and since it was Camel doing the redelivey we should have headers for this
+        // and since it was Camel doing the redelivery we should have headers for this
         mock.message(0).header(Exchange.REDELIVERED).isEqualTo(true);
         mock.message(0).header(Exchange.REDELIVERY_COUNTER).isEqualTo(2);
         // and not JMS doing the redelivery

Modified: camel/branches/camel-2.9.x/components/camel-jms/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-jms/src/test/resources/log4j.properties?rev=1238239&r1=1238238&r2=1238239&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-jms/src/test/resources/log4j.properties (original)
+++ camel/branches/camel-2.9.x/components/camel-jms/src/test/resources/log4j.properties Tue
Jan 31 08:20:23 2012
@@ -16,10 +16,17 @@
 ## ---------------------------------------------------------------------------
 
 #
-# The logging properties used during tests..
+# The logging properties used
 #
 log4j.rootLogger=INFO, out
 
+#log4j.logger.org.apache.activemq.spring=WARN
+#log4j.logger.org.apache.camel.component.jms=TRACE
+#log4j.logger.org.apache.camel.component.jms.reply.CorrelationMap=DEBUG
+#log4j.logger.org.apache.camel.component.jms.reply=TRACE
+#log4j.logger.org.apache.camel=DEBUG
+#log4j.logger.org.springframework.jms.listener=TRACE
+
 # CONSOLE appender not used by default
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
@@ -32,12 +39,3 @@ log4j.appender.out.layout.ConversionPatt
 log4j.appender.out.file=target/camel-jms-test.log
 log4j.appender.out.append=true
 
-log4j.logger.org.apache.camel.impl.converter=WARN
-log4j.logger.org.apache.camel.management=WARN
-log4j.logger.org.apache.camel.impl.DefaultPackageScanClassResolver=WARN
-#log4j.logger.org.apache.activemq.spring=WARN
-#log4j.logger.org.apache.camel.component.jms=TRACE
-#log4j.logger.org.apache.camel.component.jms.reply.CorrelationMap=DEBUG
-#log4j.logger.org.apache.camel.component.jms.reply=TRACE
-#log4j.logger.org.apache.camel=DEBUG
-#log4j.logger.org.springframework.jms.listener=TRACE



Mime
View raw message