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
commit 0a5f3db55ae48aed177d4f5a199b75f379728915 Author: Claus Ibsen <[email protected]> AuthorDate: Fri Feb 13 16:34:30 2026 +0100 camel-jbang: EIPs with AggregationStrategy should support stubbing as well --- .../modules/eips/pages/competing-consumers.adoc | 2 +- .../eips/pages/composed-message-processor.adoc | 57 ++++++++++++++++++++-- .../apache/camel/reifier/ClaimCheckReifier.java | 3 ++ .../org/apache/camel/reifier/MulticastReifier.java | 3 ++ .../org/apache/camel/reifier/ProcessorReifier.java | 3 ++ .../apache/camel/reifier/RecipientListReifier.java | 3 ++ .../org/apache/camel/reifier/SplitReifier.java | 3 ++ .../org/apache/camel/support/PatternHelper.java | 5 ++ .../camel/main/download/StubBeanRepository.java | 5 ++ .../yaml/validator/stub/StubBeanRepository.java | 5 ++ 10 files changed, 84 insertions(+), 5 deletions(-) diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/competing-consumers.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/competing-consumers.adoc index 0e122d97638c..14dcab6c178a 100644 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/competing-consumers.adoc +++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/competing-consumers.adoc @@ -177,4 +177,4 @@ into the backup folder. This is an important note that the on completion is done This ensures the file is not moved before the file is processed successfully. Suppose the `calculateBean` bean could not process one of the files. If it was the synchronous thread that should do the on completion strategy, then the file would have been moved to early into the backup folder. By handing over this to the asynchronous - thread, we do it after we have processed the message completely +thread, we do it after we have processed the message completely diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/composed-message-processor.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/composed-message-processor.adoc index fe1d0d2cb7c7..1fd1a9874976 100644 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/composed-message-processor.adoc +++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/composed-message-processor.adoc @@ -22,17 +22,22 @@ aggregate and return a single combined response. The route and the code comments below explain how you can use the xref:split-eip.adoc[Split] EIP to split each message to sub-message which are processed individually and then combined back into -a single response message via the custom `AggregationStrategy` (`MyOrderStrategy`), as the output from the Split EIP. +a single response message via the custom `AggregationStrategy` (`myStrategy`), as the output from the Split EIP. +[tabs] +==== +Java:: ++ [source,java] ---- // this routes starts from the direct:start endpoint // the body is then split based on @ separator // the splitter in Camel supports InOut as well, and for that we need // to be able to aggregate what response we need to send back, so we provide our -// own strategy with the class MyOrderStrategy. +// own strategy with the class MyOrderStrategy which has been registered as a bean +// with id myStrategy. from("direct:start") - .split(body().tokenize("@"), new MyOrderStrategy()) + .split(simple("${split(@)}")).aggregationStrategy("myStrategy") // each split message is then send to this bean where we can process it .to("bean:MyOrderService?method=handleOrder") // this is important to end the splitter route as we do not want to do more routing @@ -40,10 +45,54 @@ from("direct:start") .end() // after we have split and handled each message, we want to send a single combined // response back to the original caller, so we let this bean build it for us - // this bean will receive the result of the aggregate strategy: MyOrderStrategy + // this bean will receive the result of the aggregate strategy .to("bean:MyOrderService?method=buildCombinedResponse") ---- +XML:: ++ +[source,xml] +---- +<route> + <from uri="direct:start"/> + <split aggregationStrategy="myStrategy"> + <simple>${split(@)}</simple> + <to uri="bean:MyOrderService?method=handleOrder"/> + </split> + <to uri="bean:MyOrderService?method=buildCombinedResponse"/> +</route> +---- + + +YAML:: ++ +[source,yaml] +---- +- route: + from: + uri: direct + parameters: + name: start + steps: + - split: + aggregationStrategy: myStrategy + expression: + simple: + expression: "${split(@)}" + steps: + - to: + uri: bean + parameters: + beanName: MyOrderService + method: handleOrder + - to: + uri: bean + parameters: + beanName: MyOrderService + method: buildCombinedResponse +---- +==== + == More details See the xref:split-eip.adoc[Splitter] EIP. diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ClaimCheckReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ClaimCheckReifier.java index b36c4fe63cb5..2504fa737666 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ClaimCheckReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ClaimCheckReifier.java @@ -116,6 +116,9 @@ public class ClaimCheckReifier extends ProcessorReifier<ClaimCheckDefinition> { String ref = parseString(definition.getAggregationStrategy()); if (strategy == null && ref != null) { Object aggStrategy = lookupByName(ref); + if (aggStrategy == null) { + aggStrategy = lookupByNameAndType(ref, AggregationStrategy.class); + } if (aggStrategy instanceof AggregationStrategy aggregationStrategy) { strategy = aggregationStrategy; } else if (aggStrategy instanceof BiFunction biFunction) { diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/MulticastReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/MulticastReifier.java index 2b84b0246e85..b1ed396ff781 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/MulticastReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/MulticastReifier.java @@ -92,6 +92,9 @@ public class MulticastReifier extends ProcessorReifier<MulticastDefinition> { String ref = parseString(definition.getAggregationStrategy()); if (strategy == null && ref != null) { Object aggStrategy = lookupByName(ref); + if (aggStrategy == null) { + aggStrategy = lookupByNameAndType(ref, AggregationStrategy.class); + } if (aggStrategy instanceof AggregationStrategy aggregationStrategy) { strategy = aggregationStrategy; } else if (aggStrategy instanceof BiFunction biFunction) { 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 bc4fa9ade67b..86ebf04c5220 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 @@ -912,6 +912,9 @@ public abstract class ProcessorReifier<T extends ProcessorDefinition<?>> extends AggregationStrategy strategy = definition.getAggregationStrategyBean(); if (strategy == null && definition.getAggregationStrategyRef() != null) { Object aggStrategy = lookupByName(definition.getAggregationStrategyRef()); + if (aggStrategy == null) { + aggStrategy = lookupByNameAndType(definition.getAggregationStrategyRef(), AggregationStrategy.class); + } if (aggStrategy instanceof AggregationStrategy aggregationStrategy) { strategy = aggregationStrategy; } else if (aggStrategy instanceof BiFunction biFunction) { diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/RecipientListReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/RecipientListReifier.java index 71dc229cdb62..992e731f35d4 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/RecipientListReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/RecipientListReifier.java @@ -118,6 +118,9 @@ public class RecipientListReifier extends ProcessorReifier<RecipientListDefiniti String ref = parseString(definition.getAggregationStrategy()); if (strategy == null && ref != null) { Object aggStrategy = lookupByName(ref); + if (aggStrategy == null) { + aggStrategy = lookupByNameAndType(ref, AggregationStrategy.class); + } if (aggStrategy instanceof AggregationStrategy aggregationStrategy) { strategy = aggregationStrategy; } else if (aggStrategy instanceof BiFunction biFunction) { diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/SplitReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/SplitReifier.java index 1068698603a1..77d0fb583dfb 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/SplitReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/SplitReifier.java @@ -85,6 +85,9 @@ public class SplitReifier extends ExpressionReifier<SplitDefinition> { AggregationStrategy strategy = definition.getAggregationStrategyBean(); if (strategy == null && definition.getAggregationStrategy() != null) { Object aggStrategy = lookupByName(definition.getAggregationStrategy()); + if (aggStrategy == null) { + aggStrategy = lookupByNameAndType(definition.getAggregationStrategy(), AggregationStrategy.class); + } if (aggStrategy instanceof AggregationStrategy aggregationStrategy) { strategy = aggregationStrategy; } else if (aggStrategy instanceof BiFunction biFunction) { diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PatternHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/PatternHelper.java index b0c562a7b5ed..dd784ae5ae47 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/PatternHelper.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/PatternHelper.java @@ -58,6 +58,11 @@ public final class PatternHelper { return true; } + if ("*".equals(pattern)) { + // matches everything + return true; + } + if (matchWildcard(name, pattern)) { return true; } diff --git a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/StubBeanRepository.java b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/StubBeanRepository.java index 4457d3abb61f..20466d4a4d98 100644 --- a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/StubBeanRepository.java +++ b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/StubBeanRepository.java @@ -21,7 +21,9 @@ import java.util.Map; import java.util.Set; import java.util.UUID; +import org.apache.camel.AggregationStrategy; import org.apache.camel.processor.DefaultClaimCheckRepository; +import org.apache.camel.processor.aggregate.GroupedBodyAggregationStrategy; import org.apache.camel.processor.aggregate.MemoryAggregationRepository; import org.apache.camel.spi.AggregationRepository; import org.apache.camel.spi.BeanRepository; @@ -92,6 +94,9 @@ public class StubBeanRepository implements BeanRepository { if (StateRepository.class.isAssignableFrom(type)) { return (T) new MemoryStateRepository(); } + if (AggregationStrategy.class.isAssignableFrom(type)) { + return (T) new GroupedBodyAggregationStrategy(); + } return null; } } diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/stub/StubBeanRepository.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/stub/StubBeanRepository.java index 9557db7d05f3..1ba9aa3a93fd 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/stub/StubBeanRepository.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/stub/StubBeanRepository.java @@ -21,7 +21,9 @@ import java.util.Map; import java.util.Set; import java.util.UUID; +import org.apache.camel.AggregationStrategy; import org.apache.camel.processor.DefaultClaimCheckRepository; +import org.apache.camel.processor.aggregate.GroupedBodyAggregationStrategy; import org.apache.camel.processor.aggregate.MemoryAggregationRepository; import org.apache.camel.spi.AggregationRepository; import org.apache.camel.spi.BeanRepository; @@ -78,6 +80,9 @@ public class StubBeanRepository implements BeanRepository { if (StateRepository.class.isAssignableFrom(type)) { return (T) new MemoryStateRepository(); } + if (AggregationStrategy.class.isAssignableFrom(type)) { + return (T) new GroupedBodyAggregationStrategy(); + } return null; } }
