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 2022/10/05 01:51:25 UTC
[camel] 03/09: CAMEL-18574: camel-core - Add disabled option to EIPs
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch disabled
in repository https://gitbox.apache.org/repos/asf/camel.git
commit c555e3fbeb6b00642c2ae64efaba84293b52088f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Oct 4 17:04:51 2022 -0500
CAMEL-18574: camel-core - Add disabled option to EIPs
---
.../apache/camel/model/ProcessorDefinition.java | 36 +++++++++++++--
.../org/apache/camel/reifier/DisabledReifier.java | 9 ++--
.../org/apache/camel/reifier/ProcessorReifier.java | 8 ++--
.../camel/processor/DisabledProcessorTest.java | 54 ++++++++++++++++++++++
4 files changed, 96 insertions(+), 11 deletions(-)
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 4585b01abad..f9637e144d5 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
@@ -851,19 +851,49 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
return asType();
}
+ /**
+ * Disables this EIP from the route.
+ */
+ public Type disabled() {
+ return disabled("true");
+ }
+
/**
* Whether to disable this EIP from the route.
*/
public Type disabled(boolean disabled) {
- setDisabled(disabled ? "true" : "false");
- return asType();
+ return disabled(disabled ? "true" : "false");
}
/**
* Whether to disable this EIP from the route.
*/
public Type disabled(String disabled) {
- setDisabled(disabled);
+ if (this instanceof OutputNode && getOutputs().isEmpty()) {
+ // set id on this
+ setDisabled(disabled);
+ } else {
+
+ // set it on last output as this is what the user means to do
+ // for Block(s) with non empty getOutputs() the id probably refers
+ // to the last definition in the current Block
+ List<ProcessorDefinition<?>> outputs = getOutputs();
+ if (!blocks.isEmpty()) {
+ if (blocks.getLast() instanceof ProcessorDefinition) {
+ ProcessorDefinition<?> block = (ProcessorDefinition<?>) blocks.getLast();
+ if (!block.getOutputs().isEmpty()) {
+ outputs = block.getOutputs();
+ }
+ }
+ }
+ if (!getOutputs().isEmpty()) {
+ outputs.get(outputs.size() - 1).setDisabled(disabled);
+ } else {
+ // the output could be empty
+ setDisabled(disabled);
+ }
+ }
+
return asType();
}
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/DisabledReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/DisabledReifier.java
index e2a89b8d74f..6b7961abb9a 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/DisabledReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/DisabledReifier.java
@@ -18,18 +18,17 @@ package org.apache.camel.reifier;
import org.apache.camel.Processor;
import org.apache.camel.Route;
-import org.apache.camel.model.ProcessDefinition;
import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.processor.DisabledProcessor;
-public class DisabledReifier extends ProcessorReifier<ProcessDefinition> {
+public class DisabledReifier extends ProcessorReifier {
public DisabledReifier(Route route, ProcessorDefinition<?> definition) {
- super(route, (ProcessDefinition) definition);
+ super(route, definition);
}
@Override
public Processor createProcessor() {
- // disabled so return null
- return null;
+ return new DisabledProcessor();
}
}
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ProcessorReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ProcessorReifier.java
index c1a8aacd6fd..a492b8645a3 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ProcessorReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ProcessorReifier.java
@@ -161,9 +161,11 @@ public abstract class ProcessorReifier<T extends ProcessorDefinition<?>> extends
ProcessorReifier<? extends ProcessorDefinition<?>> answer = null;
// special if the EIP is disabled
- Boolean disabled = CamelContextHelper.parseBoolean(route.getCamelContext(), definition.getDisabled());
- if (disabled != null && disabled) {
- return new DisabledReifier(route, definition);
+ if (route != null && route.getCamelContext() != null) {
+ Boolean disabled = CamelContextHelper.parseBoolean(route.getCamelContext(), definition.getDisabled());
+ if (disabled != null && disabled) {
+ return new DisabledReifier(route, definition);
+ }
}
if (!PROCESSORS.isEmpty()) {
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/DisabledProcessorTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/DisabledProcessorTest.java
new file mode 100644
index 00000000000..4423621e55c
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/DisabledProcessorTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class DisabledProcessorTest extends ContextTestSupport {
+
+ @Test
+ public void testDisabled() throws Exception {
+ getMockEndpoint("mock:foo").expectedMessageCount(0);
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+ getMockEndpoint("mock:baz").expectedMessageCount(0);
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ // the EIPs are disabled but there are still 4 outputs
+ Assertions.assertEquals(4, context.getRouteDefinitions().get(0).getOutputs().size());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .to("mock:foo").disabled()
+ .to("mock:bar").disabled(false)
+ .to("mock:baz").disabled(true)
+ .to("mock:result");
+ }
+ };
+ }
+}