On Wed, 2009-04-01 at 15:24 +0530, Brijesh Deo wrote:
> 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.
This is indeed the recommended way. For details, see the 'Ensuring
release of low level resources' section of the tutorial
http://wiki.apache.org/HttpComponents/HttpClientTutorial
> 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.
>
This should also work. What kind of SocketException are you getting?
Oleg
>
>
> Thanks,
>
> Brijesh
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]