You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Keean Schupke <ke...@fry-it.com> on 2009/05/03 12:59:45 UTC

Connection Reuse.

Hi,

I searched for old posts on this topic, but none seem to cover my case
exactly. I suspect I am dealing with a non-standard webserver.
However, a telnet to  the server on port 80 allows several HTTP
commands to be run before the server closes the connection (at least 6
if they succeed).

So, I want to force the client to keep an SSL connection open and
re-use it. For now I am happy to catch an exception if the server has
closed the connection.

To give me an idea of what is going on I implemented a decorator for
the ClientConnectionManager and the SSLSocketFactory, logging the
method calls to a debug log.

Every time we try and execute a query on the server, the following
calls are made:

ClientConnectionManager.requestConnection(...)
SSLSocketFactory.createSocket()
SSLSockerFactory.connectSocket(...)

I have tried:

HttpConnectionParams.setStaleCheckingEnabled(httpParams, false);

But this seems to have no effect.

How can I force the HttpClient to reuse the connections?

Regards,
Keean.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Connection Reuse.

Posted by Oleg Kalnichevski <ol...@apache.org>.
Keean Schupke wrote:
> 2009/5/3 Oleg Kalnichevski <ol...@apache.org>:
>> Keean Schupke wrote:
>>> As I pointed out the server is keeping the connection open and
>>> accepting more requests... this is confirmed by manually pasting the
>>> requests into a telnet session.
>>>
>> Huh? Telneting to an SSL protected port? How exactly do you manage to get
>> the SSL handshaking done by typing to a terminal?
> 
> Because the server is configured the same on both port 80 and port
> 443, of course you are right, it is possible they behave differently
> on each port, although unlikely.
> 

I personally think this is not _that_ unlikely.

One more thing, the stale connection checking often behaves differently 
(unreliably) for SSL connections. I would really recommend disabling the 
stale connection checking for a start.

Oleg

>>
>>> I dont think I can get the android SDK to produce those logs? There
>>> doesn't seem to be a way to pass those args to the JVM either on the
>>> handset or the emulator.
>>>
>>> Is there any other way to find out why HttpClient thinks the
>>> connection is closed?
>>>
>> Reproduce the issue in a standalone application using the stock version of
>> HttpClient.
> 
> Hmm, It seems easier to open an HTTP socket directly and build my own
> HTTP query. I'll let you know what happens.
> 
> Regards,
> Keean,
> 
> ---------------------------------------------------------------------
> 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


Re: Connection Reuse.

Posted by Keean Schupke <ke...@fry-it.com>.
2009/5/3 Oleg Kalnichevski <ol...@apache.org>:
> Keean Schupke wrote:
>>
>> As I pointed out the server is keeping the connection open and
>> accepting more requests... this is confirmed by manually pasting the
>> requests into a telnet session.
>>
>
> Huh? Telneting to an SSL protected port? How exactly do you manage to get
> the SSL handshaking done by typing to a terminal?

Because the server is configured the same on both port 80 and port
443, of course you are right, it is possible they behave differently
on each port, although unlikely.

>
>
>> I dont think I can get the android SDK to produce those logs? There
>> doesn't seem to be a way to pass those args to the JVM either on the
>> handset or the emulator.
>>
>> Is there any other way to find out why HttpClient thinks the
>> connection is closed?
>>
>
> Reproduce the issue in a standalone application using the stock version of
> HttpClient.

Hmm, It seems easier to open an HTTP socket directly and build my own
HTTP query. I'll let you know what happens.

Regards,
Keean,

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Connection Reuse.

Posted by Oleg Kalnichevski <ol...@apache.org>.
Keean Schupke wrote:
> 2009/5/3 Oleg Kalnichevski <ol...@apache.org>:
>> There is no point forcing the client to keep a connection open if the server
>> is not going to do likewise. Per default HttpClient tries to reuse every
>> connection that can be reused.
>>
>> You need to find out why HttpClient considers those connections
>> non-reusable. Turn on wire/context logging as described here [1] and post
>> the log to this list.
> 
> As I pointed out the server is keeping the connection open and
> accepting more requests... this is confirmed by manually pasting the
> requests into a telnet session.
> 

Huh? Telneting to an SSL protected port? How exactly do you manage to 
get the SSL handshaking done by typing to a terminal?


> I dont think I can get the android SDK to produce those logs? There
> doesn't seem to be a way to pass those args to the JVM either on the
> handset or the emulator.
> 
> Is there any other way to find out why HttpClient thinks the
> connection is closed?
> 

Reproduce the issue in a standalone application using the stock version 
of HttpClient.

Oleg

> Regards,
> Keean.
> 
>> Oleg
>>
>> [1] http://hc.apache.org/httpcomponents-client/logging.html
> 
> ---------------------------------------------------------------------
> 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


Re: Connection Reuse.

Posted by Keean Schupke <ke...@fry-it.com>.
2009/5/3 Oleg Kalnichevski <ol...@apache.org>:
> There is no point forcing the client to keep a connection open if the server
> is not going to do likewise. Per default HttpClient tries to reuse every
> connection that can be reused.
>
> You need to find out why HttpClient considers those connections
> non-reusable. Turn on wire/context logging as described here [1] and post
> the log to this list.

As I pointed out the server is keeping the connection open and
accepting more requests... this is confirmed by manually pasting the
requests into a telnet session.

I dont think I can get the android SDK to produce those logs? There
doesn't seem to be a way to pass those args to the JVM either on the
handset or the emulator.

Is there any other way to find out why HttpClient thinks the
connection is closed?

Regards,
Keean.

>
> Oleg
>
> [1] http://hc.apache.org/httpcomponents-client/logging.html

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Connection Reuse.

Posted by Oleg Kalnichevski <ol...@apache.org>.
Keean Schupke wrote:
> Hi,
> 
> I searched for old posts on this topic, but none seem to cover my case
> exactly. I suspect I am dealing with a non-standard webserver.
> However, a telnet to  the server on port 80 allows several HTTP
> commands to be run before the server closes the connection (at least 6
> if they succeed).
> 
> So, I want to force the client to keep an SSL connection open and
> re-use it. For now I am happy to catch an exception if the server has
> closed the connection.
> 
> To give me an idea of what is going on I implemented a decorator for
> the ClientConnectionManager and the SSLSocketFactory, logging the
> method calls to a debug log.
> 
> Every time we try and execute a query on the server, the following
> calls are made:
> 
> ClientConnectionManager.requestConnection(...)
> SSLSocketFactory.createSocket()
> SSLSockerFactory.connectSocket(...)
> 
> I have tried:
> 
> HttpConnectionParams.setStaleCheckingEnabled(httpParams, false);
> 
> But this seems to have no effect.
> 
> How can I force the HttpClient to reuse the connections?
> 

There is no point forcing the client to keep a connection open if the 
server is not going to do likewise. Per default HttpClient tries to 
reuse every connection that can be reused.

You need to find out why HttpClient considers those connections 
non-reusable. Turn on wire/context logging as described here [1] and 
post the log to this list.

Oleg

[1] http://hc.apache.org/httpcomponents-client/logging.html


> Regards,
> Keean.
> 
> ---------------------------------------------------------------------
> 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