CAMEL-16823: kamelets should support dynamic endpoints from toD
diff --git a/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletRecipientListTest.java b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletRecipientListTest.java
new file mode 100644
index 0000000..2121508
--- /dev/null
+++ b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletRecipientListTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.kamelet;
+
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+public class KameletRecipientListTest extends CamelTestSupport {
+
+ @Test
+ public void testRecipientList() throws Exception {
+ getMockEndpoint("mock:foo").expectedBodiesReceived("A");
+ getMockEndpoint("mock:bar").expectedBodiesReceived("B");
+
+ template.sendBody("direct:foo", "A");
+ template.sendBody("direct:bar", "B");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ // **********************************************
+ //
+ // test set-up
+ //
+ // **********************************************
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ routeTemplate("broker")
+ .templateParameter("queue")
+ .from("kamelet:source")
+ .recipientList(constant("mock:{{queue}}"));
+
+ from("direct:foo")
+ .kamelet("broker?queue=foo");
+
+ from("direct:bar")
+ .kamelet("broker?queue=bar");
+ }
+ };
+ }
+}
diff --git a/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletToDTest.java b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletToDTest.java
index dce4dc6..e72e32f 100644
--- a/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletToDTest.java
+++ b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletToDTest.java
@@ -19,10 +19,8 @@
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit5.CamelTestSupport;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
-@Disabled
public class KameletToDTest extends CamelTestSupport {
@Test
@@ -50,7 +48,7 @@
routeTemplate("broker")
.templateParameter("queue")
.from("kamelet:source")
- .toD("seda:{{name}}");
+ .toD("mock:{{queue}}");
from("direct:foo")
.kamelet("broker?queue=foo");
diff --git a/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletWireTapTest.java b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletWireTapTest.java
new file mode 100644
index 0000000..ff64836
--- /dev/null
+++ b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletWireTapTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.kamelet;
+
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+public class KameletWireTapTest extends CamelTestSupport {
+
+ @Test
+ public void testWireTap() throws Exception {
+ getMockEndpoint("mock:foo").expectedBodiesReceived("A");
+ getMockEndpoint("mock:bar").expectedBodiesReceived("B");
+
+ template.sendBody("direct:foo", "A");
+ template.sendBody("direct:bar", "B");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ // **********************************************
+ //
+ // test set-up
+ //
+ // **********************************************
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ routeTemplate("broker")
+ .templateParameter("queue")
+ .from("kamelet:source")
+ .wireTap("mock:{{queue}}");
+
+ from("direct:foo")
+ .kamelet("broker?queue=foo");
+
+ from("direct:bar")
+ .kamelet("broker?queue=bar");
+ }
+ };
+ }
+}
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ToDynamicReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ToDynamicReifier.java
index fc4ad92..aece53b 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ToDynamicReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ToDynamicReifier.java
@@ -21,6 +21,8 @@
import org.apache.camel.Processor;
import org.apache.camel.Route;
import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.ProcessorDefinitionHelper;
+import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.ToDynamicDefinition;
import org.apache.camel.processor.SendDynamicProcessor;
import org.apache.camel.spi.Language;
@@ -45,6 +47,12 @@
exp = createExpression(uri);
}
+ // route templates should pre parse uri as they have dynamic values as part of their template parameters
+ RouteDefinition rd = ProcessorDefinitionHelper.getRoute(definition);
+ if (rd != null && rd.isTemplate() != null && rd.isTemplate()) {
+ uri = EndpointHelper.resolveEndpointUriPropertyPlaceholders(camelContext, uri);
+ }
+
SendDynamicProcessor processor = new SendDynamicProcessor(uri, exp);
processor.setCamelContext(camelContext);
processor.setPattern(parse(ExchangePattern.class, definition.getPattern()));
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java
index 23a7508..c43c592 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java
@@ -26,12 +26,15 @@
import org.apache.camel.Processor;
import org.apache.camel.Route;
import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.ProcessorDefinitionHelper;
+import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.SetHeaderDefinition;
import org.apache.camel.model.WireTapDefinition;
import org.apache.camel.processor.SendDynamicProcessor;
import org.apache.camel.processor.SendProcessor;
import org.apache.camel.processor.WireTapProcessor;
import org.apache.camel.support.CamelContextHelper;
+import org.apache.camel.support.EndpointHelper;
import org.apache.camel.support.LanguageSupport;
import org.apache.camel.util.StringHelper;
@@ -58,6 +61,12 @@
uri = StringHelper.notEmpty(definition.getUri(), "uri", this);
}
+ // route templates should pre parse uri as they have dynamic values as part of their template parameters
+ RouteDefinition rd = ProcessorDefinitionHelper.getRoute(definition);
+ if (rd != null && rd.isTemplate() != null && rd.isTemplate()) {
+ uri = EndpointHelper.resolveEndpointUriPropertyPlaceholders(camelContext, uri);
+ }
+
SendDynamicProcessor dynamicSendProcessor = null;
SendProcessor sendProcessor = null;
boolean simple = LanguageSupport.hasSimpleFunction(definition.getUri());