Search in sources :

Example 1 with HttpClientConnectionManager

use of org.apache.hc.client5.http.io.HttpClientConnectionManager in project gradle-download-task by michel-kraemer.

the class DefaultHttpClientFactory method createHttpClient.

@Override
public CloseableHttpClient createHttpClient(HttpHost httpHost, boolean acceptAnyCertificate, final int retries, Logger logger, boolean quiet) {
    HttpClientBuilder builder = HttpClientBuilder.create();
    // configure retries
    if (retries == 0) {
        builder.disableAutomaticRetries();
    } else {
        // TODO make interval configurable
        int maxRetries = retries;
        if (retries < 0) {
            maxRetries = Integer.MAX_VALUE;
        }
        builder.setRetryStrategy(new CustomHttpRequestRetryStrategy(maxRetries, TimeValue.ofSeconds(0L), logger, quiet));
    }
    // configure proxy from system environment
    builder.setRoutePlanner(new SystemDefaultRoutePlanner(null));
    // accept any certificate if necessary
    if ("https".equals(httpHost.getSchemeName()) && acceptAnyCertificate) {
        SSLConnectionSocketFactory icsf = getInsecureSSLSocketFactory();
        Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", icsf).register("http", PlainConnectionSocketFactory.INSTANCE).build();
        HttpClientConnectionManager cm = new BasicHttpClientConnectionManager(registry);
        builder.setConnectionManager(cm);
    }
    return builder.build();
}
Also used : ConnectionSocketFactory(org.apache.hc.client5.http.socket.ConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.hc.client5.http.socket.PlainConnectionSocketFactory) HttpClientBuilder(org.apache.hc.client5.http.impl.classic.HttpClientBuilder) BasicHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager) HttpClientConnectionManager(org.apache.hc.client5.http.io.HttpClientConnectionManager) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) BasicHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager) SystemDefaultRoutePlanner(org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner)

Example 2 with HttpClientConnectionManager

use of org.apache.hc.client5.http.io.HttpClientConnectionManager in project spring-cloud-openfeign by spring-cloud.

the class FeignHttpClient5ConfigurationTests method verifyHc5BeansAvailable.

private static void verifyHc5BeansAvailable(ConfigurableApplicationContext context) {
    CloseableHttpClient httpClient = context.getBean(CloseableHttpClient.class);
    assertThat(httpClient).isNotNull();
    HttpClientConnectionManager connectionManager = context.getBean(HttpClientConnectionManager.class);
    assertThat(connectionManager).isInstanceOf(PoolingHttpClientConnectionManager.class);
    Client client = context.getBean(Client.class);
    assertThat(client).isInstanceOf(ApacheHttp5Client.class);
}
Also used : CloseableHttpClient(org.apache.hc.client5.http.impl.classic.CloseableHttpClient) PoolingHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager) HttpClientConnectionManager(org.apache.hc.client5.http.io.HttpClientConnectionManager) ApacheHttpClient(feign.httpclient.ApacheHttpClient) Client(feign.Client) ApacheHttp5Client(feign.hc5.ApacheHttp5Client) CloseableHttpClient(org.apache.hc.client5.http.impl.classic.CloseableHttpClient)

Example 3 with HttpClientConnectionManager

use of org.apache.hc.client5.http.io.HttpClientConnectionManager in project geo-platform by geosdi.

the class GeoSDIHttpClient5 method createClientConnectionManager.

/**
 * @return {@link HttpClientConnectionManager}
 */
HttpClientConnectionManager createClientConnectionManager() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, (chain, authType) -> true);
        SSLConnectionSocketFactory sslSF = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSF).build());
        cm.setMaxTotal(10);
        cm.setDefaultMaxPerRoute(3);
        return cm;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new IllegalStateException(ex);
    }
}
Also used : ConnectionSocketFactory(org.apache.hc.client5.http.socket.ConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.hc.client5.http.socket.PlainConnectionSocketFactory) SSLContextBuilder(org.apache.hc.core5.ssl.SSLContextBuilder) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) URISyntaxException(java.net.URISyntaxException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) IOException(java.io.IOException) PoolingHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager)

Example 4 with HttpClientConnectionManager

use of org.apache.hc.client5.http.io.HttpClientConnectionManager in project geo-platform by geosdi.

the class GPAbstractServerConnector method createClientConnectionManager.

/**
 * @return {@link HttpClientConnectionManager}
 */
protected HttpClientConnectionManager createClientConnectionManager() {
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", this.sslConnectionSocketFactory).build());
    cm.setMaxTotal(this.pooledConnectorConfig.getMaxTotalConnections());
    cm.setDefaultMaxPerRoute(this.pooledConnectorConfig.getDefaultMaxPerRoute());
    return cm;
}
Also used : ConnectionSocketFactory(org.apache.hc.client5.http.socket.ConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.hc.client5.http.socket.PlainConnectionSocketFactory) PoolingHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager)

Example 5 with HttpClientConnectionManager

use of org.apache.hc.client5.http.io.HttpClientConnectionManager in project commons-vfs by apache.

the class Http5FileProvider method createConnectionManager.

private HttpClientConnectionManager createConnectionManager(final Http5FileSystemConfigBuilder builder, final FileSystemOptions fileSystemOptions) throws FileSystemException {
    final SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(Timeout.ofMilliseconds(builder.getSoTimeoutDuration(fileSystemOptions).toMillis())).build();
    final String[] tlsVersions = builder.getTlsVersions(fileSystemOptions).split("\\s*,\\s*");
    final TLS[] tlsArray = Stream.of(tlsVersions).map(TLS::valueOf).toArray(TLS[]::new);
    final SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder.create().setSslContext(createSSLContext(builder, fileSystemOptions)).setHostnameVerifier(createHostnameVerifier(builder, fileSystemOptions)).setTlsVersions(tlsArray).build();
    return PoolingHttpClientConnectionManagerBuilder.create().setSSLSocketFactory(sslSocketFactory).setMaxConnTotal(builder.getMaxTotalConnections(fileSystemOptions)).setMaxConnPerRoute(builder.getMaxConnectionsPerHost(fileSystemOptions)).setDefaultSocketConfig(socketConfig).build();
}
Also used : SocketConfig(org.apache.hc.core5.http.io.SocketConfig) TLS(org.apache.hc.core5.http.ssl.TLS) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory)

Aggregations

SSLConnectionSocketFactory (org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory)7 HttpClientConnectionManager (org.apache.hc.client5.http.io.HttpClientConnectionManager)5 CloseableHttpClient (org.apache.hc.client5.http.impl.classic.CloseableHttpClient)4 PoolingHttpClientConnectionManager (org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager)4 ConnectionSocketFactory (org.apache.hc.client5.http.socket.ConnectionSocketFactory)4 PlainConnectionSocketFactory (org.apache.hc.client5.http.socket.PlainConnectionSocketFactory)4 HttpGet (org.apache.hc.client5.http.classic.methods.HttpGet)3 IOException (java.io.IOException)2 CloseableHttpResponse (org.apache.hc.client5.http.impl.classic.CloseableHttpResponse)2 SSLContextBuilder (org.apache.hc.core5.ssl.SSLContextBuilder)2 Client (feign.Client)1 ApacheHttp5Client (feign.hc5.ApacheHttp5Client)1 ApacheHttpClient (feign.httpclient.ApacheHttpClient)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 X509Certificate (java.security.cert.X509Certificate)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutorService (java.util.concurrent.ExecutorService)1 SSLContext (javax.net.ssl.SSLContext)1