All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ecwid.consul.transport.DefaultHttpTransport Maven / Gradle / Ivy

There is a newer version: 1.4.5
Show newest version
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