Jens Meuller wrote:
> Hello,
>
> it would be kind if you could help me with my question. I want to abort the
> communication with the remote server in case I did not get a 200 Status code
> back.
>
> Please see my code below:
>
> HttpResponse response = httpClient.execute(httpGet);
>
> int status = response.getStatusLine().getStatusCode();
>
> if ( status != 200) {
> throw new RuntimeException("No valid result"); // IS THIS
> VALID?
> }
>
> HttpEntity httpEntity = response.getEntity();
> if (httpEntity != null) {
>
>
> Will this lead to "stale" connections if I simply exit my method with a
> RuntimeException
This will certainly cause a connection leak.
or do i have to "consume the Content" with the
> "consumeContent()" method in every case or alternatively call
> InputStream.close()??
Yes, you do.
But both methods force me to "open" the Result Stream
> and then read it, even tough I am not interested in the Content at all.
>
Yes, you do not want to re-use the connection simply abort the request.
This will also ensure proper deallocation of system resources.
For details see:
http://hc.apache.org/httpcomponents-client/tutorial/html/fundamentals.html#d4e143Oleg
> I would be very thankfull for some tips how this is implemented the
> best/simplest but being "safe" to return connections back to the
> connection-pool.
>
> Thank you very much
> Jens
>
---------------------------------------------------------------------
To unsubscribe, e-mail:
httpclient-users-unsubscribe@...
For additional commands, e-mail:
httpclient-users-help@...