[
https://issues.apache.org/jira/browse/HTTPCLIENT-1921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16482366#comment-16482366
]
elise badr edited comment on HTTPCLIENT-1921 at 5/21/18 10:17 AM:
------------------------------------------------------------------
Hi again,
Thanks a lot for your support. I still have one question.
i am testing now the connection time out using this code:
{code:java}
HttpGet httpGet = new HttpGet("http://172.17.2.135:9090/selfcare/me/balance");
CloseableHttpClient client =
HttpClientBuilder.create().setMaxConnTotal(2).setMaxConnPerRoute(2).setDefaultRequestConfig(RequestConfig.custom()
.setSocketTimeout(10000).setConnectTimeout(10000).setConnectionRequestTimeout(2000).build()).build();
CloseableHttpResponse response = null;
long startTime = 0 ;
try
{
startTime = System.currentTimeMillis();
response = client.execute(httpGet);
result = response.toString();
}
catch(Exception e)
{
System.out.println("Total time: " + (System.currentTimeMillis() - startTime));
e.printStackTrace();
}
finally {
try
{
if(response!=null)
{
response.close();
}
}
catch(IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
{code}
No server is running. An error connecting is thrown and the System.out.println
prints a wait time of 1000ms always even though i set the connect time out to
10000. Is something wrong in my configuration?
Same problem happens while using httpclient jar through Spring 4.
was (Author: elise.badr.cme):
Hi again,
i am testing now the connection time out using this code:
{code:java}
HttpGet httpGet = new HttpGet("http://172.17.2.135:9090/selfcare/me/balance");
CloseableHttpClient client =
HttpClientBuilder.create().setMaxConnTotal(2).setMaxConnPerRoute(2).setDefaultRequestConfig(RequestConfig.custom()
.setSocketTimeout(10000).setConnectTimeout(10000).setConnectionRequestTimeout(2000).build()).build();
CloseableHttpResponse response = null;
long startTime = 0 ;
try
{
startTime = System.currentTimeMillis();
response = client.execute(httpGet);
result = response.toString();
}
catch(Exception e)
{
System.out.println("Total time: " + (System.currentTimeMillis() - startTime));
e.printStackTrace();
}
finally {
try
{
if(response!=null)
{
response.close();
}
}
catch(IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
{code}
No server is running. An error connecting is thrown and the System.out.println
prints a wait time of 1000ms always even though i set the connect time out to
10000. Is something wrong in my configuration?
Same problem happens while using httpclient jar through Spring 4.
> Time out values not correctly used
> ----------------------------------
>
> Key: HTTPCLIENT-1921
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1921
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Affects Versions: 4.5.5
> Reporter: elise badr
> Priority: Blocker
> Labels: SocketTimeout, httpclient, timeout
> Attachments: FirstTime.png, httpclient.zip,
> oldJarSocketTimeoutScenarioResult.png, secondTime.png,
> socketTimeoutScenarioResult.png, thirdTime.png
>
>
> I was obliged to migrate to httpclient *4.5.5* and httpcore *4.4.9* while i
> was upgrading to Spring 4.
> I started using the following configuration to set my time out values:
>
> <bean id="httpClient"
> class="org.springframework.remoting.httpinvoker.HttpComponentsHttpInvokerRequestExecutor">
> <property name="httpClient" ref="httpClientBld"/>
> </bean>
> <bean id="requestConfigBuilder"
> class="org.apache.http.client.config.RequestConfig" factory-method="custom">
> <property name="socketTimeout" value="3000" />
> <property name="connectTimeout" value="4000" />
> <property name="staleConnectionCheckEnabled" value="true"/>
> <property name="connectionRequestTimeout" value="2000" />
> </bean>
> <bean id="requestConfig" factory-bean="requestConfigBuilder"
> factory-method="build" />
> <bean id="httpClientBuilder"
> class="org.apache.http.impl.client.HttpClientBuilder" factory-method="create">
> <property name="defaultRequestConfig" ref="requestConfig" />
> <property name="maxConnTotal" value="2" />
> <property name="maxConnPerRoute" value="2" />
> </bean>
> <bean id="httpClientBld" factory-bean="httpClientBuilder"
> factory-method="build" />
>
> However, while testing, the socket time out and connection time out doesn't
> seem to be working correctly... it always waits around 1000 ms for the
> connection timeout and 60000 for the socket time out instead of the
> configured values. The request connection time out seems to be working fine.
> Can you please help... is it a bug from your side? or a wrong configuration
> from my side?
>
> Note that it seems the issues exists also in older versions as the following
> link from stack overflow discuss a similar issue for an older version:
> [https://stackoverflow.com/questions/21576414/setting-time-out-in-apache-http-client]
> Note that it was working fine before with Spring 3 requiring commons http
> client
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]