hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Magnus Landrø <stefan.lan...@gmail.com>
Subject Re: Fw:Fw:PoolingHttpClientConnectionManager how to reuse the connection
Date Fri, 24 Apr 2015 12:26:43 GMT
I prefer this code-style:


client.execute(new HttpGet(), response -> {
return response.getAllHeaders();
}
);

The response handler will clean up everything.



2015-04-24 13:57 GMT+02:00 Oleg Kalnichevski <olegk@apache.org>:

> On Fri, 2015-04-24 at 13:22 +0200, Joan Balagueró wrote:
> > Hello,
> >
> > Regarding this posts:
> >
> > > Any help in this issue would be much appreciated.
> > > Thanks
> > > mrhuang
> > >
> >
> > > I am not quite sure I understand the issue. You should not even be
> using #releaseConnection in the first place. It is provided for
> compatibility with HC 3.x. You should always close CloseableHttpResponse in
> a try-finally or try-with-resources.
> > > Oleg
> >
> > You say that using CloseableHttpResponse is the right way to release a
> connection. Currently, our code to release a connection is the above (works
> fine):
> >
> >   if (entity != null)
> >   {
> >    try { EntityUtils.consume(entity); }
> >    catch (Exception e) {}
> >   }
> >   else
> >   {
> >    if (objPost != null) objPost.abort();
> >    else if (objGet != null) objGet.abort();
> >   }
> >
> > Do you think it's preferrable to change this code by one that directly
> closes the CloseableHttpResponse?
> >
>
> It is a matter of taste. I find try-finally or try-with-resources just
> nicer
>
> ---
> HttpGet get = new HttpGet("http://stuff/");
> try (CloseableHttpResponse response = client.execute(get)) {
>     System.out.println(response.getStatusLine());
>     EntityUtils.consume(entity);
> }
> ---
>
> Oleg
>
> > Thanks,
> >
> > Joan.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>


-- 
BEKK Open
http://open.bekk.no

TesTcl - a unit test framework for iRules
http://testcl.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message