-
Bug
-
Resolution: Not a Bug
-
Critical
-
None
-
None
-
None
-
False
-
-
False
-
-
-
-
0
When using Camel Templated Routes with multiple instances of the same route-template, the Advicewith method does not respect the routeId and applies the pattern to all routes and endpoints with the same pattern.
routeTemplate("rouEmailSender") .templateParameter("username") .templateParameter("input") .templateParameter("output") .route() .from("{{input}}") .log("{{input}}: got message ${body}") .to("smtp:{{username}}@adesso.de") .to("{{output}}"); templatedRoute("rouEmailSender") .routeId("rouInput1") .parameter("input","direct:input1") .parameter("username","test1") .parameter("output","direct:input2"); templatedRoute("rouEmailSender") .routeId("rouInput2") .parameter("input","direct:input2") .parameter("username","test2") .parameter("output","mock:final"); }
Test
@QuarkusTest public class AppRouteBuilderTest extends CamelQuarkusTestSupport { @Override public boolean isUseAdviceWith() { return true; } @Override public boolean isUseDebugger() { return true; } @Override protected void doPostSetup() throws Exception { super.doPostSetup(); AdviceWith.adviceWith(context, "rouInput1", a -> a.weaveByToUri("smtp*").replace().to("mock:out1")); //the issue is with below line AdviceWith.adviceWith(context, "rouInput2", b -> b.weaveByToUri("smtp*").replace().to("mock:out2")); startRouteDefinitions(); } @Test void testHappyFlow() throws InterruptedException { var mockSmtp1 = getMockEndpoint("mock:out1", false); var mockSmtp2 = getMockEndpoint("mock:out2", false); var mockFinal = getMockEndpoint("mock:final", false); // Set expectations mockSmtp1.setExpectedCount(1); mockSmtp2.setExpectedCount(1); mockFinal.setExpectedCount(1); // Start Test var input1 = context.getEndpoint("direct:input1"); Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("Body from test"); Exchange result = template.send(input1, exchange); // Verify mockSmtp1.assertIsSatisfied(); mockSmtp2.assertIsSatisfied(); mockFinal.assertIsSatisfied(); assertEquals("Body from test", result.getIn().getBody(String.class)); } }
Log:
2022-12-09 09:44:59,103 INFO [org.apa.cam.bui.AdviceWith] (main) AdviceWith route after: Route(rouInput1)[From[{{input}}] -> [Log[{{input}}: got message ${body}], To[mock:out1], To[{{output}}]]] 2022-12-09 09:44:59,105 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Stopped rouInput2 (direct://input2) 2022-12-09 09:44:59,106 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Shutdown rouInput2 (direct://input2) 2022-12-09 09:44:59,108 INFO [org.apa.cam.tes.jun.CamelTestSupport] (main) ******************************************************************************** 2022-12-09 09:44:59,108 INFO [org.apa.cam.tes.jun.CamelTestSupport] (main) Testing done: testHappyFlow() (de.adesso.issuecameladvicewith.AppRouteBuilderTest) 2022-12-09 09:44:59,108 INFO [org.apa.cam.tes.jun.CamelTestSupport] (main) Took: 60ms (60 millis) 2022-12-09 09:44:59,108 INFO [org.apa.cam.tes.jun.CamelTestSupport] (main) ******************************************************************************** 2022-12-09 09:44:59,285 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Routes stopped (stopped:1) 2022-12-09 09:44:59,285 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Stopped rouInput1 (direct://input1) [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.666 s <<< FAILURE! - in de.adesso.issuecameladvicewith.AppRouteBuilderTest [ERROR] de.adesso.issuecameladvicewith.AppRouteBuilderTest.testHappyFlow Time elapsed: 0.236 s <<< ERROR! java.lang.IllegalArgumentException: There are no outputs which matches: smtp* in the route: Route(rouInput2)[From[{{input}}] -> [Log[{{input}}: got message ${body}], To[mock:out1], To[{{output}}]]] at org.apache.camel.builder.AdviceWithTasks$1.task(AdviceWithTasks.java:226) at org.apache.camel.builder.AdviceWith.doAdviceWith(AdviceWith.java:222) at org.apache.camel.builder.AdviceWith.adviceWith(AdviceWith.java:75) at de.adesso.issuecameladvicewith.AppRouteBuilderTest.doPostSetup(AppRouteBuilderTest.java:28) at org.apache.camel.test.junit5.CamelTestSupport.setUp(CamelTestSupport.java:385) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)