You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2008/05/21 19:14:11 UTC

svn commit: r658765 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/model/ camel-core/src/main/java/org/apache/camel/processor/ camel-core/src/test/java/org/apache/camel/processor/ components/camel-spring/src/test/java/org/apache/...

Author: hadrian
Date: Wed May 21 10:14:11 2008
New Revision: 658765

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

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/HandleFaultType.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/HandleFaultProcessor.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThrowFaultType.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFaultRouteTest.java

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/HandleFaultType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/HandleFaultType.java?rev=658765&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/HandleFaultType.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/HandleFaultType.java Wed May 21 10:14:11 2008
@@ -0,0 +1,41 @@
+/**
+ * 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.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.processor.HandleFaultProcessor;
+
+/**
+ * @version $Revision: 36565 $
+ */
+@XmlRootElement(name = "handleFault")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class HandleFaultType extends InterceptorRef {
+    
+    public HandleFaultType() {
+    	super(new HandleFaultProcessor());
+    }    
+
+    @Override
+    public String toString() {
+        return "HandleFault[" + getLabel() + "]";
+    }
+
+}

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java?rev=658765&r1=658764&r2=658765&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java Wed May 21 10:14:11 2008
@@ -990,6 +990,15 @@
         return answer;
     }
 
+    /**
+     * Forces handling of faults as exceptions
+     *
+     * @return the current builder with the fault handler configured
+     */
+    public Type handleFault() {
+        intercept(new HandleFaultType());
+        return (Type) this;
+    }
 
     /**
      * Installs the given error handler builder

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThrowFaultType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThrowFaultType.java?rev=658765&r1=658764&r2=658765&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThrowFaultType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThrowFaultType.java Wed May 21 10:14:11 2008
@@ -80,7 +80,4 @@
     public List<ProcessorType<?>> getOutputs() {
         return Collections.EMPTY_LIST;
     }
-
-
-
 }

Added: 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=658765&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/HandleFaultProcessor.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/HandleFaultProcessor.java Wed May 21 10:14:11 2008
@@ -0,0 +1,42 @@
+/**
+ * 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.Exchange;
+import org.apache.camel.Message;
+
+public class HandleFaultProcessor extends DelegateProcessor {
+
+	@Override
+	public void process(Exchange exchange) throws Exception {
+    	super.process(exchange);
+        final Message faultMessage = exchange.getFault(false);
+        if (faultMessage != null) {
+            final Object faultBody = faultMessage.getBody();
+            if (faultBody != null) {
+            	if (faultBody instanceof Throwable) {
+            		exchange.setException((Throwable)faultBody);
+            	} else {
+            		exchange.setException(new CamelException(
+            		    "Message contains fault of type " + 
+            		    faultBody.getClass().getName() + ":\n" + faultBody));
+            	}
+            }
+        }
+	}
+}

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=658765&r1=658764&r2=658765&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 Wed May 21 10:14:11 2008
@@ -33,6 +33,7 @@
     protected MockEndpoint a;
     protected MockEndpoint b;
     protected MockEndpoint c;
+    protected MockEndpoint err;
     protected boolean shouldWork = true;
 
     public void testWithOut() throws Exception {
@@ -75,25 +76,34 @@
     }
 
     public void testWithThrowFaultMessage() throws Exception {
-
         throwFaultTest("direct:string");
-
     }
 
     public void testWithThrowFaultException() throws Exception {
-
         throwFaultTest("direct:exception");
+    }
+
+    public void testWithThrowFaultMessageUnhandled() throws Exception {
+        throwFaultTest("direct:fault");
+    }
 
+    public void testWithHandleFaultMessage() throws Exception {
+        throwFaultTest("direct:error", 1);
     }
 
     private void throwFaultTest(String startPoint) throws InterruptedException {
+    	throwFaultTest(startPoint, 0);
+    }
+    
+   private void throwFaultTest(String startPoint, int errors) throws InterruptedException {
         a.expectedMessageCount(1);
         b.expectedMessageCount(0);
         c.expectedMessageCount(0);
+        err.expectedMessageCount(errors);
 
         template.sendBody(startPoint, "in");
 
-        MockEndpoint.assertIsSatisfied(a, b, c);
+        MockEndpoint.assertIsSatisfied(a, b, c, err);
 
         List<Exchange> list = a.getReceivedExchanges();
         Exchange exchange = list.get(0);
@@ -109,7 +119,6 @@
             assertEquals("Fault message", "ExceptionMessage", ((CamelException)(fault.getBody()))
                 .getMessage());
         }
-
     }
 
     @Override
@@ -118,6 +127,8 @@
         a = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);
         b = resolveMandatoryEndpoint("mock:b", MockEndpoint.class);
         c = resolveMandatoryEndpoint("mock:c", MockEndpoint.class);
+        err = resolveMandatoryEndpoint("mock:error", MockEndpoint.class);
+
     }
 
     @Override
@@ -132,8 +143,19 @@
                 from("direct:exception").to("mock:a")
                     .throwFault(new IllegalStateException("It makes no sense of business logic"))
                     .to("mock:b");
+                
+                from("direct:fault").errorHandler(
+                    deadLetterChannel("mock:error")
+                	    .maximumRedeliveries(2)
+                        .loggingLevel(LoggingLevel.DEBUG))
+                    .to("mock:a").throwFault("ExceptionMessage").to("mock:b");
+                
+                from("direct:error").errorHandler(
+                    deadLetterChannel("mock:error")
+                	    .maximumRedeliveries(2)
+                        .loggingLevel(LoggingLevel.DEBUG))
+                    .to("mock:a").handleFault().throwFault("ExceptionMessage").to("mock:b");
             }
         };
     }
-
 }

Modified: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFaultRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFaultRouteTest.java?rev=658765&r1=658764&r2=658765&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFaultRouteTest.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFaultRouteTest.java Wed May 21 10:14:11 2008
@@ -30,4 +30,15 @@
         return createSpringCamelContext(this, "org/apache/camel/spring/processor/faultRoute.xml");
     }
 
+    @Override
+    public void testWithThrowFaultMessageUnhandled() throws Exception {
+        // Route cannot be configured due to lack of support for errorHandler
+    	// in the xml dsl (CAMEL-122)
+    }
+
+    @Override
+    public void testWithHandleFaultMessage() throws Exception {
+        // Route cannot be configured due to lack of support for errorHandler
+    	// in the xml dsl (CAMEL-122)
+    }
 }