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 2021/02/15 10:18:22 UTC
[camel] branch master updated: CAMEL-16210: camel-core - Choice EIP
exception from predicate may trigger otherwise
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 8a6290f CAMEL-16210: camel-core - Choice EIP exception from predicate may trigger otherwise
8a6290f is described below
commit 8a6290f8d775233c99f34b20b23d13e93683aa0c
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Feb 15 11:17:02 2021 +0100
CAMEL-16210: camel-core - Choice EIP exception from predicate may trigger otherwise
---
.../apache/camel/processor/ChoiceProcessor.java | 4 +-
.../ChoicePredicateThrowExceptionTest.java | 125 +++++++++++++++++++++
2 files changed, 128 insertions(+), 1 deletion(-)
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/ChoiceProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/ChoiceProcessor.java
index cf80e7e..983dcc7 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/ChoiceProcessor.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/ChoiceProcessor.java
@@ -84,7 +84,9 @@ public class ChoiceProcessor extends AsyncProcessorSupport implements Navigate<P
// check for error if so we should break out
if (!continueProcessing(exchange, "so breaking out of choice", LOG)) {
- break;
+ // okay there was an error in the predicate so we should exit
+ choiceCallback.done(true);
+ return true;
}
// if we did not match then continue to next filter
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/ChoicePredicateThrowExceptionTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/ChoicePredicateThrowExceptionTest.java
new file mode 100644
index 0000000..a62be68
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/ChoicePredicateThrowExceptionTest.java
@@ -0,0 +1,125 @@
+/*
+ * 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.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.fail;
+
+/**
+ * Unit test based on user forum problem.
+ */
+public class ChoicePredicateThrowExceptionTest extends ContextTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Test
+ public void testChoiceGlobal() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ errorHandler(noErrorHandler());
+
+ from("direct:start")
+ .choice()
+ .when(e -> {
+ throw new IllegalArgumentException("Forced");
+ })
+ .to("mock:a")
+ .to("mock:b")
+ .to("mock:c")
+ .otherwise()
+ .to("mock:d")
+ .to("mock:e")
+ .to("mock:f")
+ .end()
+ .end()
+ .to("mock:result");
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:a").expectedMessageCount(0);
+ getMockEndpoint("mock:b").expectedMessageCount(0);
+ getMockEndpoint("mock:c").expectedMessageCount(0);
+ getMockEndpoint("mock:d").expectedMessageCount(0);
+ getMockEndpoint("mock:e").expectedMessageCount(0);
+ getMockEndpoint("mock:f").expectedMessageCount(0);
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+
+ try {
+ template.sendBody("direct:start", "Hello World");
+ fail();
+ } catch (Exception e) {
+ assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testChoiceSubRoute() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
+ from("direct:start")
+ .to("direct:sub")
+ .to("mock:result");
+
+ from("direct:sub")
+ .errorHandler(noErrorHandler())
+ .choice()
+ .when(e -> {
+ throw new IllegalArgumentException("Forced");
+ })
+ .to("mock:a")
+ .to("mock:b")
+ .to("mock:c")
+ .otherwise()
+ .to("mock:d")
+ .to("mock:e")
+ .to("mock:f")
+ .end();
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:a").expectedMessageCount(0);
+ getMockEndpoint("mock:b").expectedMessageCount(0);
+ getMockEndpoint("mock:c").expectedMessageCount(0);
+ getMockEndpoint("mock:d").expectedMessageCount(0);
+ getMockEndpoint("mock:e").expectedMessageCount(0);
+ getMockEndpoint("mock:f").expectedMessageCount(0);
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+
+ try {
+ template.sendBody("direct:start", "Hello World");
+ fail();
+ } catch (Exception e) {
+ assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+}