This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 414ddaff572 CAMEL-21778: camel-core - Java DSL using id in processors after Enrich EIP is not assigned 414ddaff572 is described below commit 414ddaff572cac47a6f709c975811d340bd79309 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat Feb 22 17:30:21 2025 +0100 CAMEL-21778: camel-core - Java DSL using id in processors after Enrich EIP is not assigned --- .../org/apache/camel/model/ExpressionNode.java | 11 ----- .../apache/camel/model/ProcessorDefinition.java | 7 +++ .../org/apache/camel/processor/EnrichIdTest.java | 54 ++++++++++++++++++++++ 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ExpressionNode.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ExpressionNode.java index 7c7ca6fb15e..6336cd6e449 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/ExpressionNode.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ExpressionNode.java @@ -150,15 +150,4 @@ public abstract class ExpressionNode extends ProcessorDefinition<ExpressionNode> return Collections.emptyList(); } - @Override - public ExpressionNode id(String id) { - if (!(this instanceof OutputNode)) { - // let parent handle assigning the id, as we do not support outputs - getParent().id(id); - return this; - } else { - return super.id(id); - } - } - } 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 2e3477e4c53..6917ea436af 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 @@ -695,6 +695,13 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type> if (getParent() != null) { outputs = getParent().getOutputs(); } + } else if (this instanceof OutputExpressionNode) { + outputs = getOutputs(); + } else if (this instanceof ExpressionNode) { + // this does not accept output so it should be on the parent + if (getParent() != null) { + outputs = getParent().getOutputs(); + } } else { outputs = getOutputs(); } diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/EnrichIdTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/EnrichIdTest.java new file mode 100644 index 00000000000..76d7c4f88ba --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/processor/EnrichIdTest.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.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class EnrichIdTest extends ContextTestSupport { + + @Test + public void testEnrichId() throws Exception { + Assertions.assertInstanceOf(Enricher.class, context.getProcessor("Enriching something")); + Assertions.assertInstanceOf(LogProcessor.class, context.getProcessor("After enrich")); + Assertions.assertInstanceOf(SetBodyProcessor.class, context.getProcessor("Setting body")); + } + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start").routeId("myRoute") + .choice() + .when().constant(true) + .enrich() + .constant("direct:test") + .end() + .id("Enriching something") + .end() + .log("${body}").id("After enrich"); + + from("direct:test") + .setBody(constant("I'm running")).id("Setting body"); + } + }; + } +}