camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r906417 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/processor/ test/java/org/apache/camel/processor/ test/java/org/apache/camel/processor/aggregator/
Date Thu, 04 Feb 2010 09:37:06 GMT
Author: davsclaus
Date: Thu Feb  4 09:37:06 2010
New Revision: 906417

URL: http://svn.apache.org/viewvc?rev=906417&view=rev
Log:
CAMEL-2448: Camel error handler now catches all exceptions (eg Throwable) instead of just
Exception.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelCatchThrowableTest.java
  (contents, props changed)
      - copied, changed from r906367, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorExceptionTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerCatchThrowableTest.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorExceptionTest.java

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=906417&r1=906416&r2=906417&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
Thu Feb  4 09:37:06 2010
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.processor;
 
+import org.apache.camel.CamelExchangeException;
 import org.apache.camel.Exchange;
 import org.apache.camel.LoggingLevel;
 import org.apache.camel.Message;
@@ -142,6 +143,9 @@
                 processExchange(exchange);
             } catch (Exception e) {
                 exchange.setException(e);
+            } catch (Throwable t) {
+                // let Camel error handle take care of all kind of exceptions now
+                exchange.setException(new CamelExchangeException("Error processing Exchange",
exchange, t));
             }
 
             boolean done = isDone(exchange);
@@ -163,7 +167,7 @@
     }
 
     /**
-     * Strategy to process the given exchange to the destinated output.
+     * Strategy to process the given exchange to the designated output.
      * <p/>
      * This happens when the exchange is processed the first time and also for redeliveries
      * to the same destination.

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelCatchThrowableTest.java
(from r906367, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorExceptionTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelCatchThrowableTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelCatchThrowableTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorExceptionTest.java&r1=906367&r2=906417&rev=906417&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorExceptionTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelCatchThrowableTest.java
Thu Feb  4 09:37:06 2010
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.processor.aggregator;
+package org.apache.camel.processor;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
@@ -22,17 +22,14 @@
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 
-public class AggregatorExceptionTest extends ContextTestSupport {
+public class DeadLetterChannelCatchThrowableTest extends ContextTestSupport {
 
-    public void testAggregateAndOnException() throws Exception {
+    public void testDeadLetterChannelCatchThrowable() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:error");
+        mock.expectedMessageCount(1);
 
-        // can change this to 5 when BatchProcessor's exception handling works properly
-        mock.expectedMessageCount(0);
+        template.sendBody("direct:start", "Hello World");
 
-        for (int c = 0; c <= 10; c++) {
-            template.sendBodyAndHeader("seda:start", "Hi!", "id", 123);
-        }
         assertMockEndpointsSatisfied();
     }
 
@@ -41,21 +38,16 @@
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-
                 final String exceptionString = "This is an Error not an Exception";
+                errorHandler(deadLetterChannel("mock:error"));
 
-                //errorHandler(deadLetterChannel("mock:error"));
-                onException(Throwable.class).handled(true).to("mock:error");
-
-                from("seda:start")
-                    .aggregate(header("id"))
-                    .batchSize(2)
+                from("direct:start")
                     .process(new Processor() {
                         public void process(Exchange exchange) throws Exception {
-                            throw new java.lang.NoSuchMethodError(exceptionString);   
+                            throw new NoSuchMethodError(exceptionString);
                         }
                     });
             }
         };
     }
-}
+}
\ No newline at end of file

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelCatchThrowableTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelCatchThrowableTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerCatchThrowableTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerCatchThrowableTest.java?rev=906417&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerCatchThrowableTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerCatchThrowableTest.java
Thu Feb  4 09:37:06 2010
@@ -0,0 +1,55 @@
+/**
+ * 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;
+
+import org.apache.camel.CamelExchangeException;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+
+public class DefaultErrorHandlerCatchThrowableTest extends ContextTestSupport {
+
+    public void testDefaultErrorHandlerCatchThrowable() throws Exception {
+        try {
+            template.sendBody("direct:start", "Hello World");
+            fail("Should have thrown exception");
+        } catch (CamelExecutionException e) {
+            CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class,
e.getCause());
+            assertEquals("Hello World", cause.getExchange().getIn().getBody());
+            assertIsInstanceOf(NoSuchMethodError.class, cause.getCause());
+        }
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                final String exceptionString = "This is an Error not an Exception";
+
+                from("direct:start")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            throw new NoSuchMethodError(exceptionString);
+                        }
+                    });
+            }
+        };
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerCatchThrowableTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerCatchThrowableTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorExceptionTest.java?rev=906417&r1=906416&r2=906417&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorExceptionTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorExceptionTest.java
Thu Feb  4 09:37:06 2010
@@ -25,14 +25,14 @@
 public class AggregatorExceptionTest extends ContextTestSupport {
 
     public void testAggregateAndOnException() throws Exception {
+        // all goes to error
         MockEndpoint mock = getMockEndpoint("mock:error");
-
-        // can change this to 5 when BatchProcessor's exception handling works properly
-        mock.expectedMessageCount(0);
+        mock.expectedMessageCount(2);
 
         for (int c = 0; c <= 10; c++) {
-            template.sendBodyAndHeader("seda:start", "Hi!", "id", 123);
+            template.sendBodyAndHeader("direct:start", "Hi!" + c, "id", 123);
         }
+
         assertMockEndpointsSatisfied();
     }
 
@@ -41,15 +41,12 @@
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-
                 final String exceptionString = "This is an Error not an Exception";
+                errorHandler(deadLetterChannel("mock:error"));
 
-                //errorHandler(deadLetterChannel("mock:error"));
-                onException(Throwable.class).handled(true).to("mock:error");
-
-                from("seda:start")
+                from("direct:start")
                     .aggregate(header("id"))
-                    .batchSize(2)
+                    .batchSize(5)
                     .process(new Processor() {
                         public void process(Exchange exchange) throws Exception {
                             throw new java.lang.NoSuchMethodError(exceptionString);   



Mime
View raw message