You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2020/07/22 08:40:23 UTC

[GitHub] [camel] lburgazzoli commented on a change in pull request #4029: CAMEL-15283: Add Vert.x HTTP client component

lburgazzoli commented on a change in pull request #4029:
URL: https://github.com/apache/camel/pull/4029#discussion_r458631567



##########
File path: components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpEndpoint.java
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.core.Vertx;
+import io.vertx.core.net.ProxyOptions;
+import io.vertx.ext.web.client.WebClient;
+import io.vertx.ext.web.client.WebClientOptions;
+import io.vertx.ext.web.client.WebClientSession;
+import io.vertx.ext.web.client.spi.CookieStore;
+import org.apache.camel.Category;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.support.DefaultEndpoint;
+import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.util.ObjectHelper;
+
+@UriEndpoint(firstVersion = "3.5.0", scheme = "vertx-http", title = "Vert.x HTTP Client", syntax = "vertx-http:httpUri", category = {Category.HTTP}, producerOnly = true, lenientProperties = true)
+public class VertxHttpEndpoint extends DefaultEndpoint {
+
+    @UriParam
+    private VertxHttpConfiguration configuration;
+
+    private WebClient webClient;
+
+    public VertxHttpEndpoint(String uri, VertxHttpComponent component, VertxHttpConfiguration configuration) {
+        super(uri, component);
+        this.configuration = configuration;
+    }
+
+    @Override
+    public VertxHttpComponent getComponent() {
+        return (VertxHttpComponent) super.getComponent();
+    }
+
+    @Override
+    public Producer createProducer() throws Exception {
+        return new VertxHttpProducer(this);
+    }
+
+    @Override
+    public Consumer createConsumer(Processor processor) throws Exception {
+        throw new UnsupportedOperationException("vertx-http consumers are not supported");
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        if (webClient == null) {
+            WebClientOptions options = configuration.getWebClientOptions();
+            if (options == null) {
+                options = new WebClientOptions();
+                options.setTryUseCompression(configuration.isUseCompression());
+                options.setConnectTimeout(configuration.getConnectTimeout());
+                configureProxyOptionsIfRequired(options);
+            }
+
+            SSLContextParameters sslContextParameters = configuration.getSslContextParameters();
+            if (sslContextParameters != null) {
+                VertxHttpHelper.setupSSLOptions(sslContextParameters, options);
+            }
+
+            webClient = WebClient.create(getVertx(), options);
+            if (configuration.isSessionManagement()) {
+                CookieStore cookieStore = configuration.getCookieStore() == null ? CookieStore.build() : configuration.getCookieStore();
+                webClient = WebClientSession.create(webClient, cookieStore);
+            }
+        }
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+        webClient.close();

Review comment:
       maybe we need to check for null here ? I don't remember if in case of failures setting up the routes, the doStop method would get invoked




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org