camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jans...@apache.org
Subject svn commit: r720837 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/processor/DeadLetterChannel.java test/java/org/apache/camel/processor/DeadLetterChannelExceptionCausePropagatedTest.java
Date Wed, 26 Nov 2008 12:57:07 GMT
Author: janstey
Date: Wed Nov 26 04:57:06 2008
New Revision: 720837

URL: http://svn.apache.org/viewvc?rev=720837&view=rev
Log:
CAMEL-1122 - add handled exception to message header

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelExceptionCausePropagatedTest.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java?rev=720837&r1=720836&r2=720837&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
Wed Nov 26 04:57:06 2008
@@ -45,9 +45,11 @@
     public static final String REDELIVERY_COUNTER = "org.apache.camel.RedeliveryCounter";
     public static final String REDELIVERED = "org.apache.camel.Redelivered";
     public static final String EXCEPTION_CAUSE_PROPERTY = "CamelCauseException";
-
+    public static final String CAUGHT_EXCEPTION_HEADER = "org.apache.camel.CamelCaughtException";
   
+    
     private static final transient Log LOG = LogFactory.getLog(DeadLetterChannel.class);
     private static final String FAILURE_HANDLED_PROPERTY = DeadLetterChannel.class.getName()
+ ".FAILURE_HANDLED";
+    
     private Processor output;
     private Processor deadLetter;
     private AsyncProcessor outputAsync;
@@ -214,11 +216,13 @@
     }
 
     public static boolean isFailureHandled(Exchange exchange) {
-        return exchange.getProperty(FAILURE_HANDLED_PROPERTY) != null;
+        return exchange.getProperty(FAILURE_HANDLED_PROPERTY) != null 
+            || exchange.getIn().getHeader(CAUGHT_EXCEPTION_HEADER) != null;
     }
 
     public static void setFailureHandled(Exchange exchange) {
         exchange.setProperty(FAILURE_HANDLED_PROPERTY, exchange.getException());
+        exchange.getIn().setHeader(CAUGHT_EXCEPTION_HEADER, exchange.getException());   
    
         exchange.setException(null);
     }
 

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelExceptionCausePropagatedTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelExceptionCausePropagatedTest.java?rev=720837&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelExceptionCausePropagatedTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelExceptionCausePropagatedTest.java
Wed Nov 26 04:57:06 2008
@@ -0,0 +1,57 @@
+/**
+ * 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.ContextTestSupport;
+import org.apache.camel.builder.ProcessorBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+
+public class DeadLetterChannelExceptionCausePropagatedTest extends ContextTestSupport {
+    private static final RuntimeException RUNTIME_EXCEPTION = new RuntimeException("Expected
exception.");
+    private String body = "<hello>world!</hello>";
+
+    public void testFirstFewAttemptsFail() throws Exception {
+        MockEndpoint failedEndpoint = getMockEndpoint("mock:failed");
+        MockEndpoint successEndpoint = getMockEndpoint("mock:success");
+
+        failedEndpoint.expectedBodiesReceived(body);
+        failedEndpoint.message(0).header(DeadLetterChannel.CAUGHT_EXCEPTION_HEADER)
+            .isEqualTo(RUNTIME_EXCEPTION);
+        failedEndpoint.expectedMessageCount(1);
+
+        successEndpoint.expectedMessageCount(0);
+
+        sendBody("direct:start", body);
+
+        assertMockEndpointsSatisfied();
+        assertNull(failedEndpoint.getExchanges().get(0).getException());
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                onException(RuntimeException.class).handled(true).to("mock:failed");
+
+                from("direct:start").process(ProcessorBuilder.throwException(RUNTIME_EXCEPTION))
+                    .to("mock:success");
+            }
+        };
+    }
+
+}

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



Mime
View raw message