You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Check Peck <co...@gmail.com> on 2015/08/04 20:42:33 UTC
How to use PoolingHttpClientConnectionManager and other things in
older version of Apache http client?
I am using Apache HttpClient 4.2.5 which is very old and we cannot update
as of now due to old legacy system we have. In my other project in which I
am using Apache HttpClient 4.3.1, I am using below code:
private ClientHttpRequestFactory clientHttpRequestFactory() {
HttpComponentsClientHttpRequestFactory requestFactory = new
HttpComponentsClientHttpRequestFactory();
RequestConfig requestConfig =
RequestConfig.custom().setConnectionRequestTimeout(1000).setConnectTimeout(1000)
.setSocketTimeout(1000).setStaleConnectionCheckEnabled(false).build();
SocketConfig socketConfig =
SocketConfig.custom().setSoKeepAlive(true).setTcpNoDelay(true).build();
PoolingHttpClientConnectionManager
poolingHttpClientConnectionManager = new
PoolingHttpClientConnectionManager();
poolingHttpClientConnectionManager.setMaxTotal(300);
poolingHttpClientConnectionManager.setDefaultMaxPerRoute(200);
CloseableHttpClient httpClientBuilder = HttpClientBuilder.create()
.setConnectionManager(poolingHttpClientConnectionManager).setDefaultRequestConfig(requestConfig)
.setDefaultSocketConfig(socketConfig).build();
requestFactory.setHttpClient(httpClientBuilder);
return requestFactory;
}
I cannot use same above code in my legacy code in which I have 4.2.5 Apache
HttpClient. I cannot find RequestConfig and SocketConfig. Is there any
other way to achieve the above thing in 4.2.5 Apache HttpClient?
Re: How to use PoolingHttpClientConnectionManager and other things
in older version of Apache http client?
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2015-08-04 at 11:42 -0700, Check Peck wrote:
> I am using Apache HttpClient 4.2.5 which is very old and we cannot update
> as of now due to old legacy system we have. In my other project in which I
> am using Apache HttpClient 4.3.1, I am using below code:
>
> private ClientHttpRequestFactory clientHttpRequestFactory() {
> HttpComponentsClientHttpRequestFactory requestFactory = new
> HttpComponentsClientHttpRequestFactory();
> RequestConfig requestConfig =
> RequestConfig.custom().setConnectionRequestTimeout(1000).setConnectTimeout(1000)
>
> .setSocketTimeout(1000).setStaleConnectionCheckEnabled(false).build();
> SocketConfig socketConfig =
> SocketConfig.custom().setSoKeepAlive(true).setTcpNoDelay(true).build();
>
> PoolingHttpClientConnectionManager
> poolingHttpClientConnectionManager = new
> PoolingHttpClientConnectionManager();
> poolingHttpClientConnectionManager.setMaxTotal(300);
> poolingHttpClientConnectionManager.setDefaultMaxPerRoute(200);
>
> CloseableHttpClient httpClientBuilder = HttpClientBuilder.create()
>
> .setConnectionManager(poolingHttpClientConnectionManager).setDefaultRequestConfig(requestConfig)
> .setDefaultSocketConfig(socketConfig).build();
>
> requestFactory.setHttpClient(httpClientBuilder);
> return requestFactory;
> }
>
> I cannot use same above code in my legacy code in which I have 4.2.5 Apache
> HttpClient. I cannot find RequestConfig and SocketConfig. Is there any
> other way to achieve the above thing in 4.2.5 Apache HttpClient?
Yes, there is. You have to use older HttpParams APIs
https://hc.apache.org/httpcomponents-core-4.2.x/httpcore/apidocs/org/apache/http/params/HttpConnectionParams.html
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org