camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r791456 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/processor/ camel-core/src/test/java/org/apache/camel/processor/ camel-core/src/test/java/org/apache/camel/processor/async/ components/camel-spring/src/test/java/org/apache...
Date Mon, 06 Jul 2009 12:13:34 GMT
Author: davsclaus
Date: Mon Jul  6 12:13:33 2009
New Revision: 791456

URL: http://svn.apache.org/viewvc?rev=791456&view=rev
Log:
CAMEL-1803: error handler when handled exception should clear traces of redeliver headers.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ErrorHandlerOnExceptionRedeliveryAndHandledTest.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/DeadLetterChannelRedeliveryTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDeadLetterChannelTest.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DeadLetterChannelRedeliveryConfigTest.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=791456&r1=791455&r2=791456&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
Mon Jul  6 12:13:33 2009
@@ -295,9 +295,16 @@
         // clear exception as we let the failure processor handle it
         exchange.setException(null);
 
-        // must decrement the redelivery counter as we didn't process the redelivery but
is
-        // handling by the failure handler. So we must -1 to not let the counter be out-of-sync
-        decrementRedeliveryCounter(exchange);
+        if (data.handledPredicate != null && data.handledPredicate.matches(exchange))
{
+            // its handled then remove traces of redelivery attempted
+            exchange.getIn().removeHeader(Exchange.REDELIVERED);
+            exchange.getIn().removeHeader(Exchange.REDELIVERY_COUNTER);
+        } else {
+            // must decrement the redelivery counter as we didn't process the redelivery
but is
+            // handling by the failure handler. So we must -1 to not let the counter be out-of-sync
+            decrementRedeliveryCounter(exchange);
+        }
+
         // reset cached streams so they can be read again
         MessageHelper.resetStreamCache(exchange.getIn());
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliveryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliveryTest.java?rev=791456&r1=791455&r2=791456&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliveryTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliveryTest.java
Mon Jul  6 12:13:33 2009
@@ -94,8 +94,11 @@
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
+                // we use handled(false) to instruct DLC to not handle the exception and
therefore
+                // we can assert the number of redeliver attempts to see if that works correct
+
                 from("direct:start")
-                    .errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(2).redeliverDelay(0))
+                    .errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(2).redeliverDelay(0).handled(false))
                     .process(new Processor() {
                         public void process(Exchange exchange) throws Exception {
                             counter++;
@@ -104,7 +107,7 @@
                     });
 
                 from("direct:no")
-                    .errorHandler(deadLetterChannel("mock:no").maximumRedeliveries(0))
+                    .errorHandler(deadLetterChannel("mock:no").maximumRedeliveries(0).handled(false))
                     .process(new Processor() {
                         public void process(Exchange exchange) throws Exception {
                             counter++;
@@ -113,7 +116,7 @@
                     });
 
                 from("direct:one")
-                    .errorHandler(deadLetterChannel("mock:one").maximumRedeliveries(1).redeliverDelay(0))
+                    .errorHandler(deadLetterChannel("mock:one").maximumRedeliveries(1).redeliverDelay(0).handled(false))
                     .process(new Processor() {
                         public void process(Exchange exchange) throws Exception {
                             counter++;

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.java?rev=791456&r1=791455&r2=791456&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.java
Mon Jul  6 12:13:33 2009
@@ -50,8 +50,9 @@
         failUntilAttempt = 5;
 
         deadEndpoint.expectedBodiesReceived(body);
-        deadEndpoint.message(0).header(Exchange.REDELIVERED).isEqualTo(true);
-        deadEndpoint.message(0).header(Exchange.REDELIVERY_COUNTER).isEqualTo(2);
+        // no traces of redelivery as the dead letter channel will handle the exception when
moving the DLQ
+        deadEndpoint.message(0).header(Exchange.REDELIVERED).isNull();
+        deadEndpoint.message(0).header(Exchange.REDELIVERY_COUNTER).isNull();
         successEndpoint.expectedMessageCount(0);
 
         sendBody("direct:start", body);

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ErrorHandlerOnExceptionRedeliveryAndHandledTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ErrorHandlerOnExceptionRedeliveryAndHandledTest.java?rev=791456&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ErrorHandlerOnExceptionRedeliveryAndHandledTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ErrorHandlerOnExceptionRedeliveryAndHandledTest.java
Mon Jul  6 12:13:33 2009
@@ -0,0 +1,84 @@
+/**
+ * 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 java.io.IOException;
+import java.net.ConnectException;
+
+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;
+
+/**
+ * @version $Revision$
+ */
+public class ErrorHandlerOnExceptionRedeliveryAndHandledTest extends ContextTestSupport {
+
+    private static String counter = "";
+
+    public void testRedeliveryCounterIsResetWhenHandled() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+        getMockEndpoint("mock:other").expectedMessageCount(0);
+
+        try {
+            template.sendBody("direct:start", "Hello World");
+            fail("Should throw an exception");
+        } catch (CamelExecutionException e) {
+            assertIsInstanceOf(ConnectException.class, e.getCause());
+        }
+
+        assertMockEndpointsSatisfied();
+
+        assertEquals("12312345", counter);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                errorHandler(defaultErrorHandler().maximumRedeliveries(5).redeliverDelay(0));
+
+                onException(IOException.class).maximumRedeliveries(3).handled(true)
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            if (exchange.getIn().getHeader(Exchange.REDELIVERED) != null)
{
+                                String s = exchange.getIn().getHeader(Exchange.REDELIVERY_COUNTER,
String.class);
+                                counter += s;
+                            }
+                            throw new ConnectException("Cannot connect to bar server");
+                        }
+                    })
+                    .to("mock:other");
+
+                from("direct:start")
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                if (exchange.getIn().getHeader(Exchange.REDELIVERED) != null)
{
+                                    String s = exchange.getIn().getHeader(Exchange.REDELIVERY_COUNTER,
String.class);
+                                    counter += s;
+                                }
+                                throw new ConnectException("Cannot connect to foo server");
+                            }
+                        })
+                    .to("mock:result");
+            }
+        };
+    }
+}

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

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

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDeadLetterChannelTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDeadLetterChannelTest.java?rev=791456&r1=791455&r2=791456&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDeadLetterChannelTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDeadLetterChannelTest.java
Mon Jul  6 12:13:33 2009
@@ -94,8 +94,9 @@
 
         MockEndpoint mock = getMockEndpoint("mock:dead");
         mock.expectedMessageCount(1);
-        mock.message(0).header(Exchange.REDELIVERED).isEqualTo(Boolean.TRUE);
-        mock.message(0).header(Exchange.REDELIVERY_COUNTER).isEqualTo(2);
+        // no traces of redelivery as the dead letter channel will handle the exception when
moving the DLQ
+        mock.message(0).header(Exchange.REDELIVERED).isNull();
+        mock.message(0).header(Exchange.REDELIVERY_COUNTER).isNull();
 
         template.requestBody("direct:in", "Hello World");
 

Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DeadLetterChannelRedeliveryConfigTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DeadLetterChannelRedeliveryConfigTest.java?rev=791456&r1=791455&r2=791456&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DeadLetterChannelRedeliveryConfigTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DeadLetterChannelRedeliveryConfigTest.java
Mon Jul  6 12:13:33 2009
@@ -41,8 +41,9 @@
         MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
 
         dead.expectedBodiesReceived("Hello World");
-        dead.message(0).header(Exchange.REDELIVERED).isEqualTo(Boolean.TRUE);
-        dead.message(0).header(Exchange.REDELIVERY_COUNTER).isEqualTo(3);
+        // no traces of redelivery headers as DLC handles the exception when moving to DLQ
+        dead.message(0).header(Exchange.REDELIVERED).isNull();
+        dead.message(0).header(Exchange.REDELIVERY_COUNTER).isNull();
         result.expectedMessageCount(0);
 
         template.sendBody("direct:in", "Hello World");



Mime
View raw message