Java HTTP Client Request with defined timeout
Posted
by Maxim Veksler
on Stack Overflow
See other posts from Stack Overflow
or by Maxim Veksler
Published on 2010-06-08T18:36:31Z
Indexed on
2010/06/09
1:32 UTC
Read the original article
Hit count: 312
Hello,
I would like to make BIT (Built in tests) to a number of server in my cloud. I need the request to fail on large timeout.
How should I do this with java?
Trying something like the below does not seem to work.
public class TestNodeAliveness {
public static NodeStatus nodeBIT(String elasticIP) throws ClientProtocolException, IOException {
HttpClient client = new DefaultHttpClient();
client.getParams().setIntParameter("http.connection.timeout", 1);
HttpUriRequest request = new HttpGet("http://192.168.20.43");
HttpResponse response = client.execute(request);
System.out.println(response.toString());
return null;
}
public static void main(String[] args) throws ClientProtocolException, IOException {
nodeBIT("");
}
}
-- EDIT: Clarify what library is being used --
I'm using httpclient from apache, here is the relevant pom.xml section
org.apache.httpcomponents httpclient 4.0.1 jar
© Stack Overflow or respective owner