From 0552946facfd6316aaf2bd153d60184ebe2acdd6 Mon Sep 17 00:00:00 2001 From: James Netherton Date: Wed, 20 Nov 2024 11:39:41 +0000 Subject: [PATCH] Filter AdviceWithRouteBuilder types from build time route discovery Fixes #6807 --- .../core/deployment/CamelProcessor.java | 10 +++----- .../component/mock/it/MockResource.java | 25 +++++++++---------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java index b36c18eb8326..e51892d0e71f 100644 --- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java +++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java @@ -90,8 +90,6 @@ class CamelProcessor { private static final DotName ROUTES_BUILDER_TYPE = DotName.createSimple( "org.apache.camel.RoutesBuilder"); - private static final DotName ROUTE_BUILDER_TYPE = DotName.createSimple( - "org.apache.camel.builder.RouteBuilder"); private static final DotName LAMBDA_ROUTE_BUILDER_TYPE = DotName.createSimple( "org.apache.camel.builder.LambdaRouteBuilder"); private static final DotName LAMBDA_ENDPOINT_ROUTE_BUILDER_TYPE = DotName.createSimple( @@ -386,10 +384,10 @@ public List discoverRoutesBuilderClassNames( final IndexView index = combinedIndex.getIndex(); - Set allKnownImplementors = new HashSet<>(); - allKnownImplementors.addAll(index.getAllKnownImplementors(ROUTES_BUILDER_TYPE)); - allKnownImplementors.addAll(index.getAllKnownSubclasses(ROUTE_BUILDER_TYPE)); - allKnownImplementors.addAll(index.getAllKnownSubclasses(ADVICE_WITH_ROUTE_BUILDER_TYPE)); + Set allKnownImplementors = index.getAllKnownImplementors(ROUTES_BUILDER_TYPE) + .stream() + .filter(classInfo -> !classInfo.superName().equals(ADVICE_WITH_ROUTE_BUILDER_TYPE)) + .collect(Collectors.toSet()); final Predicate pathFilter = new PathFilter.Builder() .exclude( diff --git a/integration-test-groups/foundation/mock/src/main/java/org/apache/camel/quarkus/component/mock/it/MockResource.java b/integration-test-groups/foundation/mock/src/main/java/org/apache/camel/quarkus/component/mock/it/MockResource.java index d9fd66e16980..d7f1c644dd23 100644 --- a/integration-test-groups/foundation/mock/src/main/java/org/apache/camel/quarkus/component/mock/it/MockResource.java +++ b/integration-test-groups/foundation/mock/src/main/java/org/apache/camel/quarkus/component/mock/it/MockResource.java @@ -29,7 +29,6 @@ import org.apache.camel.builder.AdviceWith; import org.apache.camel.builder.AdviceWithRouteBuilder; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.model.ModelCamelContext; import org.jboss.logging.Logger; import org.wildfly.common.Assert; @@ -48,18 +47,11 @@ public class MockResource { @Path("/advice") @GET public void advice() throws Exception { - // advice the first route using the inlined AdviceWith route builder // which has extended capabilities than the regular route builder - AdviceWith.adviceWith(((ModelCamelContext) context).getRouteDefinition("forMocking"), context, - new AdviceWithRouteBuilder() { - @Override - public void configure() throws Exception { - mockEndpoints("direct:mock.*", "log:mock.*"); - } - }); + AdviceWith.adviceWith("forMocking", context, new RouteAdvisor()); - MockEndpoint mockEndpoint1 = context.getEndpoint("mock:direct:mockStart", MockEndpoint.class); + MockEndpoint mockEndpoint1 = context.getEndpoint("mock:direct:mockStartAdvised", MockEndpoint.class); mockEndpoint1.expectedBodiesReceived("Hello World"); MockEndpoint mockEndpoint2 = context.getEndpoint("mock:direct:mockFoo", MockEndpoint.class); mockEndpoint2.expectedBodiesReceived("Hello World"); @@ -68,7 +60,7 @@ public void configure() throws Exception { MockEndpoint mockEndpoint4 = context.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint4.expectedBodiesReceived("Bye World"); - producerTemplate.sendBody("direct:mockStart", "Hello World"); + producerTemplate.sendBody("direct:mockStartAdvised", "Hello World"); mockEndpoint1.assertIsSatisfied(); mockEndpoint2.assertIsSatisfied(); @@ -76,12 +68,12 @@ public void configure() throws Exception { mockEndpoint4.assertIsSatisfied(); // test to ensure correct endpoints in registry - Assert.assertNotNull(context.hasEndpoint("direct:mockStart")); + Assert.assertNotNull(context.hasEndpoint("direct:mockStartAdvised")); Assert.assertNotNull(context.hasEndpoint("direct:mockFoo")); Assert.assertNotNull(context.hasEndpoint("log:mockFoo")); Assert.assertNotNull(context.hasEndpoint("mock:result")); // all the endpoints was mocked - Assert.assertNotNull(context.hasEndpoint("mock:direct:mockStart")); + Assert.assertNotNull(context.hasEndpoint("mock:direct:mockStartAdvised")); Assert.assertNotNull(context.hasEndpoint("mock:direct:mockFoo")); Assert.assertNotNull(context.hasEndpoint("mock:log:mockFoo")); } @@ -107,4 +99,11 @@ public String post(String message, @PathParam("route") String route) throws Exce return producerTemplate.requestBody("direct:" + route, message, String.class); } + public static class RouteAdvisor extends AdviceWithRouteBuilder { + @Override + public void configure() throws Exception { + replaceFromWith("direct:mockStartAdvised"); + mockEndpoints("direct:mock.*", "log:mock.*"); + } + } }