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/01/21 15:14:00 UTC

[camel] 04/04: CAMEL-17531: A better and general fix for CAMEL-17521 without hardcoding the prefix.

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

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

commit e606c8275083e7e9c936c489155ebf5268f1d27c
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jan 21 16:08:59 2022 +0100

    CAMEL-17531: A better and general fix for CAMEL-17521 without hardcoding the prefix.
---
 .../camel/component/http/HttpSendDynamicAware.java      | 17 -----------------
 .../support/component/SendDynamicAwareSupport.java      | 14 +++++++++++---
 2 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpSendDynamicAware.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpSendDynamicAware.java
index 4f21e58..7e76c0d 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpSendDynamicAware.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpSendDynamicAware.java
@@ -16,26 +16,9 @@
  */
 package org.apache.camel.component.http;
 
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.apache.camel.Exchange;
 import org.apache.camel.spi.annotations.SendDynamic;
 
 @SendDynamic("http,https")
 public class HttpSendDynamicAware extends org.apache.camel.http.base.HttpSendDynamicAware {
 
-    @Override
-    public Map<String, Object> endpointLenientProperties(Exchange exchange, String uri) throws Exception {
-        Map<String, Object> answer = new LinkedHashMap<>();
-
-        // workaround as we need to remove all prefix options as they are not part of lenient properties
-        Map<String, Object> properties = super.endpointLenientProperties(exchange, uri);
-        properties.forEach((k, v) -> {
-            if (!k.startsWith("httpClient.")) {
-                answer.put(k, v);
-            }
-        });
-        return answer;
-    }
 }
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/component/SendDynamicAwareSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/component/SendDynamicAwareSupport.java
index a868dcd..0120ef9 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/component/SendDynamicAwareSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/component/SendDynamicAwareSupport.java
@@ -35,6 +35,7 @@ public abstract class SendDynamicAwareSupport extends ServiceSupport implements
 
     private CamelContext camelContext;
     private Set<String> knownProperties;
+    private Set<String> knownPrefixes;
     private String scheme;
 
     @Override
@@ -64,13 +65,14 @@ public abstract class SendDynamicAwareSupport extends ServiceSupport implements
 
     @Override
     protected void doInit() throws Exception {
-        if (knownProperties == null) {
-            // optimize to eager load the list of known properties
+        if (knownProperties == null || knownPrefixes == null) {
+            // optimize to eager load the list of known properties/prefixes
             EndpointUriFactory factory = getCamelContext().adapt(ExtendedCamelContext.class).getEndpointUriFactory(getScheme());
             if (factory == null) {
                 throw new IllegalStateException("Cannot find EndpointUriFactory for component: " + getScheme());
             }
             knownProperties = factory.propertyNames();
+            knownPrefixes = factory.multiValuePrefixes();
         }
     }
 
@@ -112,7 +114,13 @@ public abstract class SendDynamicAwareSupport extends ServiceSupport implements
             }
             properties = new LinkedHashMap<>();
             map.forEach((k, v) -> {
-                if (!knownProperties.contains(k)) {
+                // we only accept if the key is not an existing known property
+                // or that the key is not from a multi-value (prefix)
+                boolean accept = !knownProperties.contains(k);
+                if (accept && !knownPrefixes.isEmpty()) {
+                    accept = knownPrefixes.stream().noneMatch(k::startsWith);
+                }
+                if (accept) {
                     properties.put(k, v.toString());
                 }
             });