I think I've found the problem.  The Spring code isn't closing the input
stream from the response after reading it.  Easy to override and fix.

Thanks for your help...

On Fri, Apr 8, 2016 at 11:10 AM, Tim Webster <tim.webs...@gmail.com> wrote:

> Hi  sorry I'm not sure which question you are answering, but it sounds
> like you are saying that as long as I consume the response properly then
> the connections should be re-used properly (and not closed), despite the
> call to releaseConnection()?  If that is so, why do we need the call to
> releaseConnection()?
>
> How do I ensure this - we are already reading the output stream from the
> response and closing it...(hard to explain really in an email)...
>
>
>
> On Fri, Apr 8, 2016 at 11:04 AM, Oleg Kalnichevski <ol...@apache.org>
> wrote:
>
>> On Fri, 2016-04-08 at 11:02 +0100, Tim Webster wrote:
>> > OK...so do you think I need to use this class to explicitly to consume
>> the
>> > response?  I can see some methods on there for this.
>> >
>> > Also - I think the call to PostMethod.releaseConnection() will still
>> close
>> > it - do you have any idea if this should / should not be used?
>> >
>>
>> No, it will not.
>>
>> Just make sure your code always consumes response content.
>>
>> Oleg
>>
>> > Thanks,
>> >
>> >
>> >
>> >
>> > On Fri, Apr 8, 2016 at 10:46 AM, Bernd Eckenfels <
>> e...@zusammenkunft.net>
>> > wrote:
>> >
>> > > It looks like the HttpResponseProxy will be responsible for releasing
>> the
>> > > connection once the entity is consumed. Most likely by wrapping and
>> > > tracking the input stream.
>> > >
>> > >
>> > >
>> > >
>> > > Gruss
>> > > Bernd
>> > > --
>> > > http://bernd.eckenfels.net
>> > > From Win 10 Mobile
>> > >
>> > >
>> > >
>> > > *Von: *Tim Webster <tim.webs...@gmail.com>
>> > > *Gesendet: *Freitag, 8. April 2016 11:42
>> > > *An: *httpclient-users@hc.apache.org
>> > > *Betreff: *releasing streamed connections back to connection pool
>> > >
>> > >
>> > >
>> > > Hi,
>> > >
>> > >
>> > >
>> > > I'm using Spring's HttpComponentsHttpInvokerRequestExecutor in my
>> > >
>> > > application, configured with a PoolingHttpClientConnectionManager.
>> > >
>> > >
>> > >
>> > > It all works fine, except that when a request is executed, the HTTP
>> > >
>> > > connection that was used is closed after every request.  This is a
>> result
>> > >
>> > > of Spring calling HttpPost.releaseConnection().
>> > >
>> > >
>> > >
>> > > Ideally the connections would not be closed, but just released back
>> to the
>> > >
>> > > connection pool.   This is especially important for HTTPS connections
>> and
>> > >
>> > > the overhead of handshakes.
>> > >
>> > >
>> > >
>> > > My problem is, when httpPost.releaseConnection() is called, instead
>> of just
>> > >
>> > > releasing the connection back to the pool, it closes it.  If you dig
>> into
>> > >
>> > > the code you can see it ends up calling ConnectionHolder.cancel(),
>> where
>> > >
>> > > ideally it would be calling ConnectionHolder.releaseConnection().
>> > >
>> > >
>> > >
>> > > I thought I could override the Spring code to NOT call
>> > >
>> > > HttpPost.releaseConnection(), figuring the connection manager would
>> take
>> > >
>> > > care of releasing the connection itself, which it does, but not in my
>> case
>> > >
>> > > because it is a streaming request (these are HTTP posts with input
>> stream):
>> > >
>> > >
>> > >
>> > > From MainClientExec.java:
>> > >
>> > >
>> > >
>> > >
>> > >
>> > >             // check for entity, release connection if possible
>> > >
>> > >             final HttpEntity entity = response.getEntity();
>> > >
>> > >            if (entity == null || !entity.isStreaming()) {
>> > >
>> > >                 // connection not needed and (assumed to be) in
>> re-usable
>> > >
>> > > state
>> > >
>> > >                 connHolder.releaseConnection();
>> > >
>> > >                 return new HttpResponseProxy(response, null);
>> > >
>> > >             } else {
>> > >
>> > >                 return new HttpResponseProxy(response, connHolder);
>> > >
>> > >             }
>> > >
>> > >
>> > >
>> > > So - I don't see a way with the API the way it is to do what I
>> require,
>> > >
>> > > which is release the connection (without closing it) after consuming
>> the
>> > >
>> > > response.
>> > >
>> > >
>> > >
>> > > I'm happy to provide more details/context if anyone can help....
>> > >
>> > >
>> > >
>> > > thanks,
>> > >
>> > >
>> > >
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
>> For additional commands, e-mail: httpclient-users-h...@hc.apache.org
>>
>>
>

Reply via email to