You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/08/25 15:19:10 UTC

svn commit: r989092 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/model/ProcessorDefinition.java test/java/org/apache/camel/processor/onexception/OnExceptionsPerRouteTest.java

Author: davsclaus
Date: Wed Aug 25 13:19:09 2010
New Revision: 989092

URL: http://svn.apache.org/viewvc?rev=989092&view=rev
Log:
CAMEL-3061: onException with multiple exceptions now avail in the DSL for route scoped.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionsPerRouteTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=989092&r1=989091&r2=989092&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java Wed Aug 25 13:19:09 2010
@@ -1871,7 +1871,7 @@ public abstract class ProcessorDefinitio
 
     /**
      * <a href="http://camel.apache.org/exception-clause.html">Exception clause</a>
-     * for cathing certain exceptions and handling them.
+     * for catching certain exceptions and handling them.
      *
      * @param exceptionType  the exception to catch
      * @return the exception builder to configure
@@ -1883,6 +1883,19 @@ public abstract class ProcessorDefinitio
     }
 
     /**
+     * <a href="http://camel.apache.org/exception-clause.html">Exception clause</a>
+     * for catching certain exceptions and handling them.
+     *
+     * @param exceptions list of exceptions to catch
+     * @return the exception builder to configure
+     */
+    public OnExceptionDefinition onException(Class... exceptions) {
+        OnExceptionDefinition answer = new OnExceptionDefinition(Arrays.asList(exceptions));
+        addOutput(answer);
+        return answer;
+    }
+
+    /**
      * Apply a {@link Policy}.
      * <p/>
      * Policy can be used for transactional policies.

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionsPerRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionsPerRouteTest.java?rev=989092&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionsPerRouteTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionsPerRouteTest.java Wed Aug 25 13:19:09 2010
@@ -0,0 +1,63 @@
+/**
+ * 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.onexception;
+
+import java.io.IOException;
+import java.net.ConnectException;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class OnExceptionsPerRouteTest extends ContextTestSupport {
+
+    public void testOnExceptionsPerRouteDamn() throws Exception {
+        getMockEndpoint("mock:error").expectedBodiesReceived("Damn");
+
+        template.sendBody("direct:start", "Damn");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testOnExceptionsPerRouteConnect() throws Exception {
+        getMockEndpoint("mock:error").expectedBodiesReceived("Connect");
+
+        template.sendBody("direct:start", "Connect");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .onException(IllegalArgumentException.class, IOException.class)
+                        .handled(true)
+                        .to("mock:error")
+                    .end()
+                    .choice()
+                        .when(body().contains("Damn")).throwException(new IllegalArgumentException("Damn"))
+                        .when(body().contains("Connect")).throwException(new ConnectException("Cannot connect"))
+                    .end();
+            }
+        };
+    }
+}