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:43:25 UTC
[camel] branch camel-4.0.x updated: CAMEL-19814: camel-rest - Should filter out query parameters that are for the producer endpoint (#11250)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.0.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.0.x by this push:
new b0fa3e4bc96 CAMEL-19814: camel-rest - Should filter out query parameters that are for the producer endpoint (#11250)
b0fa3e4bc96 is described below
commit b0fa3e4bc96be3f36185dbd0d1be30e34b34ef62
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 31 11:42:41 2023 +0200
CAMEL-19814: camel-rest - Should filter out query parameters that are for the producer endpoint (#11250)
---
.../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);