com.ecwid.consul.transport.DefaultHttpTransport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of consul-api Show documentation
Show all versions of consul-api Show documentation
Java client for Consul HTTP API (http://consul.io)
package com.ecwid.consul.transport;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
/**
* Default HTTP client This class is thread safe
*
* @author Vasily Vasilkov ([email protected])
*/
public final class DefaultHttpTransport extends AbstractHttpTransport {
private final HttpClient httpClient;
public DefaultHttpTransport() {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(DEFAULT_MAX_CONNECTIONS);
connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_PER_ROUTE_CONNECTIONS);
RequestConfig requestConfig = RequestConfig.custom().
setConnectTimeout(DEFAULT_CONNECTION_TIMEOUT).
setConnectionRequestTimeout(DEFAULT_CONNECTION_TIMEOUT).
setSocketTimeout(DEFAULT_READ_TIMEOUT).
build();
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().
setConnectionManager(connectionManager).
setDefaultRequestConfig(requestConfig).
useSystemProperties();
this.httpClient = httpClientBuilder.build();
}
public DefaultHttpTransport(HttpClient httpClient) {
this.httpClient = httpClient;
}
@Override
protected HttpClient getHttpClient() {
return httpClient;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy