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/09/28 14:07:36 UTC

[camel] branch main updated: CAMEL-19879: camel-rest- Add option to set headerfilterStrategy (#11437)

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


The following commit(s) were added to refs/heads/main by this push:
     new 2540a95a367 CAMEL-19879: camel-rest- Add option to set headerfilterStrategy (#11437)
2540a95a367 is described below

commit 2540a95a3679d796f1b55f0ebb9b29f8bfe0194e
Author: TUCJVXCB <39...@users.noreply.github.com>
AuthorDate: Thu Sep 28 22:07:29 2023 +0800

    CAMEL-19879: camel-rest- Add option to set headerfilterStrategy (#11437)
    
    * CAMEL-19879: camel-rest- Add option to set headerfilterStrategy
    
    * CAMEL-19879: update camel-rest docs
    
    * CAMEL-19879: update camel-rest docs
    
    * CAMEL-19879: adjust netty-http vertx-http
    
    * CAMEL-19879: Add missing files
    
    ---------
    
    Co-authored-by: tanyu <83...@qq.com>
---
 .../resources/org/apache/camel/catalog/components/rest.json    |  3 ++-
 .../java/org/apache/camel/component/http/HttpComponent.java    |  8 +++++++-
 .../apache/camel/component/netty/http/NettyHttpComponent.java  |  8 +++++++-
 .../apache/camel/component/rest/RestComponentConfigurer.java   |  6 ++++++
 .../resources/org/apache/camel/component/rest/rest.json        |  3 ++-
 components/camel-rest/src/main/docs/rest-component.adoc        |  4 ++++
 .../java/org/apache/camel/component/rest/RestComponent.java    | 10 ++++------
 .../apache/camel/component/vertx/http/VertxHttpComponent.java  | 10 ++++++++--
 8 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/rest.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/rest.json
index f3934fe42fe..71a3f2602c7 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/rest.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/rest.json
@@ -29,7 +29,8 @@
     "host": { "index": 3, "kind": "property", "displayName": "Host", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Host and port of HTTP service to use (override host in swagger schema)" },
     "lazyStartProducer": { "index": 4, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...]
     "producerComponentName": { "index": 5, "kind": "property", "displayName": "Producer Component Name", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel Rest component to use for the producer REST transport, such as http, undertow. If no component has been explicitly configured, then Camel will lookup if there is a Camel component that integra [...]
-    "autowiredEnabled": { "index": 6, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching t [...]
+    "autowiredEnabled": { "index": 6, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching t [...]
+    "headerFilterStrategy": { "index": 7, "kind": "property", "displayName": "Header Filter Strategy", "group": "filter", "label": "filter", "required": false, "type": "object", "javaType": "org.apache.camel.spi.HeaderFilterStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message." }
   },
   "headers": {
     "CamelRestHttpQuery": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The query parameters for the rest call to be used", "constantName": "org.apache.camel.component.rest.RestConstants#REST_HTTP_QUERY" },
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
index 2d856d74d5a..afb481813c2 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
@@ -624,8 +624,14 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
         HttpEndpoint endpoint = (HttpEndpoint) camelContext.getEndpoint(url, parameters);
 
         String path = uriTemplate != null ? uriTemplate : basePath;
-        endpoint.setHeaderFilterStrategy(new HttpRestHeaderFilterStrategy(path, queryParameters));
 
+        HeaderFilterStrategy headerFilterStrategy
+                = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class);
+        if (headerFilterStrategy != null) {
+            endpoint.setHeaderFilterStrategy(headerFilterStrategy);
+        } else {
+            endpoint.setHeaderFilterStrategy(new HttpRestHeaderFilterStrategy(path, queryParameters));
+        }
         // the endpoint must be started before creating the producer
         ServiceHelper.startService(endpoint);
 
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
index ae34f278295..1b071b2b280 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
@@ -497,8 +497,14 @@ public class NettyHttpComponent extends NettyComponent
 
         NettyHttpEndpoint endpoint = (NettyHttpEndpoint) camelContext.getEndpoint(url, parameters);
         String path = uriTemplate != null ? uriTemplate : basePath;
-        endpoint.setHeaderFilterStrategy(new NettyHttpRestHeaderFilterStrategy(path, queryParameters));
 
+        HeaderFilterStrategy headerFilterStrategy
+                = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class);
+        if (headerFilterStrategy != null) {
+            endpoint.setHeaderFilterStrategy(headerFilterStrategy);
+        } else {
+            endpoint.setHeaderFilterStrategy(new NettyHttpRestHeaderFilterStrategy(path, queryParameters));
+        }
         // the endpoint must be started before creating the producer
         ServiceHelper.startService(endpoint);
 
diff --git a/components/camel-rest/src/generated/java/org/apache/camel/component/rest/RestComponentConfigurer.java b/components/camel-rest/src/generated/java/org/apache/camel/component/rest/RestComponentConfigurer.java
index 0302f752692..249a29453ef 100644
--- a/components/camel-rest/src/generated/java/org/apache/camel/component/rest/RestComponentConfigurer.java
+++ b/components/camel-rest/src/generated/java/org/apache/camel/component/rest/RestComponentConfigurer.java
@@ -29,6 +29,8 @@ public class RestComponentConfigurer extends PropertyConfigurerSupport implement
         case "bridgeErrorHandler": target.setBridgeErrorHandler(property(camelContext, boolean.class, value)); return true;
         case "consumercomponentname":
         case "consumerComponentName": target.setConsumerComponentName(property(camelContext, java.lang.String.class, value)); return true;
+        case "headerfilterstrategy":
+        case "headerFilterStrategy": target.setHeaderFilterStrategy(property(camelContext, org.apache.camel.spi.HeaderFilterStrategy.class, value)); return true;
         case "host": target.setHost(property(camelContext, java.lang.String.class, value)); return true;
         case "lazystartproducer":
         case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
@@ -49,6 +51,8 @@ public class RestComponentConfigurer extends PropertyConfigurerSupport implement
         case "bridgeErrorHandler": return boolean.class;
         case "consumercomponentname":
         case "consumerComponentName": return java.lang.String.class;
+        case "headerfilterstrategy":
+        case "headerFilterStrategy": return org.apache.camel.spi.HeaderFilterStrategy.class;
         case "host": return java.lang.String.class;
         case "lazystartproducer":
         case "lazyStartProducer": return boolean.class;
@@ -70,6 +74,8 @@ public class RestComponentConfigurer extends PropertyConfigurerSupport implement
         case "bridgeErrorHandler": return target.isBridgeErrorHandler();
         case "consumercomponentname":
         case "consumerComponentName": return target.getConsumerComponentName();
+        case "headerfilterstrategy":
+        case "headerFilterStrategy": return target.getHeaderFilterStrategy();
         case "host": return target.getHost();
         case "lazystartproducer":
         case "lazyStartProducer": return target.isLazyStartProducer();
diff --git a/components/camel-rest/src/generated/resources/org/apache/camel/component/rest/rest.json b/components/camel-rest/src/generated/resources/org/apache/camel/component/rest/rest.json
index f3934fe42fe..71a3f2602c7 100644
--- a/components/camel-rest/src/generated/resources/org/apache/camel/component/rest/rest.json
+++ b/components/camel-rest/src/generated/resources/org/apache/camel/component/rest/rest.json
@@ -29,7 +29,8 @@
     "host": { "index": 3, "kind": "property", "displayName": "Host", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Host and port of HTTP service to use (override host in swagger schema)" },
     "lazyStartProducer": { "index": 4, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...]
     "producerComponentName": { "index": 5, "kind": "property", "displayName": "Producer Component Name", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The Camel Rest component to use for the producer REST transport, such as http, undertow. If no component has been explicitly configured, then Camel will lookup if there is a Camel component that integra [...]
-    "autowiredEnabled": { "index": 6, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching t [...]
+    "autowiredEnabled": { "index": 6, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching t [...]
+    "headerFilterStrategy": { "index": 7, "kind": "property", "displayName": "Header Filter Strategy", "group": "filter", "label": "filter", "required": false, "type": "object", "javaType": "org.apache.camel.spi.HeaderFilterStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message." }
   },
   "headers": {
     "CamelRestHttpQuery": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The query parameters for the rest call to be used", "constantName": "org.apache.camel.component.rest.RestConstants#REST_HTTP_QUERY" },
diff --git a/components/camel-rest/src/main/docs/rest-component.adoc b/components/camel-rest/src/main/docs/rest-component.adoc
index 8abbc7aef45..70da146fd7c 100644
--- a/components/camel-rest/src/main/docs/rest-component.adoc
+++ b/components/camel-rest/src/main/docs/rest-component.adoc
@@ -33,6 +33,10 @@ rest://method:path[:uriTemplate]?[options]
 
 // component options: START
 include::partial$component-configure-options.adoc[]
+[NOTE]
+====
+If you want to configure custom headerFilterStrategy, its recommended to extend the rest based(org.apache.camel.http.common.HttpRestHeaderFilterStrategy) and ensure to call its super methods
+====
 include::partial$component-endpoint-options.adoc[]
 // component options: END
 
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 fd29c7e8e34..45e73d819bc 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,12 +21,9 @@ 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.spi.*;
 import org.apache.camel.support.CamelContextHelper;
-import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.support.HeaderFilterStrategyComponent;
 import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.StringHelper;
@@ -37,7 +34,7 @@ import org.apache.camel.util.URISupport;
  */
 @org.apache.camel.spi.annotations.Component("rest")
 @Metadata(label = "verifiers", enums = "parameters,connectivity")
-public class RestComponent extends DefaultComponent {
+public class RestComponent extends HeaderFilterStrategyComponent {
 
     public static final String DEFAULT_REST_CONFIGURATION_ID = "rest-configuration";
 
@@ -82,6 +79,7 @@ public class RestComponent extends DefaultComponent {
         }
         answer.setHost(h);
 
+        parameters.put("headerFilterStrategy", getHeaderFilterStrategy());
         setProperties(answer, parameters);
         if (!parameters.isEmpty()) {
             // use only what remains and at this point parameters that have been used have been removed
diff --git a/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpComponent.java b/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpComponent.java
index db4647c6ba8..9ad4b374023 100644
--- a/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpComponent.java
+++ b/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpComponent.java
@@ -29,6 +29,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Producer;
 import org.apache.camel.SSLContextParametersAware;
+import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.RestConfiguration;
 import org.apache.camel.spi.RestProducerFactory;
@@ -199,8 +200,13 @@ public class VertxHttpComponent extends HeaderFilterStrategyComponent
 
         VertxHttpEndpoint endpoint = (VertxHttpEndpoint) camelContext.getEndpoint(url, parameters);
         String path = uriTemplate != null ? uriTemplate : basePath;
-        endpoint.getConfiguration().setHeaderFilterStrategy(new VertxHttpRestHeaderFilterStrategy(path, queryParameters));
-
+        HeaderFilterStrategy headerFilterStrategy
+                = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class);
+        if (headerFilterStrategy != null) {
+            endpoint.getConfiguration().setHeaderFilterStrategy(headerFilterStrategy);
+        } else {
+            endpoint.getConfiguration().setHeaderFilterStrategy(new VertxHttpRestHeaderFilterStrategy(path, queryParameters));
+        }
         // the endpoint must be started before creating the producer
         ServiceHelper.startService(endpoint);