On Tue, 2011-01-11 at 19:17 +0100, Stevo Slavić wrote:
> It seems they were.
> 
> On client side of communication I now have:
> 
> 
>               HttpDelete httpDelete = new HttpDelete(deleteUrl);
> 
>               try {
>                       HttpResponse response = client.execute(delete);
>                       if (response.getStatusLine().getStatusCode() != 
> HttpStatus.SC_OK) {
>                               throw new 
> SomeCustomException(response.getStatusLine().getStatusCode(),
> response.getStatusLine().getReasonPhrase());
>                       }
>               } catch (IOException ioe) {
>                       throw new SomeCustomException(ioe);
>               } finally {
>                       if (delete != null) {
>                               delete.abort();
>                       }
>               }
> 
> 
> Without finally and abort call in it (also with abort just on
> IOException in catch block), connections would not get returned to the
> pool in regular non-exceptional return. HttpDelete refrence is lost -
> not accessible outside of this block/method. This puts responsibility
> to the developer to clean up low level resources which weren't
> directly created or accessed - I guess it has to be like that.
> 

What is wrong with just this?

HttpDelete httpDelete = new HttpDelete(deleteUrl);
HttpResponse response = client.execute(httpDelete);
HttpEntity entity = response.getEntity();
if (entity != null) {
    entity.consumeContent();
}
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
   throw new SomeCustomException();
}

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to