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 2017/01/30 13:46:59 UTC

[1/2] camel git commit: Extract HttpClientConnectionManager creation

Repository: camel
Updated Branches:
  refs/heads/master c6635f18c -> 3a0f0b6de


Extract HttpClientConnectionManager creation

This commit extracts creation of `HttpClientConnectionManager` in a
separate method `createConnectionManager`, this method can be then
reused from a component based on the `HttpComponent`.

(cherry picked from commit dd8b972ea5e7e0cc3e94f30d7261900cb780305f)


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3a0f0b6d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3a0f0b6d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3a0f0b6d

Branch: refs/heads/master
Commit: 3a0f0b6de4c3903acc5202dbf94b7daa70cd5fbe
Parents: a6ba603
Author: Zoran Regvart <zo...@regvart.com>
Authored: Fri Jan 27 20:42:37 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jan 30 14:44:10 2017 +0100

----------------------------------------------------------------------
 .../camel/component/http4/HttpComponent.java    | 32 ++++++++++++--------
 1 file changed, 20 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3a0f0b6d/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
index 463708f..89a5bea 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
@@ -21,6 +21,7 @@ import java.net.URI;
 import java.security.GeneralSecurityException;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.CamelContext;
@@ -171,11 +172,6 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
         HttpBinding httpBinding = resolveAndRemoveReferenceParameter(parameters, "httpBinding", HttpBinding.class);
         HttpContext httpContext = resolveAndRemoveReferenceParameter(parameters, "httpContext", HttpContext.class);
 
-        X509HostnameVerifier x509HostnameVerifier = resolveAndRemoveReferenceParameter(parameters, "x509HostnameVerifier", X509HostnameVerifier.class);
-        if (x509HostnameVerifier == null) {
-            x509HostnameVerifier = getX509HostnameVerifier();
-        }
-
         SSLContextParameters sslContextParameters = resolveAndRemoveReferenceParameter(parameters, "sslContextParameters", SSLContextParameters.class);
         if (sslContextParameters == null) {
             sslContextParameters = getSslContextParameters();
@@ -225,13 +221,7 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
         String endpointUriString = endpointUri.toString();
 
         LOG.debug("Creating endpoint uri {}", endpointUriString);
-        HttpClientConnectionManager localConnectionManager = clientConnectionManager;
-        if (localConnectionManager == null) {
-            // need to check the parameters of maxTotalConnections and connectionsPerRoute
-            int maxTotalConnections = getAndRemoveParameter(parameters, "maxTotalConnections", int.class, 0);
-            int connectionsPerRoute = getAndRemoveParameter(parameters, "connectionsPerRoute", int.class, 0);
-            localConnectionManager = createConnectionManager(createConnectionRegistry(x509HostnameVerifier, sslContextParameters), maxTotalConnections, connectionsPerRoute);
-        }
+        final HttpClientConnectionManager localConnectionManager = createConnectionManager(parameters, sslContextParameters);
         HttpEndpoint endpoint = new HttpEndpoint(endpointUriString, this, clientBuilder, localConnectionManager, configurer);
         if (urlRewrite != null) {
             // let CamelContext deal with the lifecycle of the url rewrite
@@ -281,6 +271,24 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
         return endpoint;
     }
 
+    protected HttpClientConnectionManager createConnectionManager(final Map<String, Object> parameters,
+            final SSLContextParameters sslContextParameters) throws GeneralSecurityException, IOException {
+        if (clientConnectionManager != null) {
+            return clientConnectionManager;
+        }
+
+        final X509HostnameVerifier resolvedHostnameVerifier = resolveAndRemoveReferenceParameter(parameters, "x509HostnameVerifier", X509HostnameVerifier.class);
+        final X509HostnameVerifier hostnameVerifier = Optional.ofNullable(resolvedHostnameVerifier).orElse(x509HostnameVerifier);
+
+        // need to check the parameters of maxTotalConnections and connectionsPerRoute
+        final int maxTotalConnections = getAndRemoveParameter(parameters, "maxTotalConnections", int.class, 0);
+        final int connectionsPerRoute = getAndRemoveParameter(parameters, "connectionsPerRoute", int.class, 0);
+
+        final Registry<ConnectionSocketFactory> connectionRegistry = createConnectionRegistry(hostnameVerifier, sslContextParameters);
+
+        return createConnectionManager(connectionRegistry, maxTotalConnections, connectionsPerRoute);
+    }
+
     protected HttpClientBuilder createHttpClientBuilder(final String uri, final Map<String, Object> parameters,
             final Map<String, Object> httpClientOptions) throws Exception {
         // http client can be configured from URI options


[2/2] camel git commit: Extract HttpClientBuilder creation

Posted by da...@apache.org.
Extract HttpClientBuilder creation

This commit extracts creation of `HttpClientBuilder` in a separate
method `createHttpClientBuilder`, this method can be then reused from a
component based on the `HttpComponent`.

(cherry picked from commit e3601df1eb06988ca326dedfd7bb0f5508a3bb1a)


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a6ba603e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a6ba603e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a6ba603e

Branch: refs/heads/master
Commit: a6ba603ef3a42387eafc97dee91fc33005bf2616
Parents: c6635f1
Author: Zoran Regvart <zo...@regvart.com>
Authored: Fri Jan 27 20:19:10 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jan 30 14:44:10 2017 +0100

----------------------------------------------------------------------
 .../camel/component/http4/HttpComponent.java    | 34 ++++++++++++--------
 1 file changed, 21 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a6ba603e/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
index 632a0f0..463708f 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
@@ -165,18 +165,8 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
         Map<String, Object> httpClientParameters = new HashMap<String, Object>(parameters);
-        // http client can be configured from URI options
-        HttpClientBuilder clientBuilder = HttpClientBuilder.create();
-        // allow the builder pattern
-        Map<String, Object> httpClientOptions = IntrospectionSupport.extractProperties(parameters, "httpClient.");
-        IntrospectionSupport.setProperties(clientBuilder, httpClientOptions);
-        // set the Request configure this way and allow the builder pattern
-        RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
-        IntrospectionSupport.setProperties(requestConfigBuilder, httpClientOptions);
-        clientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
-        
-        // validate that we could resolve all httpClient. parameters as this component is lenient
-        validateParameters(uri, httpClientOptions, null);
+        final Map<String, Object> httpClientOptions = new HashMap<>();
+        final HttpClientBuilder clientBuilder = createHttpClientBuilder(uri, parameters, httpClientOptions);
         
         HttpBinding httpBinding = resolveAndRemoveReferenceParameter(parameters, "httpBinding", HttpBinding.class);
         HttpContext httpContext = resolveAndRemoveReferenceParameter(parameters, "httpContext", HttpContext.class);
@@ -290,7 +280,25 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
         
         return endpoint;
     }
-    
+
+    protected HttpClientBuilder createHttpClientBuilder(final String uri, final Map<String, Object> parameters,
+            final Map<String, Object> httpClientOptions) throws Exception {
+        // http client can be configured from URI options
+        HttpClientBuilder clientBuilder = HttpClientBuilder.create();
+        // allow the builder pattern
+        httpClientOptions.putAll(IntrospectionSupport.extractProperties(parameters, "httpClient."));
+        IntrospectionSupport.setProperties(clientBuilder, httpClientOptions);
+        // set the Request configure this way and allow the builder pattern
+        RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
+        IntrospectionSupport.setProperties(requestConfigBuilder, httpClientOptions);
+        clientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
+
+        // validate that we could resolve all httpClient. parameters as this component is lenient
+        validateParameters(uri, httpClientOptions, null);
+
+        return clientBuilder;
+    }
+
     protected Registry<ConnectionSocketFactory> createConnectionRegistry(X509HostnameVerifier x509HostnameVerifier, SSLContextParameters sslContextParams)
         throws GeneralSecurityException, IOException {
         // create the default connection registry to use