This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-4.10.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.10.x by this push: new 19bff736152 CAMEL-21778: camel-core - Java DSL using id in processors after Threads EIP is not assigned 19bff736152 is described below commit 19bff73615265235d9e3bc8eda1e49786e131ba9 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat Feb 22 13:54:44 2025 +0100 CAMEL-21778: camel-core - Java DSL using id in processors after Threads EIP is not assigned --- .../apache/camel/model/ProcessorDefinition.java | 13 +++++- .../org/apache/camel/processor/ThreadsIdTest.java | 48 ++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 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 b848914af37..2e3477e4c53 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 @@ -689,11 +689,19 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type> // set id on this setId(id); } else { + List<ProcessorDefinition<?>> outputs = null; + if (this instanceof NoOutputDefinition<Type>) { + // this does not accept output so it should be on the parent + if (getParent() != null) { + outputs = getParent().getOutputs(); + } + } else { + outputs = getOutputs(); + } // 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(); @@ -702,7 +710,8 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type> } } } - if (!getOutputs().isEmpty()) { + if (outputs != null && !outputs.isEmpty()) { + // set id on last output outputs.get(outputs.size() - 1).setId(id); } else { // the output could be empty diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/ThreadsIdTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/ThreadsIdTest.java new file mode 100644 index 00000000000..a89bf44fcb1 --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/processor/ThreadsIdTest.java @@ -0,0 +1,48 @@ +/* + * 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 ThreadsIdTest extends ContextTestSupport { + + @Test + public void testThreadsId() throws Exception { + Assertions.assertInstanceOf(SetBodyProcessor.class, context.getProcessor("Setting body")); + Assertions.assertInstanceOf(ThreadsProcessor.class, context.getProcessor("Parallel processing")); + Assertions.assertInstanceOf(LogProcessor.class, context.getProcessor("After threads")); + Assertions.assertInstanceOf(SendProcessor.class, context.getProcessor("End of route")); + } + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start").routeId("myRoute") + .setBody().simple("Hello Camel from ${routeId}").id("Setting body") + .threads(5).id("Parallel processing") + .log("${body}").id("After threads") + .to("mock:end").id("End of route"); + } + }; + } +}