camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r984390 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ main/java/org/apache/camel/processor/ test/java/org/apache/camel/impl/ test/java/org/apache/camel/processor/onexception/
Date Wed, 11 Aug 2010 12:27:35 GMT
Author: davsclaus
Date: Wed Aug 11 12:27:35 2010
New Revision: 984390

URL: http://svn.apache.org/viewvc?rev=984390&view=rev
Log:
CAMEL-3044: Fixed logging error handler interferring with onException.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/LoggingErrorHandlerOnExceptionTest.java
Removed:
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ShutdownRouteGracefulWithTimerTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/LoggingErrorHandlerBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/LoggingErrorHandler.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/LoggingErrorHandlerBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/LoggingErrorHandlerBuilder.java?rev=984390&r1=984389&r2=984390&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/LoggingErrorHandlerBuilder.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/LoggingErrorHandlerBuilder.java
Wed Aug 11 12:27:35 2010
@@ -50,7 +50,9 @@ public class LoggingErrorHandlerBuilder 
     }
 
     public Processor createErrorHandler(final RouteContext routeContext, final Processor
processor) {
-        LoggingErrorHandler handler = new LoggingErrorHandler(processor, log, level);
+        Logger logger = new Logger(log, level);
+
+        LoggingErrorHandler handler = new LoggingErrorHandler(routeContext.getCamelContext(),
processor, logger, getExceptionPolicyStrategy());
         configure(handler);
         return handler;
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/LoggingErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/LoggingErrorHandler.java?rev=984390&r1=984389&r2=984390&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/LoggingErrorHandler.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/LoggingErrorHandler.java
Wed Aug 11 12:27:35 2010
@@ -16,31 +16,27 @@
  */
 package org.apache.camel.processor;
 
-import org.apache.camel.Exchange;
-import org.apache.camel.LoggingLevel;
+import org.apache.camel.CamelContext;
 import org.apache.camel.Processor;
-import org.apache.camel.util.ServiceHelper;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.camel.processor.exceptionpolicy.ExceptionPolicyStrategy;
 
 /**
  * An {@link ErrorHandler} which uses commons-logging to dump the error
  *
  * @version $Revision$
  */
-public class LoggingErrorHandler extends ErrorHandlerSupport {
-    private Processor output;
-    private Log log;
-    private LoggingLevel level;
+public class LoggingErrorHandler extends DefaultErrorHandler {
 
-    public LoggingErrorHandler(Processor output) {
-        this(output, LogFactory.getLog(LoggingErrorHandler.class), LoggingLevel.INFO);
-    }
-
-    public LoggingErrorHandler(Processor output, Log log, LoggingLevel level) {
-        this.output = output;
-        this.log = log;
-        this.level = level;
+    /**
+     * Creates the logging error handler.
+     *
+     * @param camelContext            the camel context
+     * @param output                  outer processor that should use this logging error
handler
+     * @param logger                  logger to use for logging failures
+     * @param exceptionPolicyStrategy strategy for onException handling
+     */
+    public LoggingErrorHandler(CamelContext camelContext, Processor output, Logger logger,
ExceptionPolicyStrategy exceptionPolicyStrategy) {
+        super(camelContext, output, logger, null, new RedeliveryPolicy(), null, exceptionPolicyStrategy);
     }
 
     @Override
@@ -48,106 +44,4 @@ public class LoggingErrorHandler extends
         return "LoggingErrorHandler[" + output + "]";
     }
 
-    public boolean supportTransacted() {
-        return false;
-    }
-
-    public void process(Exchange exchange) throws Exception {
-        Throwable error = null;
-        try {
-            output.process(exchange);
-
-            // could also fail and set exception on the exchange itself
-            if (exchange.getException() != null) {
-                error = exchange.getException();
-            }
-        } catch (Exception e) {
-            error = e;
-        }
-
-        if (error != null) {
-            if (!customProcessorForException(exchange, error)) {
-                logError(exchange, error);
-            }
-        }
-    }
-
-    // Properties
-    // -------------------------------------------------------------------------
-
-    /**
-     * Returns the output processor
-     */
-    public Processor getOutput() {
-        return output;
-    }
-
-    public LoggingLevel getLevel() {
-        return level;
-    }
-
-    public void setLevel(LoggingLevel level) {
-        this.level = level;
-    }
-
-    public Log getLog() {
-        return log;
-    }
-
-    public void setLog(Log log) {
-        this.log = log;
-    }
-
-    // Implementation methods
-    // -------------------------------------------------------------------------
-    protected void logError(Exchange exchange, Throwable e) {
-        switch (level) {
-        case DEBUG:
-            if (log.isDebugEnabled()) {
-                log.debug(logMessage(exchange, e), e);
-            }
-            break;
-        case ERROR:
-            if (log.isErrorEnabled()) {
-                log.error(logMessage(exchange, e), e);
-            }
-            break;
-        case FATAL:
-            if (log.isFatalEnabled()) {
-                log.fatal(logMessage(exchange, e), e);
-            }
-            break;
-        case INFO:
-            if (log.isInfoEnabled()) {
-                log.info(logMessage(exchange, e), e);
-            }
-            break;
-        case TRACE:
-            if (log.isTraceEnabled()) {
-                log.trace(logMessage(exchange, e), e);
-            }
-            break;
-        case WARN:
-            if (log.isWarnEnabled()) {
-                log.warn(logMessage(exchange, e), e);
-            }
-            break;
-        case OFF:
-            break;
-        default:
-            log.error("Unknown level: " + level + " when trying to log exchange: " + logMessage(exchange,
e), e);
-        }
-    }
-
-    protected Object logMessage(Exchange exchange, Throwable e) {
-        return e.getMessage() + " while processing exchange: " + exchange;
-    }
-
-    protected void doStart() throws Exception {
-        ServiceHelper.startServices(output);
-    }
-
-    protected void doStop() throws Exception {
-        ServiceHelper.stopServices(output);
-    }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java?rev=984390&r1=984389&r2=984390&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
Wed Aug 11 12:27:35 2010
@@ -35,6 +35,7 @@ import org.apache.camel.util.AsyncProces
 import org.apache.camel.util.EventHelper;
 import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.MessageHelper;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ServiceHelper;
 
 /**
@@ -174,6 +175,9 @@ public abstract class RedeliveryErrorHan
     public RedeliveryErrorHandler(CamelContext camelContext, Processor output, Logger logger,
Processor redeliveryProcessor,
                                   RedeliveryPolicy redeliveryPolicy, Predicate handledPolicy,
Processor deadLetter,
                                   String deadLetterUri, boolean useOriginalMessagePolicy)
{
+        ObjectHelper.notNull(camelContext, "CamelContext", this);
+        ObjectHelper.notNull(redeliveryPolicy, "RedeliveryPolicy", this);
+
         this.camelContext = camelContext;
         this.redeliveryProcessor = redeliveryProcessor;
         this.deadLetter = deadLetter;

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/LoggingErrorHandlerOnExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/LoggingErrorHandlerOnExceptionTest.java?rev=984390&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/LoggingErrorHandlerOnExceptionTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/LoggingErrorHandlerOnExceptionTest.java
Wed Aug 11 12:27:35 2010
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor.onexception;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class LoggingErrorHandlerOnExceptionTest extends ContextTestSupport {
+
+    public void testLoggingErrorHandler() throws Exception {
+        getMockEndpoint("mock:handled").expectedMessageCount(0);
+
+        try {
+            template.sendBody("direct:kaboom", "Hello World");
+            fail("Should have thrown an exception");
+        } catch (CamelExecutionException e) {
+            assertEquals("Kaboom", e.getCause().getMessage());
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testLoggingErrorHandlerOnException() throws Exception {
+        getMockEndpoint("mock:handled").expectedMessageCount(1);
+
+        template.sendBody("direct:damn", "Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.setTracing(true);
+
+                errorHandler(loggingErrorHandler("org.apache.camel.MyLogger"));
+
+                onException(IllegalArgumentException.class)
+                    .handled(true)
+                    .to("mock:handled");
+
+                from("direct:kaboom").to("log:kaboom").throwException(new Exception("Kaboom"));
+                from("direct:damn").to("log:damn").throwException(new IllegalArgumentException("Damn"));
+            }
+        };
+    }
+}



Mime
View raw message