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