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 2015/05/29 09:43:39 UTC

[3/3] camel git commit: CAMEL-8798: weaveAddLast throwing UnsupportedOperation when route have a ChoiceDefinition

CAMEL-8798: weaveAddLast throwing UnsupportedOperation when route have a ChoiceDefinition

Conflicts:
	camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f0443ae8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f0443ae8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f0443ae8

Branch: refs/heads/camel-2.14.x
Commit: f0443ae89a13ba42d1af917238ab42e87a629c9b
Parents: 8fb0d78
Author: Claus Ibsen <da...@apache.org>
Authored: Fri May 29 09:42:14 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri May 29 09:48:20 2015 +0200

----------------------------------------------------------------------
 .../camel/model/ProcessorDefinitionHelper.java  | 42 ++++++++------
 .../interceptor/AdviceWithWeaveLastCBRTest.java | 58 ++++++++++++++++++++
 2 files changed, 82 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f0443ae8/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
index ff0b846..15a3919 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
@@ -261,18 +261,21 @@ public final class ProcessorDefinitionHelper {
                     found.add((T)choice);
                 }
 
-                for (WhenDefinition when : choice.getWhenClauses()) {
-                    if (type.isInstance(when)) {
-                        found.add((T)when);   
+                // only look at children if current < maxDeep (or max deep is disabled)
+                if (maxDeep < 0 || current < maxDeep) {
+                    for (WhenDefinition when : choice.getWhenClauses()) {
+                        if (type.isInstance(when)) {
+                            found.add((T) when);
+                        }
+                        List<ProcessorDefinition<?>> children = when.getOutputs();
+                        doFindType(children, type, found, ++current, maxDeep);
                     }
-                    List<ProcessorDefinition<?>> children = when.getOutputs();
-                    doFindType(children, type, found, ++current, maxDeep);
-                }
 
-                // otherwise is optional
-                if (choice.getOtherwise() != null) {
-                    List<ProcessorDefinition<?>> children = choice.getOtherwise().getOutputs();
-                    doFindType(children, type, found, ++current, maxDeep);
+                    // otherwise is optional
+                    if (choice.getOtherwise() != null) {
+                        List<ProcessorDefinition<?>> children = choice.getOtherwise().getOutputs();
+                        doFindType(children, type, found, ++current, maxDeep);
+                    }
                 }
 
                 // do not check children as we already did that
@@ -288,16 +291,19 @@ public final class ProcessorDefinitionHelper {
                     found.add((T)doTry);
                 }
 
-                List<ProcessorDefinition<?>> doTryOut = doTry.getOutputsWithoutCatches();
-                doFindType(doTryOut, type, found, ++current, maxDeep);
+                // only look at children if current < maxDeep (or max deep is disabled)
+                if (maxDeep < 0 || current < maxDeep) {
+                    List<ProcessorDefinition<?>> doTryOut = doTry.getOutputsWithoutCatches();
+                    doFindType(doTryOut, type, found, ++current, maxDeep);
 
-                List<CatchDefinition> doTryCatch = doTry.getCatchClauses();
-                for (CatchDefinition doCatch : doTryCatch) {
-                    doFindType(doCatch.getOutputs(), type, found, ++current, maxDeep);
-                }
+                    List<CatchDefinition> doTryCatch = doTry.getCatchClauses();
+                    for (CatchDefinition doCatch : doTryCatch) {
+                        doFindType(doCatch.getOutputs(), type, found, ++current, maxDeep);
+                    }
 
-                if (doTry.getFinallyClause() != null) {
-                    doFindType(doTry.getFinallyClause().getOutputs(), type, found, ++current, maxDeep);
+                    if (doTry.getFinallyClause() != null) {
+                        doFindType(doTry.getFinallyClause().getOutputs(), type, found, ++current, maxDeep);
+                    }
                 }
 
                 // do not check children as we already did that

http://git-wip-us.apache.org/repos/asf/camel/blob/f0443ae8/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithWeaveLastCBRTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithWeaveLastCBRTest.java b/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithWeaveLastCBRTest.java
new file mode 100644
index 0000000..b47b256
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithWeaveLastCBRTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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.interceptor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Advice with tests
+ */
+public class AdviceWithWeaveLastCBRTest extends ContextTestSupport {
+
+    public void testWeaveAddLast() throws Exception {
+        context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // insert at the end of the existing route, the given piece of route
+                weaveAddLast().to("mock:last");
+            }
+        });
+
+        getMockEndpoint("mock:foo").expectedMessageCount(1);
+        getMockEndpoint("mock:bar").expectedMessageCount(0);
+        getMockEndpoint("mock:last").expectedMessageCount(1);
+
+        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "yeah");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .choice()
+                        .when().header("foo").to("mock:foo")
+                        .otherwise().to("mock:bar");
+            }
+        };
+    }
+}
\ No newline at end of file