This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
The following commit(s) were added to refs/heads/master by this push: new c7ffb1f VFS-784 - Pass SSL connection factory to PoolingHttpClientConnectionManager (#119) c7ffb1f is described below commit c7ffb1f8b8ea0ae863b282fe0fb699a71f18622f Author: satish-csi <67928686+satish-...@users.noreply.github.com> AuthorDate: Thu Jul 15 22:32:14 2021 +0530 VFS-784 - Pass SSL connection factory to PoolingHttpClientConnectionManager (#119) * VFS-782 - pass correct proxy authentication credentials * VFS-784 - Pass SSL connection factory to PoolingHttpClientConnectionManager * Add test case for proxy authentication correction * Revert unwanted changes * Fix Formatting --- .../vfs2/provider/http4/Http4FileProvider.java | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java index 99d7d1b..2420240 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java @@ -57,11 +57,16 @@ import org.apache.http.client.CredentialsProvider; import org.apache.http.client.HttpClient; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; import org.apache.http.config.SocketConfig; import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.conn.routing.HttpRoutePlanner; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; import org.apache.http.conn.ssl.DefaultHostnameVerifier; import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.conn.ssl.TrustAllStrategy; import org.apache.http.cookie.Cookie; import org.apache.http.impl.DefaultConnectionReuseStrategy; @@ -115,8 +120,15 @@ public class Http4FileProvider extends AbstractOriginatingFileProvider { } private HttpClientConnectionManager createConnectionManager(final Http4FileSystemConfigBuilder builder, - final FileSystemOptions fileSystemOptions) { - final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(); + final FileSystemOptions fileSystemOptions, final SSLContext sslContext, final HostnameVerifier verifier) { + final SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory(sslContext, verifier); + final Registry<ConnectionSocketFactory> socketFactoryRegistry = + RegistryBuilder.<ConnectionSocketFactory> create() + .register("https", sslFactory) + .register("http", new PlainConnectionSocketFactory()) + .build(); + + final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry); connManager.setMaxTotal(builder.getMaxTotalConnections(fileSystemOptions)); connManager.setDefaultMaxPerRoute(builder.getMaxConnectionsPerHost(fileSystemOptions)); @@ -189,13 +201,14 @@ public class Http4FileProvider extends AbstractOriginatingFileProvider { final ConnectionReuseStrategy connectionReuseStrategy = builder.isKeepAlive(fileSystemOptions) ? DefaultConnectionReuseStrategy.INSTANCE : NoConnectionReuseStrategy.INSTANCE; - + final SSLContext sslContext = createSSLContext(builder, fileSystemOptions); + final HostnameVerifier hostNameVerifier = createHostnameVerifier(builder, fileSystemOptions); final HttpClientBuilder httpClientBuilder = HttpClients.custom() .setRoutePlanner(createHttpRoutePlanner(builder, fileSystemOptions)) - .setConnectionManager(createConnectionManager(builder, fileSystemOptions)) - .setSSLContext(createSSLContext(builder, fileSystemOptions)) - .setSSLHostnameVerifier(createHostnameVerifier(builder, fileSystemOptions)) + .setConnectionManager(createConnectionManager(builder, fileSystemOptions, sslContext, hostNameVerifier)) + .setSSLContext(sslContext) + .setSSLHostnameVerifier(hostNameVerifier) .setConnectionReuseStrategy(connectionReuseStrategy) .setDefaultRequestConfig(createDefaultRequestConfig(builder, fileSystemOptions)) .setDefaultHeaders(defaultHeaders)