You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2012/04/18 13:43:08 UTC

svn commit: r1327454 - in /camel/branches/camel-2.9.x: ./ camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/test/java/org/apache/camel/component/file/

Author: davsclaus
Date: Wed Apr 18 11:43:07 2012
New Revision: 1327454

URL: http://svn.apache.org/viewvc?rev=1327454&view=rev
Log:
CAMEL-5178: File consumer should use exception handler to handle all component specific exceptions. Add example how to plugin a custom exception handler and send that to a Camel route so Camel routing onException can deal with the exception. Reduce the out of the box logging exception handler to WARN level.

Added:
    camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCustomExceptionHandlerTest.java
      - copied unchanged from r1327447, camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCustomExceptionHandlerTest.java
Modified:
    camel/branches/camel-2.9.x/   (props changed)
    camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
    camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumer.java
    camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/LoggingExceptionHandler.java

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1327447

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/component/file/GenericFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java?rev=1327454&r1=1327453&r2=1327454&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java (original)
+++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java Wed Apr 18 11:43:07 2012
@@ -313,10 +313,11 @@ public abstract class GenericFileConsume
                 return;
             }
         } catch (Exception e) {
-            if (log.isDebugEnabled()) {
-                log.debug(endpoint + " cannot begin processing file: " + file + " due to: " + e.getMessage(), e);
-            }
+            // remove file from the in progress list due to failure
             endpoint.getInProgressRepository().remove(absoluteFileName);
+
+            String msg = endpoint + " cannot begin processing file: " + file + " due to: " + e.getMessage();
+            handleException(msg, e);
             return;
         }
 
@@ -364,7 +365,9 @@ public abstract class GenericFileConsume
             // from in progress when it takes over and processes the file, which may happen
             // by another thread at a later time. So its only safe to remove it if there was an exception)
             endpoint.getInProgressRepository().remove(absoluteFileName);
-            handleException(e);
+
+            String msg = "Error processing file " + file + " due to " + e.getMessage();
+            handleException(msg, e);
         }
     }
 
@@ -389,6 +392,7 @@ public abstract class GenericFileConsume
             if (log.isDebugEnabled()) {
                 log.debug(endpoint + " error custom processing: " + file + " due to: " + e.getMessage() + ". This exception will be ignored.", e);
             }
+            handleException(e);
         } finally {
             // always remove file from the in progress list as its no longer in progress
             // use the original file name that was used to add it to the repository

Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumer.java?rev=1327454&r1=1327453&r2=1327454&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumer.java (original)
+++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumer.java Wed Apr 18 11:43:07 2012
@@ -100,4 +100,15 @@ public class DefaultConsumer extends Ser
         Throwable newt = (t == null) ? new IllegalArgumentException("Handling [null] exception") : t;
         getExceptionHandler().handleException(newt);
     }
+
+    /**
+     * Handles the given exception using the {@link #getExceptionHandler()}
+     *
+     * @param message additional message about the exception
+     * @param t the exception to handle
+     */
+    protected void handleException(String message, Throwable t) {
+        Throwable newt = (t == null) ? new IllegalArgumentException("Handling [null] exception") : t;
+        getExceptionHandler().handleException(message, newt);
+    }
 }

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=1327454&r1=1327453&r2=1327454&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 Wed Apr 18 11:43:07 2012
@@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory;
  * A default implementation of {@link ExceptionHandler} which uses a {@link org.apache.camel.processor.CamelLogger} to
  * log the exception.
  * <p/>
- * This implementation will by default log the exception with stack trace at ERROR level.
+ * This implementation will by default log the exception with stack trace at WARN level.
  *
  * @version 
  */
@@ -36,7 +36,7 @@ public class LoggingExceptionHandler imp
     private final CamelLogger logger;
 
     public LoggingExceptionHandler(Class<?> ownerType) {
-        this(new CamelLogger(LoggerFactory.getLogger(ownerType), LoggingLevel.ERROR));
+        this(new CamelLogger(LoggerFactory.getLogger(ownerType), LoggingLevel.WARN));
     }
 
     public LoggingExceptionHandler(Class<?> ownerType, LoggingLevel level) {
@@ -59,7 +59,7 @@ public class LoggingExceptionHandler imp
         try {
             String msg = CamelExchangeException.createExceptionMessage(message, exchange, exception);
             if (isCausedByRollbackExchangeException(exception)) {
-                // do not log stacktrace for intended rollbacks
+                // do not log stack trace for intended rollbacks
                 logger.log(msg);
             } else {
                 if (exception != null) {