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 2025/04/15 15:44:36 UTC
(camel) branch endChoice created (now ea70a41cf68)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch endChoice
in repository https://gitbox.apache.org/repos/asf/camel.git
at ea70a41cf68 CAMEL-21958: camel-core: Java DSL. Fix endChoice() to reuse end() and scope to current/nearest choice.
This branch includes the following new commits:
new 1d8bd60c5b8 CAMEL-21958: camel-core: Java DSL. Fix endChoice() to reuse end() and scope to current/nearest choice.
new 753b8fe3379 CAMEL-21958: camel-core: Java DSL. Fix endChoice() to reuse end() and scope to current/nearest choice.
new ea70a41cf68 CAMEL-21958: camel-core: Java DSL. Fix endChoice() to reuse end() and scope to current/nearest choice.
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(camel) 01/03: CAMEL-21958: camel-core: Java DSL. Fix endChoice() to reuse end() and scope to current/nearest choice.
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch endChoice
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 1d8bd60c5b891dd0278197c07f67dfab4f84338b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Apr 15 16:57:42 2025 +0200
CAMEL-21958: camel-core: Java DSL. Fix endChoice() to reuse end() and scope to current/nearest choice.
---
.../org/apache/camel/model/ChoiceDefinition.java | 8 +++
.../apache/camel/model/ProcessorDefinition.java | 50 +++++++++++--
.../camel/processor/NestedChoiceIssueTest.java | 13 +++-
.../processor/NestedChoiceOtherwiseIssueTest.java | 83 ++++++++++++++++++++++
.../processor/TripleNestedChoiceIssueTest.java | 13 +++-
.../async/AsyncNestedTripleChoiceIssueTest.java | 4 +-
6 files changed, 161 insertions(+), 10 deletions(-)
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java
index 4d771dda24e..167a1c3e7ae 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java
@@ -191,6 +191,14 @@ public class ChoiceDefinition extends NoOutputDefinition<ChoiceDefinition> {
return this;
}
+ // TODO: delete me
+ public ChoiceDefinition otherwise(String id) {
+ OtherwiseDefinition answer = new OtherwiseDefinition();
+ answer.setId(id);
+ addClause(answer);
+ return this;
+ }
+
private void addClause(WhenDefinition when) {
popBlock();
addOutput(when);
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 8f8c7ae841f..d711284aa70 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -1165,21 +1165,63 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
* @return the choice builder
*/
public ChoiceDefinition endChoice() {
+ return endChoice(null);
+ }
+
+ public ChoiceDefinition endChoice(String id) {
ProcessorDefinition<?> def = this;
- // are we nested choice?
- if (def.getParent() instanceof ChoiceDefinition cho) {
+ // are we already a choice
+ if (def instanceof ChoiceDefinition cho) {
return cho;
}
+ // end and find the choice
+ def = end();
+ if (def instanceof RouteDefinition) {
+ // okay that was too far down so go back up
+ def = this;
+ }
+
// are we already a choice?
if (def instanceof ChoiceDefinition choice) {
return choice;
}
+ // ProcessorDefinition<?> def = this;
+
+ /*
+ // are we nested choice?
+ if (def.getParent() instanceof ChoiceDefinition cho) {
+ // are we in fact part of the parent
+ Collection<ChoiceDefinition> nested
+ = ProcessorDefinitionHelper.filterTypeInOutputs(cho.getOutputs(), ChoiceDefinition.class);
+ boolean found = nested.stream().anyMatch(this::equals);
+ if (found) {
+ if (def instanceof ChoiceDefinition choice) {
+ return choice;
+ }
+ return cho;
+ }
+ }
+
+ // are we already a choice?
+ if (def instanceof ChoiceDefinition choice) {
+ Collection<ChoiceDefinition> nested
+ = ProcessorDefinitionHelper.filterTypeInOutputs(def.getOutputs(), ChoiceDefinition.class);
+ if (nested.isEmpty()) {
+ return choice;
+ }
+ }
+ */
+
+ if (def.getParent() instanceof ChoiceDefinition cho) {
+ return cho;
+ }
+
// okay end this and get back to the choice
- def = end();
- NamedNode p = def.getParent();
+ // def = end();
+ NamedNode p = def;
if ("when".equals(p.getShortName())) {
return (ChoiceDefinition) p;
} else if ("otherwise".equals(p.getShortName())) {
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceIssueTest.java
index b46a21e2a19..b6772b60de3 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceIssueTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceIssueTest.java
@@ -18,8 +18,11 @@ package org.apache.camel.processor;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.support.PluginHelper;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
public class NestedChoiceIssueTest extends ContextTestSupport {
@Test
@@ -46,6 +49,12 @@ public class NestedChoiceIssueTest extends ContextTestSupport {
@Test
public void testNestedChoiceLow() throws Exception {
+ String xml = PluginHelper.getModelToXMLDumper(context).dumpModelAsXml(context,
+ context.getRouteDefinition("route1"));
+ assertNotNull(xml);
+ log.info(xml);
+ System.out.println(xml);
+
getMockEndpoint("mock:low").expectedMessageCount(1);
getMockEndpoint("mock:med").expectedMessageCount(0);
getMockEndpoint("mock:big").expectedMessageCount(0);
@@ -61,8 +70,8 @@ public class NestedChoiceIssueTest extends ContextTestSupport {
@Override
public void configure() {
from("direct:start").choice().when(header("foo").isGreaterThan(1)).choice().when(header("foo").isGreaterThan(5))
- .to("mock:big").otherwise().to("mock:med")
- .endChoice().otherwise().to("mock:low").end();
+ .to("mock:big").otherwise("med").to("mock:med")
+ .end().endChoice("low").otherwise("low").to("mock:low").end();
}
};
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceOtherwiseIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceOtherwiseIssueTest.java
new file mode 100644
index 00000000000..c9a32087579
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceOtherwiseIssueTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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;
+import org.apache.camel.support.PluginHelper;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class NestedChoiceOtherwiseIssueTest extends ContextTestSupport {
+
+ @Test
+ public void testNestedChoiceOtherwise() throws Exception {
+ String xml = PluginHelper.getModelToXMLDumper(context).dumpModelAsXml(context,
+ context.getRouteDefinition("myRoute"));
+ assertNotNull(xml);
+ log.info(xml);
+ System.out.println(xml);
+
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
+ getMockEndpoint("mock:bar").expectedMessageCount(0);
+ getMockEndpoint("mock:other").expectedMessageCount(0);
+ getMockEndpoint("mock:other2").expectedMessageCount(0);
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", 10);
+ assertMockEndpointsSatisfied();
+
+ resetMocks();
+ getMockEndpoint("mock:foo").expectedMessageCount(0);
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+ getMockEndpoint("mock:other").expectedMessageCount(1);
+ getMockEndpoint("mock:other2").expectedMessageCount(0);
+ template.sendBodyAndHeader("direct:start", "Hello World", "bar", 11);
+ assertMockEndpointsSatisfied();
+
+ resetMocks();
+ getMockEndpoint("mock:foo").expectedMessageCount(0);
+ getMockEndpoint("mock:bar").expectedMessageCount(0);
+ getMockEndpoint("mock:other").expectedMessageCount(1);
+ getMockEndpoint("mock:other2").expectedMessageCount(1);
+ template.sendBodyAndHeader("direct:start", "Hello World", "cheese", 12);
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start").routeId("myRoute")
+ .errorHandler(noErrorHandler())
+ .choice()
+ .when(header("foo"))
+ .to("mock:foo")
+ .otherwise()
+ .to("mock:other")
+ .choice()
+ .when(header("bar"))
+ .to("mock:bar")
+ .endChoice("other2")
+ .otherwise()
+ .to("mock:other2")
+ .end()
+ .end();
+ }
+ };
+ }
+}
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/TripleNestedChoiceIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/TripleNestedChoiceIssueTest.java
index c06cfb6eba4..b03db7ee845 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/TripleNestedChoiceIssueTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/TripleNestedChoiceIssueTest.java
@@ -18,8 +18,11 @@ package org.apache.camel.processor;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.support.PluginHelper;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
public class TripleNestedChoiceIssueTest extends ContextTestSupport {
@Test
@@ -60,6 +63,12 @@ public class TripleNestedChoiceIssueTest extends ContextTestSupport {
@Test
public void testNestedChoiceLow() throws Exception {
+ String xml = PluginHelper.getModelToXMLDumper(context).dumpModelAsXml(context,
+ context.getRouteDefinition("route1"));
+ assertNotNull(xml);
+ log.info(xml);
+ System.out.println(xml);
+
getMockEndpoint("mock:low").expectedMessageCount(1);
getMockEndpoint("mock:med").expectedMessageCount(0);
getMockEndpoint("mock:big").expectedMessageCount(0);
@@ -77,8 +86,8 @@ public class TripleNestedChoiceIssueTest extends ContextTestSupport {
public void configure() {
from("direct:start").choice().when(header("foo").isGreaterThan(1)).choice().when(header("foo").isGreaterThan(5))
.choice().when(header("foo").isGreaterThan(10))
- .to("mock:verybig").otherwise().to("mock:big").endChoice().otherwise().to("mock:med").endChoice()
- .otherwise().to("mock:low").end();
+ .to("mock:verybig").otherwise("big").to("mock:big").end().endChoice("med").otherwise("med").to("mock:med").end().endChoice("low")
+ .otherwise("low").to("mock:low").end();
}
};
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/async/AsyncNestedTripleChoiceIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/async/AsyncNestedTripleChoiceIssueTest.java
index 036bc7ac99c..8f8a284662f 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/async/AsyncNestedTripleChoiceIssueTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/async/AsyncNestedTripleChoiceIssueTest.java
@@ -79,8 +79,8 @@ public class AsyncNestedTripleChoiceIssueTest extends ContextTestSupport {
from("direct:start").choice().when(header("foo").isGreaterThan(1)).to("async:bye:camel").choice()
.when(header("foo").isGreaterThan(5)).to("async:bye:camel2")
- .choice().when(header("foo").isGreaterThan(7)).to("mock:verybig").otherwise().to("mock:big").endChoice()
- .otherwise().to("mock:med").endChoice().otherwise()
+ .choice().when(header("foo").isGreaterThan(7)).to("mock:verybig").otherwise().to("mock:big").end().endChoice()
+ .otherwise().to("mock:med").end().endChoice().otherwise()
.to("mock:low").end();
}
};
(camel) 02/03: CAMEL-21958: camel-core: Java DSL. Fix endChoice() to reuse end() and scope to current/nearest choice.
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch endChoice
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 753b8fe337984713b6e098d6441f9d09f6ce3806
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Apr 15 17:22:44 2025 +0200
CAMEL-21958: camel-core: Java DSL. Fix endChoice() to reuse end() and scope to current/nearest choice.
---
.../org/apache/camel/model/ChoiceDefinition.java | 6 +++
.../apache/camel/model/ProcessorDefinition.java | 43 +-----------------
.../ROOT/pages/camel-4x-upgrade-guide-4_12.adoc | 52 ++++++++++++++++++++++
3 files changed, 59 insertions(+), 42 deletions(-)
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java
index 167a1c3e7ae..65bde0876e8 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java
@@ -186,6 +186,9 @@ public class ChoiceDefinition extends NoOutputDefinition<ChoiceDefinition> {
* @return the builder
*/
public ChoiceDefinition otherwise() {
+ if (this.otherwise != null) {
+ throw new IllegalArgumentException("Cannot add a 2nd otherwise to this choice: " + this + ". If you have nested choice then you may need to end().endChoice() to go back to parent choice.");
+ }
OtherwiseDefinition answer = new OtherwiseDefinition();
addClause(answer);
return this;
@@ -193,6 +196,9 @@ public class ChoiceDefinition extends NoOutputDefinition<ChoiceDefinition> {
// TODO: delete me
public ChoiceDefinition otherwise(String id) {
+ if (this.otherwise != null) {
+ throw new IllegalArgumentException("Cannot add a 2nd otherwise to this choice: " + this + ". If you have nested choice then you may need to end().endChoice() to go back to parent choice.");
+ }
OtherwiseDefinition answer = new OtherwiseDefinition();
answer.setId(id);
addClause(answer);
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index d711284aa70..7c1a9781bd1 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -41,7 +41,6 @@ import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Expression;
import org.apache.camel.LoggingLevel;
-import org.apache.camel.NamedNode;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;
import org.apache.camel.builder.DataFormatClause;
@@ -1186,48 +1185,8 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
// are we already a choice?
if (def instanceof ChoiceDefinition choice) {
return choice;
- }
-
- // ProcessorDefinition<?> def = this;
-
- /*
- // are we nested choice?
- if (def.getParent() instanceof ChoiceDefinition cho) {
- // are we in fact part of the parent
- Collection<ChoiceDefinition> nested
- = ProcessorDefinitionHelper.filterTypeInOutputs(cho.getOutputs(), ChoiceDefinition.class);
- boolean found = nested.stream().anyMatch(this::equals);
- if (found) {
- if (def instanceof ChoiceDefinition choice) {
- return choice;
- }
- return cho;
- }
- }
-
- // are we already a choice?
- if (def instanceof ChoiceDefinition choice) {
- Collection<ChoiceDefinition> nested
- = ProcessorDefinitionHelper.filterTypeInOutputs(def.getOutputs(), ChoiceDefinition.class);
- if (nested.isEmpty()) {
- return choice;
- }
- }
- */
-
- if (def.getParent() instanceof ChoiceDefinition cho) {
- return cho;
- }
-
- // okay end this and get back to the choice
- // def = end();
- NamedNode p = def;
- if ("when".equals(p.getShortName())) {
- return (ChoiceDefinition) p;
- } else if ("otherwise".equals(p.getShortName())) {
- return (ChoiceDefinition) p;
} else {
- return (ChoiceDefinition) def;
+ throw new IllegalArgumentException("Cannot endChoice() to find current/parent choice DSL. If you have nested choice then you may need to end().endChoice() to go back to parent choice.");
}
}
diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc
index 7f5f35e0072..cbb45539a62 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc
@@ -27,6 +27,58 @@ to allow returning `null` as a positive answer when using `convertBodyTo` EIP an
This behaviour was present in Camel v2 and some internal optimization in Camel v3 had changed
this to not be the case. Using type converters that can return `null` is a rare use-case, and it's not a good practice.
+=== Java DSL
+
+When using Choice EIP then in some situations you may need to use `.endChoice()`
+to be able to either continue added more nodes to the current Choice EIP, or that you
+are working with nested Choice EIPs (choice inside choice), then you may also need to use `endChoice`
+to go back to the parent choice to continue from there.
+
+However, there has been some regressions from upgrading older Camel releases to 4.11, and therefore
+we have refactored `endChoice` to work more consistent.
+
+For example the following code
+
+[source,java]
+----
+from("direct:start")
+ .choice()
+ .when(header("foo").isGreaterThan(1))
+ .choice()
+ .when(header("foo").isGreaterThan(5))
+ .to("mock:big")
+ .otherwise()
+ .to("mock:med")
+ .endChoice()
+ .otherwise()
+ .to("mock:low")
+ .end();
+----
+
+Should now be
+
+[source,java]
+----
+from("direct:start")
+ .choice()
+ .when(header("foo").isGreaterThan(1))
+ .choice()
+ .when(header("foo").isGreaterThan(5))
+ .to("mock:big")
+ .otherwise()
+ .to("mock:med")
+ .end().endChoice()
+ .otherwise()
+ .to("mock:low")
+ .end();
+----
+
+Notice that the `endChoice` is changed to `end().endChoice()`. This is required to be consistent
+to end the current choice (inner) and then afterwards change the scope to be Choice EIP to be able to
+continue in the outer Choice. Otherwise the Java DSL cannot know the scope is Choice EIP and you would
+not be able to add the `otherwise` block to the outer Choice.
+
+
=== camel-as2
Add options allowing the addition of an `Authorization` header for Basic or Bearer authentication to client and
(camel) 03/03: CAMEL-21958: camel-core: Java DSL. Fix endChoice() to reuse end() and scope to current/nearest choice.
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch endChoice
in repository https://gitbox.apache.org/repos/asf/camel.git
commit ea70a41cf689ccc57a02f04145e7683178456028
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Apr 15 17:35:41 2025 +0200
CAMEL-21958: camel-core: Java DSL. Fix endChoice() to reuse end() and scope to current/nearest choice.
---
.../java/org/apache/camel/model/ChoiceDefinition.java | 15 +++------------
.../java/org/apache/camel/model/ProcessorDefinition.java | 7 ++-----
.../org/apache/camel/processor/NestedChoiceIssueTest.java | 5 ++---
.../camel/processor/NestedChoiceOtherwiseIssueTest.java | 3 +--
.../camel/processor/TripleNestedChoiceIssueTest.java | 5 ++---
5 files changed, 10 insertions(+), 25 deletions(-)
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java
index 65bde0876e8..64e2dd5abc7 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java
@@ -187,24 +187,15 @@ public class ChoiceDefinition extends NoOutputDefinition<ChoiceDefinition> {
*/
public ChoiceDefinition otherwise() {
if (this.otherwise != null) {
- throw new IllegalArgumentException("Cannot add a 2nd otherwise to this choice: " + this + ". If you have nested choice then you may need to end().endChoice() to go back to parent choice.");
+ throw new IllegalArgumentException(
+ "Cannot add a 2nd otherwise to this choice: " + this
+ + ". If you have nested choice then you may need to end().endChoice() to go back to parent choice.");
}
OtherwiseDefinition answer = new OtherwiseDefinition();
addClause(answer);
return this;
}
- // TODO: delete me
- public ChoiceDefinition otherwise(String id) {
- if (this.otherwise != null) {
- throw new IllegalArgumentException("Cannot add a 2nd otherwise to this choice: " + this + ". If you have nested choice then you may need to end().endChoice() to go back to parent choice.");
- }
- OtherwiseDefinition answer = new OtherwiseDefinition();
- answer.setId(id);
- addClause(answer);
- return this;
- }
-
private void addClause(WhenDefinition when) {
popBlock();
addOutput(when);
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 7c1a9781bd1..79e652f0264 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -1164,10 +1164,6 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
* @return the choice builder
*/
public ChoiceDefinition endChoice() {
- return endChoice(null);
- }
-
- public ChoiceDefinition endChoice(String id) {
ProcessorDefinition<?> def = this;
// are we already a choice
@@ -1186,7 +1182,8 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
if (def instanceof ChoiceDefinition choice) {
return choice;
} else {
- throw new IllegalArgumentException("Cannot endChoice() to find current/parent choice DSL. If you have nested choice then you may need to end().endChoice() to go back to parent choice.");
+ throw new IllegalArgumentException(
+ "Cannot endChoice() to find current/parent choice DSL. If you have nested choice then you may need to end().endChoice() to go back to parent choice.");
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceIssueTest.java
index b6772b60de3..c91ea223d30 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceIssueTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceIssueTest.java
@@ -53,7 +53,6 @@ public class NestedChoiceIssueTest extends ContextTestSupport {
context.getRouteDefinition("route1"));
assertNotNull(xml);
log.info(xml);
- System.out.println(xml);
getMockEndpoint("mock:low").expectedMessageCount(1);
getMockEndpoint("mock:med").expectedMessageCount(0);
@@ -70,8 +69,8 @@ public class NestedChoiceIssueTest extends ContextTestSupport {
@Override
public void configure() {
from("direct:start").choice().when(header("foo").isGreaterThan(1)).choice().when(header("foo").isGreaterThan(5))
- .to("mock:big").otherwise("med").to("mock:med")
- .end().endChoice("low").otherwise("low").to("mock:low").end();
+ .to("mock:big").otherwise().to("mock:med")
+ .end().endChoice().otherwise().to("mock:low").end();
}
};
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceOtherwiseIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceOtherwiseIssueTest.java
index c9a32087579..a938e488760 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceOtherwiseIssueTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceOtherwiseIssueTest.java
@@ -31,7 +31,6 @@ public class NestedChoiceOtherwiseIssueTest extends ContextTestSupport {
context.getRouteDefinition("myRoute"));
assertNotNull(xml);
log.info(xml);
- System.out.println(xml);
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:bar").expectedMessageCount(0);
@@ -72,7 +71,7 @@ public class NestedChoiceOtherwiseIssueTest extends ContextTestSupport {
.choice()
.when(header("bar"))
.to("mock:bar")
- .endChoice("other2")
+ .endChoice()
.otherwise()
.to("mock:other2")
.end()
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/TripleNestedChoiceIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/TripleNestedChoiceIssueTest.java
index b03db7ee845..17b469ae04a 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/TripleNestedChoiceIssueTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/TripleNestedChoiceIssueTest.java
@@ -67,7 +67,6 @@ public class TripleNestedChoiceIssueTest extends ContextTestSupport {
context.getRouteDefinition("route1"));
assertNotNull(xml);
log.info(xml);
- System.out.println(xml);
getMockEndpoint("mock:low").expectedMessageCount(1);
getMockEndpoint("mock:med").expectedMessageCount(0);
@@ -86,8 +85,8 @@ public class TripleNestedChoiceIssueTest extends ContextTestSupport {
public void configure() {
from("direct:start").choice().when(header("foo").isGreaterThan(1)).choice().when(header("foo").isGreaterThan(5))
.choice().when(header("foo").isGreaterThan(10))
- .to("mock:verybig").otherwise("big").to("mock:big").end().endChoice("med").otherwise("med").to("mock:med").end().endChoice("low")
- .otherwise("low").to("mock:low").end();
+ .to("mock:verybig").otherwise().to("mock:big").end().endChoice().otherwise().to("mock:med").end().endChoice()
+ .otherwise().to("mock:low").end();
}
};
}