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/11/05 09:57:17 UTC

[camel] branch main updated: CAMEL-18663: camel-vertx-http: allow to configure WebClientOptions at component level (#8664)

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 a9b14bb151f CAMEL-18663: camel-vertx-http: allow to configure WebClientOptions at component level (#8664)
a9b14bb151f is described below

commit a9b14bb151f666d049e4f06b3f8cc0219404d30e
Author: Luca Burgazzoli <lb...@users.noreply.github.com>
AuthorDate: Sat Nov 5 10:57:11 2022 +0100

    CAMEL-18663: camel-vertx-http: allow to configure WebClientOptions at component level (#8664)
---
 .../camel/catalog/components/vertx-http.json       |  1 +
 .../vertx/http/VertxHttpComponentConfigurer.java   |  6 ++
 .../camel/component/vertx/http/vertx-http.json     |  1 +
 .../component/vertx/http/VertxHttpComponent.java   | 17 +++++
 .../vertx/http/VertxHttpCustomWebClientTest.java   | 76 ++++++++++++++++++++++
 .../dsl/VertxHttpComponentBuilderFactory.java      | 18 +++++
 6 files changed, 119 insertions(+)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/vertx-http.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/vertx-http.json
index a6e420713b7..cc06fbafaf0 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/vertx-http.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/vertx-http.json
@@ -29,6 +29,7 @@
     "vertx": { "kind": "property", "displayName": "Vertx", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "io.vertx.core.Vertx", "deprecated": false, "autowired": false, "secret": false, "description": "To use an existing vertx instead of creating a new instance" },
     "vertxHttpBinding": { "kind": "property", "displayName": "Vertx Http Binding", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.vertx.http.VertxHttpBinding", "deprecated": false, "autowired": false, "secret": false, "description": "A custom VertxHttpBinding which can control how to bind between Vert.x and Camel" },
     "vertxOptions": { "kind": "property", "displayName": "Vertx Options", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "io.vertx.core.VertxOptions", "deprecated": false, "autowired": false, "secret": false, "description": "To provide a custom set of vertx options for configuring vertx" },
+    "webClientOptions": { "kind": "property", "displayName": "Web Client Options", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "io.vertx.ext.web.client.WebClientOptions", "deprecated": false, "autowired": false, "secret": false, "description": "To provide a custom set of options for configuring vertx web client" },
     "headerFilterStrategy": { "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." },
     "proxyHost": { "kind": "property", "displayName": "Proxy Host", "group": "proxy", "label": "proxy", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The proxy server host address" },
     "proxyPassword": { "kind": "property", "displayName": "Proxy Password", "group": "proxy", "label": "proxy", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The proxy server password if authentication is required" },
diff --git a/components/camel-vertx/camel-vertx-http/src/generated/java/org/apache/camel/component/vertx/http/VertxHttpComponentConfigurer.java b/components/camel-vertx/camel-vertx-http/src/generated/java/org/apache/camel/component/vertx/http/VertxHttpComponentConfigurer.java
index aa157f2eadc..eb9beb6ad0f 100644
--- a/components/camel-vertx/camel-vertx-http/src/generated/java/org/apache/camel/component/vertx/http/VertxHttpComponentConfigurer.java
+++ b/components/camel-vertx/camel-vertx-http/src/generated/java/org/apache/camel/component/vertx/http/VertxHttpComponentConfigurer.java
@@ -56,6 +56,8 @@ public class VertxHttpComponentConfigurer extends PropertyConfigurerSupport impl
         case "vertxHttpBinding": target.setVertxHttpBinding(property(camelContext, org.apache.camel.component.vertx.http.VertxHttpBinding.class, value)); return true;
         case "vertxoptions":
         case "vertxOptions": target.setVertxOptions(property(camelContext, io.vertx.core.VertxOptions.class, value)); return true;
+        case "webclientoptions":
+        case "webClientOptions": target.setWebClientOptions(property(camelContext, io.vertx.ext.web.client.WebClientOptions.class, value)); return true;
         default: return false;
         }
     }
@@ -98,6 +100,8 @@ public class VertxHttpComponentConfigurer extends PropertyConfigurerSupport impl
         case "vertxHttpBinding": return org.apache.camel.component.vertx.http.VertxHttpBinding.class;
         case "vertxoptions":
         case "vertxOptions": return io.vertx.core.VertxOptions.class;
+        case "webclientoptions":
+        case "webClientOptions": return io.vertx.ext.web.client.WebClientOptions.class;
         default: return null;
         }
     }
@@ -141,6 +145,8 @@ public class VertxHttpComponentConfigurer extends PropertyConfigurerSupport impl
         case "vertxHttpBinding": return target.getVertxHttpBinding();
         case "vertxoptions":
         case "vertxOptions": return target.getVertxOptions();
+        case "webclientoptions":
+        case "webClientOptions": return target.getWebClientOptions();
         default: return null;
         }
     }
diff --git a/components/camel-vertx/camel-vertx-http/src/generated/resources/org/apache/camel/component/vertx/http/vertx-http.json b/components/camel-vertx/camel-vertx-http/src/generated/resources/org/apache/camel/component/vertx/http/vertx-http.json
index a6e420713b7..cc06fbafaf0 100644
--- a/components/camel-vertx/camel-vertx-http/src/generated/resources/org/apache/camel/component/vertx/http/vertx-http.json
+++ b/components/camel-vertx/camel-vertx-http/src/generated/resources/org/apache/camel/component/vertx/http/vertx-http.json
@@ -29,6 +29,7 @@
     "vertx": { "kind": "property", "displayName": "Vertx", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "io.vertx.core.Vertx", "deprecated": false, "autowired": false, "secret": false, "description": "To use an existing vertx instead of creating a new instance" },
     "vertxHttpBinding": { "kind": "property", "displayName": "Vertx Http Binding", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.vertx.http.VertxHttpBinding", "deprecated": false, "autowired": false, "secret": false, "description": "A custom VertxHttpBinding which can control how to bind between Vert.x and Camel" },
     "vertxOptions": { "kind": "property", "displayName": "Vertx Options", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "io.vertx.core.VertxOptions", "deprecated": false, "autowired": false, "secret": false, "description": "To provide a custom set of vertx options for configuring vertx" },
+    "webClientOptions": { "kind": "property", "displayName": "Web Client Options", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "io.vertx.ext.web.client.WebClientOptions", "deprecated": false, "autowired": false, "secret": false, "description": "To provide a custom set of options for configuring vertx web client" },
     "headerFilterStrategy": { "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." },
     "proxyHost": { "kind": "property", "displayName": "Proxy Host", "group": "proxy", "label": "proxy", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The proxy server host address" },
     "proxyPassword": { "kind": "property", "displayName": "Proxy Password", "group": "proxy", "label": "proxy", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The proxy server password if authentication is required" },
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 9efae331c5c..db4647c6ba8 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
@@ -24,6 +24,7 @@ import java.util.Set;
 import io.vertx.core.Vertx;
 import io.vertx.core.VertxOptions;
 import io.vertx.core.net.ProxyType;
+import io.vertx.ext.web.client.WebClientOptions;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Producer;
@@ -79,6 +80,8 @@ public class VertxHttpComponent extends HeaderFilterStrategyComponent
     private boolean allowJavaSerializedObject;
     @Metadata(label = "producer", defaultValue = "true")
     private boolean responsePayloadAsByteArray = true;
+    @Metadata(label = "advanced")
+    private WebClientOptions webClientOptions;
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
@@ -126,6 +129,9 @@ public class VertxHttpComponent extends HeaderFilterStrategyComponent
         if (configuration.getHeaderFilterStrategy() == null) {
             configuration.setHeaderFilterStrategy(getHeaderFilterStrategy());
         }
+        if (configuration.getWebClientOptions() == null) {
+            configuration.setWebClientOptions(getWebClientOptions());
+        }
 
         // Recreate the http uri with the remaining parameters which the endpoint did not use
         URI httpUri = URISupport.createRemainingURI(
@@ -407,4 +413,15 @@ public class VertxHttpComponent extends HeaderFilterStrategyComponent
     public void setSslContextParameters(SSLContextParameters sslContextParameters) {
         this.sslContextParameters = sslContextParameters;
     }
+
+    public WebClientOptions getWebClientOptions() {
+        return webClientOptions;
+    }
+
+    /**
+     * To provide a custom set of options for configuring vertx web client
+     */
+    public void setWebClientOptions(WebClientOptions webClientOptions) {
+        this.webClientOptions = webClientOptions;
+    }
 }
diff --git a/components/camel-vertx/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpCustomWebClientTest.java b/components/camel-vertx/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpCustomWebClientTest.java
new file mode 100644
index 00000000000..f615da8c50e
--- /dev/null
+++ b/components/camel-vertx/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpCustomWebClientTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.vertx.http;
+
+import io.vertx.ext.web.client.WebClientOptions;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class VertxHttpCustomWebClientTest {
+
+    @Test
+    public void testCustomWebClientOptions() throws Exception {
+        WebClientOptions opts = new WebClientOptions();
+        opts.setSsl(true);
+        opts.setConnectTimeout(Integer.MAX_VALUE);
+
+        try (CamelContext context = new DefaultCamelContext()) {
+            VertxHttpComponent component = new VertxHttpComponent();
+            component.setCamelContext(context);
+            component.setWebClientOptions(opts);
+
+            context.start();
+
+            assertSame(opts, component.getWebClientOptions());
+            assertTrue(component.getWebClientOptions().isSsl());
+            assertEquals(Integer.MAX_VALUE, component.getWebClientOptions().getConnectTimeout());
+        }
+    }
+
+    @Test
+    public void testCustomWebClientOptionsWithRoute() throws Exception {
+        WebClientOptions opts = new WebClientOptions();
+        opts.setSsl(true);
+        opts.setConnectTimeout(Integer.MAX_VALUE);
+
+        try (CamelContext context = new DefaultCamelContext()) {
+            VertxHttpComponent component = new VertxHttpComponent();
+            component.setWebClientOptions(opts);
+
+            context.addComponent("vertx-http", component);
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:start")
+                            .to("vertx-http:http://localhost:8080");
+                }
+            });
+
+            context.start();
+
+            VertxHttpEndpoint ve = context.getEndpoint("vertx-http:http://localhost:8080", VertxHttpEndpoint.class);
+            assertTrue(ve.getConfiguration().getWebClientOptions().isSsl());
+            assertEquals(Integer.MAX_VALUE, ve.getConfiguration().getWebClientOptions().getConnectTimeout());
+        }
+    }
+}
diff --git a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/VertxHttpComponentBuilderFactory.java b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/VertxHttpComponentBuilderFactory.java
index c71ccdfb079..267087d96f5 100644
--- a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/VertxHttpComponentBuilderFactory.java
+++ b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/VertxHttpComponentBuilderFactory.java
@@ -179,6 +179,23 @@ public interface VertxHttpComponentBuilderFactory {
             doSetProperty("vertxOptions", vertxOptions);
             return this;
         }
+        /**
+         * To provide a custom set of options for configuring vertx web client.
+         * 
+         * The option is a:
+         * &lt;code&gt;io.vertx.ext.web.client.WebClientOptions&lt;/code&gt;
+         * type.
+         * 
+         * Group: advanced
+         * 
+         * @param webClientOptions the value to set
+         * @return the dsl builder
+         */
+        default VertxHttpComponentBuilder webClientOptions(
+                io.vertx.ext.web.client.WebClientOptions webClientOptions) {
+            doSetProperty("webClientOptions", webClientOptions);
+            return this;
+        }
         /**
          * To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter
          * header to and from Camel message.
@@ -372,6 +389,7 @@ public interface VertxHttpComponentBuilderFactory {
             case "vertx": ((VertxHttpComponent) component).setVertx((io.vertx.core.Vertx) value); return true;
             case "vertxHttpBinding": ((VertxHttpComponent) component).setVertxHttpBinding((org.apache.camel.component.vertx.http.VertxHttpBinding) value); return true;
             case "vertxOptions": ((VertxHttpComponent) component).setVertxOptions((io.vertx.core.VertxOptions) value); return true;
+            case "webClientOptions": ((VertxHttpComponent) component).setWebClientOptions((io.vertx.ext.web.client.WebClientOptions) value); return true;
             case "headerFilterStrategy": ((VertxHttpComponent) component).setHeaderFilterStrategy((org.apache.camel.spi.HeaderFilterStrategy) value); return true;
             case "proxyHost": ((VertxHttpComponent) component).setProxyHost((java.lang.String) value); return true;
             case "proxyPassword": ((VertxHttpComponent) component).setProxyPassword((java.lang.String) value); return true;