Hi,
I am trying to port my earlier code which used HttpClient 3.1 to now use
HttpClient 4.0. I am trying to find out a corresponding method with 4.0
to gracefully release a connection as it was being done with the 3.1
api.
With HC 3.1:
GetMethod method = new GetMethod("/someURL");
//execute the method using the HttpClient instance
//and then finally release the connection as shown below.
method.releaseConnection();
With HC 4.0:
HttpGet httpGet = new HttpGet("/someURL");
//execute the method using the HttpClient instance
HttpResponse response = httpClient.execute(httpget);
How to release the connection gracefully?
I don't want to call the abort() method on the httpGet instance.
Is it sufficient to call the consumeContect() to release a connection
gracefully?
HttpEntity entity = response.getEntity();
If (entity != null) {
entity.consumeContent();
}
Please let me know if there is a better and more efficient way to do it.
I have also tried to get the underlying inputstream from the response
entity and calling a close() on that but it's resulting in a
SocketException from other parts in my code.
Thanks,
Brijesh