camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject svn commit: r687873 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/processor/HandleFaultProcessor.java test/java/org/apache/camel/processor/FaultRetryRouteTest.java test/java/org/apache/camel/processor/FaultRouteTest.java
Date Thu, 21 Aug 2008 21:52:56 GMT
Author: hadrian
Date: Thu Aug 21 14:52:56 2008
New Revision: 687873

URL: http://svn.apache.org/viewvc?rev=687873&view=rev
Log:
CAMEL-842.

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/HandleFaultProcessor.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/HandleFaultProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/HandleFaultProcessor.java?rev=687873&r1=687872&r2=687873&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/HandleFaultProcessor.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/HandleFaultProcessor.java
Thu Aug 21 14:52:56 2008
@@ -29,12 +29,12 @@
         if (faultMessage != null) {
             final Object faultBody = faultMessage.getBody();
             if (faultBody != null) {
+                faultMessage.setBody(null); // Reset it since we are handling it.
                 if (faultBody instanceof Throwable) {
                     exchange.setException((Throwable)faultBody);
                 } else {
                     exchange.setException(new CamelException("Message contains fault of type
"
-                                                             + faultBody.getClass().getName()
+ ":\n"
-                                                             + faultBody));
+                        + faultBody.getClass().getName() + ":\n" + faultBody));
                 }
             }
         }

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java?rev=687873&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java
Thu Aug 21 14:52:56 2008
@@ -0,0 +1,71 @@
+/**
+ * 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.CamelException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+public class FaultRetryRouteTest extends ContextTestSupport {
+    protected MockEndpoint a;
+    protected MockEndpoint b;
+    protected MockEndpoint error;
+    protected final Processor successOnRetryProcessor = new Processor() {
+    	int count = 0;
+        public void process(Exchange exchange) throws CamelException {
+            if (count++ == 0) {
+                Message message = exchange.getFault();
+                message.setBody(new CamelException("Failed the first time"));
+            }
+        }
+    };
+
+    public void testSuccessfulRetry() throws Exception {
+        a.expectedBodiesReceived("in");
+        b.expectedBodiesReceived("in");
+        error.expectedMessageCount(0);
+        
+        template.sendBody("direct:start", "in");
+        
+        MockEndpoint.assertIsSatisfied(a, b, error);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        a = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);
+        b = resolveMandatoryEndpoint("mock:b", MockEndpoint.class);
+        error = resolveMandatoryEndpoint("mock:error", MockEndpoint.class);
+    }
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:start").errorHandler(
+                    deadLetterChannel("mock:error")
+                        .maximumRedeliveries(4)
+                        .loggingLevel(LoggingLevel.DEBUG))
+                    .to("mock:a").handleFault().process(successOnRetryProcessor).to("mock:b");
+            }
+        };
+    }
+}
\ No newline at end of file

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java?rev=687873&r1=687872&r2=687873&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java
Thu Aug 21 14:52:56 2008
@@ -115,9 +115,17 @@
             assertEquals("Fault message", "It makes no sense of business logic",
                          ((IllegalStateException)(fault.getBody())).getMessage());
         } else { // test for the throwFault with String
-            assertTrue("It should be the CamelException", fault.getBody() instanceof CamelException);
-            assertEquals("Fault message", "ExceptionMessage", ((CamelException)(fault.getBody()))
-                .getMessage());
+        	if (errors == 0) {
+        	    // fault *not* handled
+	            assertTrue("It should be the CamelException", fault.getBody() instanceof CamelException);
+	            assertEquals("Fault message", "ExceptionMessage", ((CamelException)(fault.getBody())).getMessage());
+        	} else {
+        	    // fault handled, exception should contain the fault
+	            assertNull("Fault body should be null", fault.getBody());
+	            CamelException faultex = (CamelException)exchange.getException();
+	            assertNotNull("Exception body should contain the fault", faultex);
+	            assertEquals("Fault message", "ExceptionMessage", faultex.getMessage());
+        	}
         }
     }
 



Mime
View raw message