Search in sources :

Example 1 with SystemDefaultRoutePlanner

use of org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner 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)

Aggregations

HttpClientBuilder (org.apache.hc.client5.http.impl.classic.HttpClientBuilder)1 BasicHttpClientConnectionManager (org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager)1 SystemDefaultRoutePlanner (org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner)1 HttpClientConnectionManager (org.apache.hc.client5.http.io.HttpClientConnectionManager)1 ConnectionSocketFactory (org.apache.hc.client5.http.socket.ConnectionSocketFactory)1 PlainConnectionSocketFactory (org.apache.hc.client5.http.socket.PlainConnectionSocketFactory)1 SSLConnectionSocketFactory (org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory)1