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 2011/06/06 19:21:13 UTC

svn commit: r1132707 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/model/ProcessorDefinition.java test/java/org/apache/camel/processor/DoTryCatchWithSplitterTest.java

Author: davsclaus
Date: Mon Jun  6 17:21:12 2011
New Revision: 1132707

URL: http://svn.apache.org/viewvc?rev=1132707&view=rev
Log:
CAMEL-3994: Added endDoTry to Java DSL so ppl can do routes with try .. catch in Java DSL and get back to the try scope so they can add the doCatch clauses.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DoTryCatchWithSplitterTest.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=1132707&r1=1132706&r2=1132707&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 Mon Jun  6 17:21:12 2011
@@ -1132,6 +1132,15 @@ public abstract class ProcessorDefinitio
     }
 
     /**
+     * Ends the current block and returns back to the {@link TryDefinition doTry()} DSL.
+     *
+     * @return the builder
+     */
+    public TryDefinition endDoTry() {
+        return (TryDefinition) end();
+    }
+
+    /**
      * <a href="http://camel.apache.org/idempotent-consumer.html">Idempotent consumer EIP:</a>
      * Creates an {@link org.apache.camel.processor.idempotent.IdempotentConsumer IdempotentConsumer}
      * to avoid duplicate messages

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DoTryCatchWithSplitterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DoTryCatchWithSplitterTest.java?rev=1132707&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DoTryCatchWithSplitterTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DoTryCatchWithSplitterTest.java Mon Jun  6 17:21:12 2011
@@ -0,0 +1,59 @@
+/**
+ * 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.RouteBuilder;
+
+/**
+ *
+ */
+public class DoTryCatchWithSplitterTest extends ContextTestSupport {
+
+    public void testTryCatchWithSplitter() throws Exception {
+        getMockEndpoint("mock:line").expectedBodiesReceived("Tiger", "Camel");
+        getMockEndpoint("mock:iae").expectedBodiesReceived("Tiger,Camel,Donkey");
+
+        template.sendBody("direct:start", "Tiger,Camel,Donkey");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .doTry()
+                        .split(body().tokenize(","))
+                            .to("direct:line")
+                        .endDoTry()
+                    .doCatch(IllegalArgumentException.class)
+                        .to("mock:iae")
+                    .end();
+
+                from("direct:line")
+                    .choice()
+                        .when(body().contains("Donkey"))
+                            .throwException(new IllegalArgumentException("Donkey not allowed"))
+                        .otherwise()
+                            .to("mock:line");
+            }
+        };
+    }
+}