You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/08/07 08:43:09 UTC

[camel] branch camel-3.18.x updated (a97bfba6837 -> 4d72f6543dc)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


    from a97bfba6837 Backport CAMEL-18347 (#8118)
     new 452d2165d60 CAMEL-18328 - Fixing template parameter to configurationId
     new 4d72f6543dc CAMEL-18328: Polished

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/camel/model/RoutesDefinition.java   | 26 ++++++++++++++++--
 .../model/RouteConfigurationOnExceptionTest.java   | 32 ++++++++++++++++++++--
 2 files changed, 54 insertions(+), 4 deletions(-)


[camel] 02/02: CAMEL-18328: Polished

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 4d72f6543dcb609b12f09b7d518e6948b7cb37aa
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Aug 7 10:35:00 2022 +0200

    CAMEL-18328: Polished
---
 .../org/apache/camel/model/RoutesDefinition.java   | 24 +++++++++++++---------
 .../model/RouteConfigurationOnExceptionTest.java   |  3 ---
 2 files changed, 14 insertions(+), 13 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 c39cc78e045..1a5b26e0498 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
@@ -255,25 +255,29 @@ public class RoutesDefinition extends OptionalIdentifiedDefinition<RoutesDefinit
             List<RouteConfigurationDefinition> globalConfigurations
                     = getCamelContext().adapt(ModelCamelContext.class).getRouteConfigurationDefinitions();
             if (globalConfigurations != null) {
-
-                // if there are multiple ids configured then we should apply in that same order
                 String[] ids;
                 if (route.getRouteConfigurationId() != null) {
-                    // if the RouteConfigurationId was configured with property placeholder it should be resolved
+                    // if the RouteConfigurationId was configured with property placeholder it should be resolved first
+                    // and include properties sources from the template parameters
                     if (route.getTemplateParameters() != null && route.getRouteConfigurationId().startsWith("{{")) {
-                        OrderedLocationProperties locationProperties = new OrderedLocationProperties();
-                        locationProperties.putAll("TemplateProperties", new HashMap<>(route.getTemplateParameters()));
-                        camelContext.getPropertiesComponent().setLocalProperties(locationProperties);
-                        ids = camelContext.adapt(ExtendedCamelContext.class)
-                                .resolvePropertyPlaceholders(route.getRouteConfigurationId(), true)
-                                .split(",");
+                        OrderedLocationProperties props = new OrderedLocationProperties();
+                        props.putAll("TemplateProperties", new HashMap<>(route.getTemplateParameters()));
+                        camelContext.getPropertiesComponent().setLocalProperties(props);
+                        try {
+                            ids = camelContext.adapt(ExtendedCamelContext.class)
+                                    .resolvePropertyPlaceholders(route.getRouteConfigurationId(), true)
+                                    .split(",");
+                        } finally {
+                            camelContext.getPropertiesComponent().setLocalProperties(null);
+                        }
                     } else {
                         ids = route.getRouteConfigurationId().split(",");
                     }
                 } else {
-                    ids = new String[] { "*" };
+                    ids = new String[]{"*"};
                 }
 
+                // if there are multiple ids configured then we should apply in that same order
                 for (String id : ids) {
                     // sort according to ordered
                     globalConfigurations.stream().sorted(OrderedComparator.get())
diff --git a/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnExceptionTest.java b/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnExceptionTest.java
index 0bcbb0e7bab..03b29874031 100644
--- a/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnExceptionTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnExceptionTest.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.model;
 
 import org.apache.camel.ContextTestSupport;
@@ -88,7 +87,6 @@ public class RouteConfigurationOnExceptionTest extends ContextTestSupport {
 
     @Test
     void testRouteTemplateCanSupportRouteConfiguration() throws Exception {
-
         getMockEndpoint("mock:result").expectedMessageCount(1);
         getMockEndpoint("mock:result").expectedBodiesReceived("Error Received");
         template.sendBody("direct:start-template", "foo");
@@ -97,7 +95,6 @@ public class RouteConfigurationOnExceptionTest extends ContextTestSupport {
 
     @Test
     void testRouteTemplateCanSupportRouteConfigurationWithParameter() throws Exception {
-
         getMockEndpoint("mock:result").expectedMessageCount(1);
         getMockEndpoint("mock:result").expectedBodiesReceived("Error Received");
         template.sendBody("direct:start-template-parameter", "foo");


[camel] 01/02: CAMEL-18328 - Fixing template parameter to configurationId

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 452d2165d60914eaf2980f2c761cfaa824d17ca1
Author: Rhuan Rocha <rh...@gmail.com>
AuthorDate: Fri Aug 5 12:19:23 2022 -0300

    CAMEL-18328 - Fixing template parameter to configurationId
    
    Signed-off-by: Rhuan Rocha <rh...@gmail.com>
---
 .../org/apache/camel/model/RoutesDefinition.java   | 22 +++++++++++++--
 .../model/RouteConfigurationOnExceptionTest.java   | 31 ++++++++++++++++++++++
 2 files changed, 51 insertions(+), 2 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 d1dd9ec93eb..c39cc78e045 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
@@ -17,6 +17,7 @@
 package org.apache.camel.model;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicReference;
 
@@ -30,6 +31,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.Endpoint;
 import org.apache.camel.ErrorHandlerFactory;
+import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.builder.EndpointConsumerBuilder;
 import org.apache.camel.spi.AsEndpointUri;
 import org.apache.camel.spi.Metadata;
@@ -37,6 +39,7 @@ import org.apache.camel.spi.Resource;
 import org.apache.camel.spi.ResourceAware;
 import org.apache.camel.support.OrderedComparator;
 import org.apache.camel.support.PatternHelper;
+import org.apache.camel.util.OrderedLocationProperties;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -254,8 +257,23 @@ public class RoutesDefinition extends OptionalIdentifiedDefinition<RoutesDefinit
             if (globalConfigurations != null) {
 
                 // if there are multiple ids configured then we should apply in that same order
-                String[] ids = route.getRouteConfigurationId() != null
-                        ? route.getRouteConfigurationId().split(",") : new String[] { "*" };
+                String[] ids;
+                if (route.getRouteConfigurationId() != null) {
+                    // if the RouteConfigurationId was configured with property placeholder it should be resolved
+                    if (route.getTemplateParameters() != null && route.getRouteConfigurationId().startsWith("{{")) {
+                        OrderedLocationProperties locationProperties = new OrderedLocationProperties();
+                        locationProperties.putAll("TemplateProperties", new HashMap<>(route.getTemplateParameters()));
+                        camelContext.getPropertiesComponent().setLocalProperties(locationProperties);
+                        ids = camelContext.adapt(ExtendedCamelContext.class)
+                                .resolvePropertyPlaceholders(route.getRouteConfigurationId(), true)
+                                .split(",");
+                    } else {
+                        ids = route.getRouteConfigurationId().split(",");
+                    }
+                } else {
+                    ids = new String[] { "*" };
+                }
+
                 for (String id : ids) {
                     // sort according to ordered
                     globalConfigurations.stream().sorted(OrderedComparator.get())
diff --git a/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnExceptionTest.java b/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnExceptionTest.java
index 215b714b142..0bcbb0e7bab 100644
--- a/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnExceptionTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnExceptionTest.java
@@ -37,6 +37,18 @@ public class RouteConfigurationOnExceptionTest extends ContextTestSupport {
                                 .throwException(RuntimeException.class, "Expected Error");
                     }
                 },
+                new RouteBuilder() {
+                    @Override
+                    public void configure() {
+                        routeTemplate("route-template-parameter")
+                                .templateParameter("configuration-id")
+                                .templateParameter("route-id")
+                                .from("direct:start-template-parameter")
+                                .routeId("{{route-id}}")
+                                .routeConfigurationId("{{configuration-id}}")
+                                .throwException(RuntimeException.class, "Expected Error");
+                    }
+                },
                 new RouteBuilder() {
                     @Override
                     public void configure() {
@@ -45,6 +57,16 @@ public class RouteConfigurationOnExceptionTest extends ContextTestSupport {
                                 .add();
                     }
                 },
+                new RouteBuilder() {
+                    @Override
+                    public void configure() {
+                        TemplatedRouteBuilder.builder(context, "route-template-parameter")
+                                .routeId("my-test-file-route-parameter")
+                                .parameter("configuration-id", "my-error-handler")
+                                .parameter("route-id", "custom-route-id")
+                                .add();
+                    }
+                },
                 new RouteBuilder() {
                     @Override
                     public void configure() {
@@ -73,6 +95,15 @@ public class RouteConfigurationOnExceptionTest extends ContextTestSupport {
         assertMockEndpointsSatisfied();
     }
 
+    @Test
+    void testRouteTemplateCanSupportRouteConfigurationWithParameter() throws Exception {
+
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+        getMockEndpoint("mock:result").expectedBodiesReceived("Error Received");
+        template.sendBody("direct:start-template-parameter", "foo");
+        assertMockEndpointsSatisfied();
+    }
+
     @Test
     void testNormalRouteCanSupportRouteConfiguration() throws Exception {
         getMockEndpoint("mock:result").expectedMessageCount(1);