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 e00d290 CAMEL-16241: Fixed endpoint-dsl should resolve property
placeholders earlier and in properties so the components always have
placeholders resolved early. Thanks to David Voit for reporting and the
reproducer.
e00d290 is described below
commit e00d2905c47c9265125553e34bd4a4d0599990be
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Mar 2 10:33:07 2021 +0100
CAMEL-16241: Fixed endpoint-dsl should resolve property placeholders
earlier and in properties so the components always have placeholders resolved
early. Thanks to David Voit for reporting and the reproducer.
---
.../builder/endpoint/AbstractEndpointBuilder.java | 22 +++++++++++++++++-----
.../camel/builder/endpoint/HttpsBasicAuthTest.java | 6 +++---
2 files changed, 20 insertions(+), 8 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 4aa08d6..b6f24aa 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
@@ -51,6 +51,9 @@ public class AbstractEndpointBuilder {
return resolvedEndpoint;
}
+ // properties may contain property placeholder which should be resolved
+ resolvePropertyPlaceholders(context, properties);
+
Map<String, Object> remaining = new LinkedHashMap<>();
// we should not bind complex objects to registry as we create the
endpoint via the properties as-is
NormalizedEndpointUri uri = computeUri(remaining, context, false,
true);
@@ -64,6 +67,19 @@ public class AbstractEndpointBuilder {
return endpoint;
}
+ private static void resolvePropertyPlaceholders(CamelContext context,
Map<String, Object> properties) {
+ for (Map.Entry<String, Object> entry : properties.entrySet()) {
+ Object value = entry.getValue();
+ if (value instanceof String) {
+ String text = (String) value;
+ String changed = context.resolvePropertyPlaceholders(text);
+ if (!changed.equals(text)) {
+ entry.setValue(changed);
+ }
+ }
+ }
+ }
+
public <T extends Endpoint> T resolve(CamelContext context, Class<T>
endpointType) throws NoSuchEndpointException {
Endpoint answer = resolve(context);
return endpointType.cast(answer);
@@ -122,11 +138,7 @@ public class AbstractEndpointBuilder {
String key = entry.getKey();
Object val = entry.getValue();
if (val instanceof String) {
- String text = val.toString();
- if (camelContext != null) {
- text = camelContext.resolvePropertyPlaceholders(text);
- }
- params.put(key, text);
+ params.put(key, val);
} else if (val instanceof Number || val instanceof Boolean || val
instanceof Enum<?>) {
params.put(key, val.toString());
} else if (camelContext != null && bindToRegistry) {
diff --git
a/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/HttpsBasicAuthTest.java
b/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/HttpsBasicAuthTest.java
index 7ec754a..6d82ba7 100644
---
a/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/HttpsBasicAuthTest.java
+++
b/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/HttpsBasicAuthTest.java
@@ -16,14 +16,14 @@
*/
package org.apache.camel.builder.endpoint;
+import java.util.Properties;
+
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Endpoint;
import org.apache.camel.builder.endpoint.dsl.HttpEndpointBuilderFactory;
import org.apache.camel.component.http.HttpEndpoint;
import org.junit.jupiter.api.Test;
-import java.util.Properties;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -48,7 +48,7 @@ public class HttpsBasicAuthTest extends ContextTestSupport {
public void configure() throws Exception {
HttpEndpointBuilderFactory.HttpEndpointBuilder builder
=
https("inline").authenticationPreemptive(true).authMethod("Basic")
-
.authUsername("{{prop.username}}").authPassword("{{prop.password}}");
+
.authUsername("{{prop.username}}").authPassword("{{prop.password}}");
Endpoint endpoint = builder.resolve(context);
assertNotNull(endpoint);