This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-3.7.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit bab7ebafd4a0391347ff922796eab4a38f511558 Author: Claus Ibsen <[email protected]> AuthorDate: Thu Feb 4 09:26:01 2021 +0100 CAMEL-16083: Route Scoped OnCompletion After Consumer routeId check --- .../java/org/apache/camel/ExchangeConstantProvider.java | 3 ++- .../apache/camel/processor/OnCompletionProcessor.java | 17 ++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java b/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java index a1380d5..0c541a8 100644 --- a/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java +++ b/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java @@ -11,7 +11,7 @@ public class ExchangeConstantProvider { private static final Map<String, String> MAP; static { - Map<String, String> map = new HashMap<>(149); + Map<String, String> map = new HashMap<>(150); map.put("ACCEPT_CONTENT_TYPE", "CamelAcceptContentType"); map.put("AGGREGATED_COLLECTION_GUARD", "CamelAggregatedCollectionGuard"); map.put("AGGREGATED_COMPLETED_BY", "CamelAggregatedCompletedBy"); @@ -113,6 +113,7 @@ public class ExchangeConstantProvider { map.put("MULTICAST_INDEX", "CamelMulticastIndex"); map.put("NOTIFY_EVENT", "CamelNotifyEvent"); map.put("ON_COMPLETION", "CamelOnCompletion"); + map.put("ON_COMPLETION_ROUTE_IDS", "CamelOnCompletionRouteIds"); map.put("OVERRULE_FILE_NAME", "CamelOverruleFileName"); map.put("PARENT_UNIT_OF_WORK", "CamelParentUnitOfWork"); map.put("RECEIVED_TIMESTAMP", "CamelReceivedTimestamp"); diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java index 3083c9c..6101e8c 100644 --- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java +++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java @@ -252,30 +252,33 @@ public class OnCompletionProcessor extends AsyncProcessorSupport implements Trac } @Override + @SuppressWarnings("unchecked") public void onAfterRoute(Route route, Exchange exchange) { - // route scope = should be from this route + // route scope = remember we have been at this route if (routeScoped && route.getRouteId().equals(routeId)) { - List routeIds = exchange.getProperty(Exchange.ON_COMPLETION_ROUTE_IDS, List.class); + List<String> routeIds = exchange.getProperty(Exchange.ON_COMPLETION_ROUTE_IDS, List.class); if (routeIds == null) { routeIds = new ArrayList<>(); exchange.setProperty(Exchange.ON_COMPLETION_ROUTE_IDS, routeIds); } routeIds.add(route.getRouteId()); - } } @Override + @SuppressWarnings("unchecked") public void onComplete(final Exchange exchange) { String currentRouteId = ExchangeHelper.getRouteId(exchange); if (!routeScoped && currentRouteId != null && !routeId.equals(currentRouteId)) { return; } - List routeIds = exchange.getProperty(Exchange.ON_COMPLETION_ROUTE_IDS, List.class); - - if (routeScoped && (routeIds == null || !routeIds.contains(routeId))) { - return; + if (routeScoped) { + // check if we visited the route + List<String> routeIds = exchange.getProperty(Exchange.ON_COMPLETION_ROUTE_IDS, List.class); + if (routeIds == null || !routeIds.contains(routeId)) { + return; + } } if (onFailureOnly) {
