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 a7b6683 CAMEL-16757: Route now stores correctly which route
configuration it has been applied with.
a7b6683 is described below
commit a7b6683230435880b1620bd9609a02d1d51ebcb3
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Aug 4 13:13:19 2021 +0200
CAMEL-16757: Route now stores correctly which route configuration it has
been applied with.
---
.../org/apache/camel/model/RoutesDefinition.java | 47 +++++++++++++---------
.../core/xml/AbstractCamelContextFactoryBean.java | 47 +++++++++++++---------
2 files changed, 54 insertions(+), 40 deletions(-)
diff --git
a/core/camel-core-model/src/main/java/org/apache/camel/model/RoutesDefinition.java
b/core/camel-core-model/src/main/java/org/apache/camel/model/RoutesDefinition.java
index 1df5154..02bd6be 100644
---
a/core/camel-core-model/src/main/java/org/apache/camel/model/RoutesDefinition.java
+++
b/core/camel-core-model/src/main/java/org/apache/camel/model/RoutesDefinition.java
@@ -32,6 +32,7 @@ import org.apache.camel.ErrorHandlerFactory;
import org.apache.camel.builder.EndpointConsumerBuilder;
import org.apache.camel.spi.AsEndpointUri;
import org.apache.camel.spi.Metadata;
+import org.apache.camel.support.OrderedComparator;
import org.apache.camel.support.PatternHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -231,26 +232,32 @@ public class RoutesDefinition extends
OptionalIdentifiedDefinition<RoutesDefinit
List<RouteConfigurationDefinition> globalConfigurations
=
getCamelContext().adapt(ModelCamelContext.class).getRouteConfigurationDefinitions();
if (globalConfigurations != null) {
- globalConfigurations.stream()
- // global configurations have no id assigned or is a
wildcard
- // if the route has a route configuration assigned
then use pattern matching
- .filter(g -> {
- if (route.getRouteConfigurationId() != null) {
- return PatternHelper.matchPattern(g.getId(),
route.getRouteConfigurationId());
- } else {
- return g.getId() == null ||
g.getId().equals("*");
- }
- })
- .forEach(g -> {
- String id = g.getId() == null ? "<default>" :
g.getId();
- // remember the id that was used on the route
- route.addAppliedRouteConfigurationId(id);
- oe.addAll(g.getOnExceptions());
- icp.addAll(g.getIntercepts());
- ifrom.addAll(g.getInterceptFroms());
- ito.addAll(g.getInterceptSendTos());
- oc.addAll(g.getOnCompletions());
- });
+ // if there are multiple ids configured then we should apply
in that same order
+ String[] ids = route.getRouteConfigurationId() != null
+ ? route.getRouteConfigurationId().split(",") : new
String[] { "*" };
+ for (String id : ids) {
+ // sort according to ordered
+
globalConfigurations.stream().sorted(OrderedComparator.get())
+ .filter(g -> {
+ if (route.getRouteConfigurationId() != null) {
+ // if the route has a route configuration
assigned then use pattern matching
+ return
PatternHelper.matchPattern(g.getId(), id);
+ } else {
+ // global configurations have no id
assigned or is a wildcard
+ return g.getId() == null ||
g.getId().equals(id);
+ }
+ })
+ .forEach(g -> {
+ String aid = g.getId() == null ? "<default>" :
g.getId();
+ // remember the id that was used on the route
+ route.addAppliedRouteConfigurationId(aid);
+ oe.addAll(g.getOnExceptions());
+ icp.addAll(g.getIntercepts());
+ ifrom.addAll(g.getInterceptFroms());
+ ito.addAll(g.getInterceptSendTos());
+ oc.addAll(g.getOnCompletions());
+ });
+ }
}
}
diff --git
a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
index ab8857b..5c717be 100644
---
a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
+++
b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
@@ -134,6 +134,7 @@ import org.apache.camel.spi.UuidGenerator;
import org.apache.camel.spi.Validator;
import org.apache.camel.support.CamelContextHelper;
import org.apache.camel.support.ObjectHelper;
+import org.apache.camel.support.OrderedComparator;
import org.apache.camel.support.PatternHelper;
import org.apache.camel.util.StringHelper;
import org.apache.camel.util.concurrent.ThreadPoolRejectedPolicy;
@@ -565,26 +566,32 @@ public abstract class AbstractCamelContextFactoryBean<T
extends ModelCamelContex
List<RouteConfigurationDefinition> globalConfigurations
=
getContext().adapt(ModelCamelContext.class).getRouteConfigurationDefinitions();
if (globalConfigurations != null) {
- globalConfigurations.stream()
- // global configurations have no id assigned or is
a wildcard
- // if the route has a route configuration assigned
then use pattern matching
- .filter(g -> {
- if (route.getRouteConfigurationId() != null) {
- return
PatternHelper.matchPattern(g.getId(), route.getRouteConfigurationId());
- } else {
- return g.getId() == null ||
g.getId().equals("*");
- }
- })
- .forEach(g -> {
- String id = g.getId() == null ? "<default>" :
g.getId();
- // remember the id that was used on the route
- route.addAppliedRouteConfigurationId(id);
- oe.addAll(g.getOnExceptions());
- icp.addAll(g.getIntercepts());
- ifrom.addAll(g.getInterceptFroms());
- ito.addAll(g.getInterceptSendTos());
- oc.addAll(g.getOnCompletions());
- });
+ // if there are multiple ids configured then we should
apply in that same order
+ String[] ids = route.getRouteConfigurationId() != null
+ ? route.getRouteConfigurationId().split(",") : new
String[] { "*" };
+ for (String id : ids) {
+ // sort according to ordered
+
globalConfigurations.stream().sorted(OrderedComparator.get())
+ .filter(g -> {
+ if (route.getRouteConfigurationId() !=
null) {
+ // if the route has a route
configuration assigned then use pattern matching
+ return
PatternHelper.matchPattern(g.getId(), id);
+ } else {
+ // global configurations have no id
assigned or is a wildcard
+ return g.getId() == null ||
g.getId().equals(id);
+ }
+ })
+ .forEach(g -> {
+ String aid = g.getId() == null ?
"<default>" : g.getId();
+ // remember the id that was used on the
route
+ route.addAppliedRouteConfigurationId(aid);
+ oe.addAll(g.getOnExceptions());
+ icp.addAll(g.getIntercepts());
+ ifrom.addAll(g.getInterceptFroms());
+ ito.addAll(g.getInterceptSendTos());
+ oc.addAll(g.getOnCompletions());
+ });
+ }
}
}