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

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


The following commit(s) were added to refs/heads/master by this push:
     new 7dc1286  CAMEL-14852: Fixed endpointdsl to support property 
placeholders.
7dc1286 is described below

commit 7dc12868a4d60f3c0a2144d0dceb11f04967a1e2
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Apr 7 10:59:48 2020 +0200

    CAMEL-14852: Fixed endpointdsl to support property placeholders.
---
 .../builder/endpoint/AbstractEndpointBuilder.java  | 21 +++++++++++++---
 ...va => NormalizedUrPropertyPlaceholderTest.java} | 28 ++++++++++++++++++----
 .../camel/builder/endpoint/NormalizedUriTest.java  |  4 +++-
 3 files changed, 44 insertions(+), 9 deletions(-)

diff --git 
a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/AbstractEndpointBuilder.java
 
b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/AbstractEndpointBuilder.java
index 660f346..f11a431 100644
--- 
a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/AbstractEndpointBuilder.java
+++ 
b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/AbstractEndpointBuilder.java
@@ -70,7 +70,13 @@ public class AbstractEndpointBuilder {
         for (Map.Entry<String, Object> entry : properties.entrySet()) {
             String key = entry.getKey();
             Object val = entry.getValue();
-            if (val instanceof String || val instanceof Number || val 
instanceof Boolean || val instanceof Enum<?>) {
+            if (val instanceof String) {
+                String text = val.toString();
+                if (camelContext != null) {
+                    text = camelContext.resolvePropertyPlaceholders(text);
+                }
+                params.put(key, text);
+            } else if (val instanceof Number || val instanceof Boolean || val 
instanceof Enum<?>) {
                 params.put(key, val.toString());
             } else if (camelContext != null && bindToRegistry) {
                 String hash = Integer.toHexString(val.hashCode());
@@ -83,12 +89,21 @@ public class AbstractEndpointBuilder {
         if (!remaining.isEmpty()) {
             params.put("hash", Integer.toHexString(remaining.hashCode()));
         }
+
+        // ensure property placeholders is also resolved on scheme and path
+        String targetScheme = scheme;
+        String targetPath = path;
+        if (camelContext != null) {
+            targetScheme = camelContext.resolvePropertyPlaceholders(scheme);
+            targetPath = camelContext.resolvePropertyPlaceholders(path);
+        }
+
         if (params.isEmpty()) {
-            answer = new NormalizedUri(scheme + "://" + path);
+            answer = new NormalizedUri(targetScheme + "://" + targetPath);
         } else {
             try {
                 String query = URISupport.createQueryString(params);
-                answer = new NormalizedUri(scheme + "://" + path + "?" + 
query);
+                answer = new NormalizedUri(targetScheme + "://" + targetPath + 
"?" + query);
             } catch (URISyntaxException e) {
                 throw RuntimeCamelException.wrapRuntimeCamelException(e);
             }
diff --git 
a/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/NormalizedUriTest.java
 
b/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/NormalizedUrPropertyPlaceholderTest.java
similarity index 69%
copy from 
core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/NormalizedUriTest.java
copy to 
core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/NormalizedUrPropertyPlaceholderTest.java
index bf6ad1a..756840a 100644
--- 
a/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/NormalizedUriTest.java
+++ 
b/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/NormalizedUrPropertyPlaceholderTest.java
@@ -16,33 +16,51 @@
  */
 package org.apache.camel.builder.endpoint;
 
+import java.util.Properties;
+
+import org.apache.camel.CamelContext;
 import org.apache.camel.EndpointInject;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class NormalizedUriTest extends CamelTestSupport {
+public class NormalizedUrPropertyPlaceholderTest extends CamelTestSupport {
 
-    @EndpointInject(value = "mock:result")
+    @EndpointInject(value = "mock:result?failFast=false")
     private MockEndpoint result;
 
     @Override
+    protected CamelContext createCamelContext() throws Exception {
+        Properties initial = new Properties();
+        initial.setProperty("foo", "test");
+        initial.setProperty("bar", "result");
+        initial.setProperty("fast", "false");
+
+        CamelContext context = super.createCamelContext();
+        context.getPropertiesComponent().setInitialProperties(initial);
+        return context;
+    }
+
+    @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new EndpointRouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from(direct("test")).to(mock("result"));
+                
from(direct("{{foo}}")).to(mock("{{bar}}").failFast("{{fast}}"));
             }
         };
     }
 
     @Test
     public void test() throws Exception {
-        template.sendBody("direct:test", null);
-        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
+        MockEndpoint resultEndpoint = 
getMockEndpoint("mock:result?failFast=false");
         resultEndpoint.expectedMessageCount(1);
+
+        template.sendBody("direct:test", null);
+
         assertMockEndpointsSatisfied();
+
         assertEquals(result, resultEndpoint);
     }
 }
diff --git 
a/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/NormalizedUriTest.java
 
b/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/NormalizedUriTest.java
index bf6ad1a..27ad1cf 100644
--- 
a/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/NormalizedUriTest.java
+++ 
b/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/NormalizedUriTest.java
@@ -39,9 +39,11 @@ public class NormalizedUriTest extends CamelTestSupport {
 
     @Test
     public void test() throws Exception {
-        template.sendBody("direct:test", null);
         MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
         resultEndpoint.expectedMessageCount(1);
+
+        template.sendBody("direct:test", null);
+
         assertMockEndpointsSatisfied();
         assertEquals(result, resultEndpoint);
     }

Reply via email to