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 2023/08/31 09:08:04 UTC

[camel] branch rest-known created (now 2d38b278313)

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

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


      at 2d38b278313 CAMEL-19814: camel-rest - Should filter out query parameters that are for the producer endpoint

This branch includes the following new commits:

     new 2d38b278313 CAMEL-19814: camel-rest - Should filter out query parameters that are for the producer endpoint

The 1 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.



[camel] 01/01: CAMEL-19814: camel-rest - Should filter out query parameters that are for the producer endpoint

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

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

commit 2d38b27831365fd3fd2804b87fac0861421c3f08
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 31 11:07:53 2023 +0200

    CAMEL-19814: camel-rest - Should filter out query parameters that are for the producer endpoint
---
 .../apache/camel/component/rest/RestComponent.java | 29 +++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestComponent.java b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestComponent.java
index 8b63431b457..fd29c7e8e34 100644
--- a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestComponent.java
+++ b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestComponent.java
@@ -21,11 +21,14 @@ import java.util.Map;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.component.extension.ComponentVerifierExtension;
+import org.apache.camel.spi.EndpointUriFactory;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.RestConfiguration;
+import org.apache.camel.spi.UriFactoryResolver;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.DefaultComponent;
 import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.StringHelper;
 import org.apache.camel.util.URISupport;
 
@@ -84,11 +87,24 @@ public class RestComponent extends DefaultComponent {
             // use only what remains and at this point parameters that have been used have been removed
             // without overwriting any query parameters set via queryParameters endpoint option
             final Map<String, Object> queryParameters = new LinkedHashMap<>(parameters);
+
+            // filter out known options from the producer, as they should not be in the query parameters
+            EndpointUriFactory factory = getEndpointUriFactory(pname);
+            if (factory != null) {
+                for (String key : parameters.keySet()) {
+                    if (factory.propertyNames().contains(key)) {
+                        queryParameters.remove(key);
+                    }
+                }
+            }
+
             final Map<String, Object> existingQueryParameters = URISupport.parseQuery(answer.getQueryParameters());
             queryParameters.putAll(existingQueryParameters);
 
             final String remainingParameters = URISupport.createQueryString(queryParameters);
-            answer.setQueryParameters(remainingParameters);
+            if (ObjectHelper.isNotEmpty(remainingParameters)) {
+                answer.setQueryParameters(remainingParameters);
+            }
         }
 
         answer.setParameters(parameters);
@@ -190,6 +206,17 @@ public class RestComponent extends DefaultComponent {
     // Helpers
     // ****************************************
 
+    private EndpointUriFactory getEndpointUriFactory(String name) {
+        if (name != null) {
+            UriFactoryResolver resolver
+                    = getCamelContext().getCamelContextExtension().getContextPlugin(UriFactoryResolver.class);
+            if (resolver != null) {
+                return resolver.resolveFactory(name, getCamelContext());
+            }
+        }
+        return null;
+    }
+
     public ComponentVerifierExtension getVerifier() {
         return (scope, parameters) -> getExtension(ComponentVerifierExtension.class)
                 .orElseThrow(UnsupportedOperationException::new).verify(scope, parameters);