Example usage for org.apache.http.config ConnectionConfig copy

List of usage examples for org.apache.http.config ConnectionConfig copy

Introduction

In this page you can find the example usage for org.apache.http.config ConnectionConfig copy.

Prototype

public static Builder copy(ConnectionConfig connectionConfig) 

Source Link

Usage

From source file:org.sonatype.nexus.httpclient.HttpClientPlan.java

public HttpClientPlan() {
    this.client = HttpClientBuilder.create();
    this.connection = ConnectionConfig.copy(ConnectionConfig.DEFAULT);
    this.socket = SocketConfig.copy(SocketConfig.DEFAULT);
    this.request = RequestConfig.copy(RequestConfig.DEFAULT);
    this.headers = new HashMap<>();
    this.attributes = new HashMap<>();
}

From source file:leap.lang.http.client.apache.ApacheHttpClient.java

protected CloseableHttpClient initHttpClient() {
    HttpClientBuilder cb = HttpClientBuilder.create();

    //TODO : small buffer size will cause socket closed when reading response entity?
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(getDefaultRegistry());
    //cm.setDefaultConnectionConfig(ConnectionConfig.custom().setBufferSize(1024 * 1024).build());

    cm.setMaxTotal(maxConnectionTotal);/*from  w w w  .  j  ava  2 s . c o  m*/
    cm.setDefaultMaxPerRoute(maxConnectionPerRoute);

    if (bufferSize > 0) {
        ConnectionConfig cc = ConnectionConfig.copy(ConnectionConfig.DEFAULT).setBufferSize(bufferSize).build();

        cm.setDefaultConnectionConfig(cc);
    }

    cb.setRetryHandler(new HttpRequestRetryHandler() {
        @Override
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
            return false;
        }
    });

    cb.setConnectionManager(cm);
    cb.setDefaultRequestConfig(requestConfig);

    return cb.build();
}