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 <[email protected]> Authored: Fri Jan 27 20:42:37 2017 +0100 Committer: Claus Ibsen <[email protected]> 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
