You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Jeremy Hicks <je...@novell.com> on 2006/06/27 17:02:52 UTC
Force-close connections queston
My reason for wanting to join was to thank all of you for a great
library and to ask if anybody has code available to do exactly what the
docs suggest in this section of the user guide:
http://jakarta.apache.org/commons/httpclient/performance.html#Connection_persistence
"The easiest way to disable connection persistence is to provide or
extend a connection manager that force-closes connections upon release
in the releaseConnection (
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/HttpConnectionManager.html#releaseConnection(org.apache.commons.httpclient.HttpConnection)
) method."
I would like to be able to force connections to not be persistent while
still using the multi-threaded http connection manager. If there is code
already available, that would be great. I think that just changing the
current multi-threaded http connection manager might be trivial, but I'm
not exactly sure what code to add to force the connections to close.
http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java?view=markup
Thanks
Jeremy Hicks
Novell, Inc., the leading provider of information solutions
http://www.novell.com
Re: Force-close connections queston
Posted by Roland Weber <ht...@dubioso.net>.
Hello Jeremy,
releasing a connection and closing a connection are two different
things. A connection always has to be released by the application,
so it can be used again for another request. Releasing a connection
means giving it back to the pool.
Closing a connection has to do with keep-alive. A connection can
be re-used without being closed, or it can be re-used after being
closed. In the latter case, it will be re-opened. The former is
possible only if the next request is sent to the same host. If not,
even the connection that was kept alive will be closed, before
being reopened to a different host.
You don't touch the releaseConnection method in BasicHttpMethod
or any other *Method class, because all it does is to give the
connection back to the pool. And that's something that has to be
done anyway.
You change the releaseConnection method in the pool implementation
because every connection being given back to the pool will pass
through that method. That gives you the opportunity to do something
with it, for example to close it. Since you are still seeing short
SSL handshakes instead of full ones, there are two reasons I can
think of right now:
1) you made some minor mistake when implementing the modified
pool (connection manager), so the code that closes the
connection is not executed
2) your SSL implementation maintains a pool of SSL sockets which
is different from the pool of HttpConnections maintained by
HttpClient, or rather by your modified connection manager
I suggest you investigate these reasons in the order given.
I'd add some debug output to the changed method in the connection
manager. A small typo, for example in the method name, will
still leave valid Java code, but breaks the overriding of the
base class method and bypasses your modifications. If that is
not the problem, you'll have to dig deep into the documentation
of your SSL/JSSE implementation before modifying the
SecureProtocolSocketFactory you're using.
hope that helps,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Ortwin Glück <od...@odi.ch>.
Jeremy Hicks wrote:
> EasySSLProtocolSocketFactory written by Oleg uses the SSL libraries
> which are under com.sun.net.ssl as opposed to the ones you suggested
> which are under javax.net.ssl.
Ah, now I understand. That was changed in February:
http://issues.apache.org/jira/browse/HTTPCLIENT-559
> There is no getClientSessionContext() method when using the SSL
> libraries from com.sun.net.ssl. It is only under javax.net.ssl.
Of course.
> I'll try this out. Thanks again for your help.
Prego
Ortwin
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Jeremy Hicks <je...@novell.com>.
EasySSLProtocolSocketFactory written by Oleg uses the SSL libraries which are under com.sun.net.ssl as opposed to the ones you suggested which are under javax.net.ssl.
There is no getClientSessionContext() method when using the SSL libraries from com.sun.net.ssl. It is only under javax.net.ssl.
I found a modified version of Oleg's EasySSLProtocolSocketFactory class online which uses the javax.net.ssl libraries instead. With this modified version, I was able to use the methods you suggested (setSessionCacheSize, etc) but I wasn't sure I was using them in the correct place and no matter what I did, it didn't seem to make any difference. (I was trying to set these within the getEasySSLSocketFactory() method.)
>>I think the best place to invalidate the session is from a custom
>>connection manager in its releaseConnection method like so:
>>((SSLSocket) conn.getSocket()).getSession().invalidate();
I'll try this out. Thanks again for your help.
Jeremy Hicks
Novell, Inc., the leading provider of information solutions
http://www.novell.com
>>> Ortwin Glück odi@odi.ch> 7/7/2006 2:33 AM >> ( mailto:odi@odi.ch> )
Jeremy Hicks wrote:
> We are using the EasySSLProtocolSocketFactory written by Oleg which
> is under com.sun.net.ssl.*.
Huh, what is under com.sun?
> I wasn't able to see a method for
> SSLContext called getClientSessionContext().
http://java.sun.com/j2se/1.4.2/docs/api/javax/net/ssl/SSLContext.html#getClientSessionContext()
> If there is a known way
> to invalidate the session using this class, that would be great. With
> this class we are getting, what appears to be, one full handshake
> that is being shared across all threads that are running instead of
> getting one full handshake for each thread (which is what a browser
> does).
Yes, that's true. This implementation is not perfect. It's a basis.
We happily accept patches, however.
> However, since I couldn't find that method, instead I tried a
> modified version of the EasySSLProtocolSocketFactory class which uses
> the javax.net.ssl.* classes.
I fail to understand...
> Using that, it seems that ALL SSL
> handshakes are full and that none of them are abbreviated.
Maybe you are not keeping any SSL sessions?
> It didn't
> seem to matter what I set the session cache size or session timeout
> to, I always got the same results. (I was trying to set these within
> the getEasySSLSocketFactory() method.) It also didn't seem to matter
> if I used the MultiThreadedHttpClientManger or my own that
> force-closes the HTTP connections. Where should I be making the call
> to SSLSocket.getSession() to try and invalidate the session there?
I think the best place to invalidate the session is from a custom
connection manager in its releaseConnection method like so:
((SSLSocket) conn.getSocket()).getSession().invalidate();
> Am I missing something basic here? If I'm not being clear enough,
> please let me know.
>
Hope that helps
Ortwin Glück
> Jeremy Hicks Novell, Inc., the leading provider of information
> solutions http://www.novell.com ( http://www.novell.com/ )
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Roland Weber <ht...@dubioso.net>.
Hello Jeremy,
> Okay, that makes sense. So you are saying that the SSLSocket socket is
> set to null after that first line. Why would it return null? Why
> wouldn't the call to getSocket() return the socket?
I have no idea. Maybe there is no socket (anymore)?
Why don't you look into the code and put some debug output there?
cheers,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Jeremy Hicks <je...@novell.com>.
Okay, that makes sense. So you are saying that the SSLSocket socket is
set to null after that first line. Why would it return null? Why
wouldn't the call to getSocket() return the socket?
Thanks again
Jeremy Hicks
Novell, Inc., the leading provider of information solutions
http://www.novell.com
>>> Roland Weber <ht...@dubioso.net> 07/17/06 11:53 AM >>>
Hi Jeremy,
> SSLSocket socket = (SSLSocket)MyConnectionHelper.getSocket(conn);
> SSLSession session = socket.getSession();
> session.invalidate();
>
> The exception seems to be coming from:
>
> SSLSession session = socket.getSession();
>
> I guess I don't understand why every SSLSocket wouldn't have a
session.
Think again. A NullPointerException isn't thrown because a method
returns null, it's thrown because the object on which you are calling
the method is null.
An SSLSocket wouldn't have a session if it hasn't been opened yet,
for starters. Communication problem? Handshake failure? Session
invalidated by server?
cheers,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Roland Weber <ht...@dubioso.net>.
Hi Jeremy,
> SSLSocket socket = (SSLSocket)MyConnectionHelper.getSocket(conn);
> SSLSession session = socket.getSession();
> session.invalidate();
>
> The exception seems to be coming from:
>
> SSLSession session = socket.getSession();
>
> I guess I don't understand why every SSLSocket wouldn't have a session.
Think again. A NullPointerException isn't thrown because a method
returns null, it's thrown because the object on which you are calling
the method is null.
An SSLSocket wouldn't have a session if it hasn't been opened yet,
for starters. Communication problem? Handshake failure? Session
invalidated by server?
cheers,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Jeremy Hicks <je...@novell.com>.
Okay, thanks for the idea of splitting it up. Now I have:
SSLSocket socket = (SSLSocket)MyConnectionHelper.getSocket(conn);
SSLSession session = socket.getSession();
session.invalidate();
The exception seems to be coming from:
SSLSession session = socket.getSession();
I guess I don't understand why every SSLSocket wouldn't have a session.
Thanks everybody for your patience.
Jeremy Hicks
Novell, Inc., the leading provider of information solutions
http://www.novell.com
>>> Roland Weber <ht...@dubioso.net> 07/17/06 11:15 AM >>>
Hi Jeremy,
> I get a NullPointerException on this line:
>
>
((SSLSocket)MyConnectionHelper.getSocket(conn)).getSession().invalidate();
>
> Can anybody tell why?
Either because getSocket(conn) returns null, or because
SSLSocket.getSession() returns null. How about splitting
this monster up into several lines to find out?
Also, how can you be sure that every SSLSocket has a
session? Connections might be released prematurely.
cheers,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Roland Weber <ht...@dubioso.net>.
Hi Jeremy,
> I get a NullPointerException on this line:
>
> ((SSLSocket)MyConnectionHelper.getSocket(conn)).getSession().invalidate();
>
> Can anybody tell why?
Either because getSocket(conn) returns null, or because
SSLSocket.getSession() returns null. How about splitting
this monster up into several lines to find out?
Also, how can you be sure that every SSLSocket has a
session? Connections might be released prematurely.
cheers,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Ortwin Glück <od...@odi.ch>.
Jeremy Hicks wrote:
> I get a NullPointerException on this line:
>
> ((SSLSocket)MyConnectionHelper.getSocket(conn)).getSession().invalidate();
>
>
> Can anybody tell why?
Maybe, because one of those reference is null? I am sure you can figure
out which one.
> Thanks
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Jeremy Hicks <je...@novell.com>.
Okay, I'm now trying with this Connection Helper class. Below is my
custom connection manager class:
import org.apache.commons.httpclient.*;
import javax.net.ssl.*;
public class MyHttpConnectionManager extends
MultiThreadedHttpConnectionManager
{
public void releaseConnection(final HttpConnection conn)
{
//TODO Need something here to check if we are SSL or not
try
{
// Getting a NullPointerException here. Why?
((SSLSocket)MyConnectionHelper.getSocket(conn)).getSession().invalidate();
}
catch(ClassCastException cce)
{
// It is okay, we are most likely just not running SSL.
}
if (conn == null)
{
return;
}
conn.close();
super.releaseConnection(conn);
}
}
I get a NullPointerException on this line:
((SSLSocket)MyConnectionHelper.getSocket(conn)).getSession().invalidate();
Can anybody tell why?
Thanks
Jeremy Hicks
Novell, Inc., the leading provider of information solutions
http://www.novell.com
>>> Roland Weber <ht...@dubioso.net> 07/08/06 10:49 AM >>>
Hello Jeremy,
> ((SSLSocket) conn.getSocket()).getSession().invalidate();
> won't work for me because the getSocket() call on the HttpConnection
conn is a protected method.
> I'm not within scope. What are my options?
Yet another design limitation of the 3.x codebase.
Easiest workaround is to get into scope:
package org.apache.commons.httpclient;
import java.net.Socket;
public final class MyConnectionHelper {
/** disabled constructor */
private MyConnectionHelper() {
}
public final static Socket getSocket(HttpConnection conn) {
return conn.getSocket();
}
}
I think you can rely on HttpClient not to define any classes
with a "My" prefix :-)
hope that helps,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Roland Weber <ht...@dubioso.net>.
Hello Jeremy,
> ((SSLSocket) conn.getSocket()).getSession().invalidate();
> won't work for me because the getSocket() call on the HttpConnection conn is a protected method.
> I'm not within scope. What are my options?
Yet another design limitation of the 3.x codebase.
Easiest workaround is to get into scope:
package org.apache.commons.httpclient;
import java.net.Socket;
public final class MyConnectionHelper {
/** disabled constructor */
private MyConnectionHelper() {
}
public final static Socket getSocket(HttpConnection conn) {
return conn.getSocket();
}
}
I think you can rely on HttpClient not to define any classes
with a "My" prefix :-)
hope that helps,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Jeremy Hicks <je...@novell.com>.
I found one problem here that I can't seem to figure out how to fix. This:
((SSLSocket) conn.getSocket()).getSession().invalidate();
won't work for me because the getSocket() call on the HttpConnection conn is a protected method. I'm not within scope. What are my options?
Thanks
Jeremy Hicks
Novell, Inc., the leading provider of information solutions
http://www.novell.com
>>> Ortwin Glück <od...@odi.ch> 7/7/2006 2:33 AM >>>
Jeremy Hicks wrote:
> We are using the EasySSLProtocolSocketFactory written by Oleg which
> is under com.sun.net.ssl.*.
Huh, what is under com.sun?
> I wasn't able to see a method for
> SSLContext called getClientSessionContext().
http://java.sun.com/j2se/1.4.2/docs/api/javax/net/ssl/SSLContext.html#getClientSessionContext()
> If there is a known way
> to invalidate the session using this class, that would be great. With
> this class we are getting, what appears to be, one full handshake
> that is being shared across all threads that are running instead of
> getting one full handshake for each thread (which is what a browser
> does).
Yes, that's true. This implementation is not perfect. It's a basis.
We happily accept patches, however.
> However, since I couldn't find that method, instead I tried a
> modified version of the EasySSLProtocolSocketFactory class which uses
> the javax.net.ssl.* classes.
I fail to understand...
> Using that, it seems that ALL SSL
> handshakes are full and that none of them are abbreviated.
Maybe you are not keeping any SSL sessions?
> It didn't
> seem to matter what I set the session cache size or session timeout
> to, I always got the same results. (I was trying to set these within
> the getEasySSLSocketFactory() method.) It also didn't seem to matter
> if I used the MultiThreadedHttpClientManger or my own that
> force-closes the HTTP connections. Where should I be making the call
> to SSLSocket.getSession() to try and invalidate the session there?
I think the best place to invalidate the session is from a custom
connection manager in its releaseConnection method like so:
((SSLSocket) conn.getSocket()).getSession().invalidate();
> Am I missing something basic here? If I'm not being clear enough,
> please let me know.
>
Hope that helps
Ortwin Glück
> Jeremy Hicks Novell, Inc., the leading provider of information
> solutions http://www.novell.com ( http://www.novell.com/ )
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Ortwin Glück <od...@odi.ch>.
Jeremy Hicks wrote:
> We are using the EasySSLProtocolSocketFactory written by Oleg which
> is under com.sun.net.ssl.*.
Huh, what is under com.sun?
> I wasn't able to see a method for
> SSLContext called getClientSessionContext().
http://java.sun.com/j2se/1.4.2/docs/api/javax/net/ssl/SSLContext.html#getClientSessionContext()
> If there is a known way
> to invalidate the session using this class, that would be great. With
> this class we are getting, what appears to be, one full handshake
> that is being shared across all threads that are running instead of
> getting one full handshake for each thread (which is what a browser
> does).
Yes, that's true. This implementation is not perfect. It's a basis.
We happily accept patches, however.
> However, since I couldn't find that method, instead I tried a
> modified version of the EasySSLProtocolSocketFactory class which uses
> the javax.net.ssl.* classes.
I fail to understand...
> Using that, it seems that ALL SSL
> handshakes are full and that none of them are abbreviated.
Maybe you are not keeping any SSL sessions?
> It didn't
> seem to matter what I set the session cache size or session timeout
> to, I always got the same results. (I was trying to set these within
> the getEasySSLSocketFactory() method.) It also didn't seem to matter
> if I used the MultiThreadedHttpClientManger or my own that
> force-closes the HTTP connections. Where should I be making the call
> to SSLSocket.getSession() to try and invalidate the session there?
I think the best place to invalidate the session is from a custom
connection manager in its releaseConnection method like so:
((SSLSocket) conn.getSocket()).getSession().invalidate();
> Am I missing something basic here? If I'm not being clear enough,
> please let me know.
>
Hope that helps
Ortwin Glück
> Jeremy Hicks Novell, Inc., the leading provider of information
> solutions http://www.novell.com
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Jeremy Hicks <je...@novell.com>.
We are using the EasySSLProtocolSocketFactory written by Oleg which is under com.sun.net.ssl.*. I wasn't able to see a method for SSLContext called getClientSessionContext().
If there is a known way to invalidate the session using this class, that would be great. With this class we are getting, what appears to be, one full handshake that is being shared across all threads that are running instead of getting one full handshake for each thread (which is what a browser does).
However, since I couldn't find that method, instead I tried a modified version of the EasySSLProtocolSocketFactory class which uses the javax.net.ssl.* classes. Using that, it seems that ALL SSL handshakes are full and that none of them are abbreviated. It didn't seem to matter what I set the session cache size or session timeout to, I always got the same results. (I was trying to set these within the getEasySSLSocketFactory() method.) It also didn't seem to matter if I used the MultiThreadedHttpClientManger or my own that force-closes the HTTP connections.
Where should I be making the call to SSLSocket.getSession() to try and invalidate the session there?
Am I missing something basic here? If I'm not being clear enough, please let me know.
Jeremy Hicks
Novell, Inc., the leading provider of information solutions
http://www.novell.com
>>> Ortwin Glück <od...@odi.ch> 6/27/2006 2:16 PM >>>
Jeremy Hicks wrote:
> We have written a client that logs into a web application and then gets
> redirected to a web resource. We want to use SSL during this process.
> Everything seems to be working fine, but we noticed that abbreviated
> handshakes are being done instead of a full handshake.
Jeremy,
Here is my understanding of the situation:
___________________________
SSL session != HTTP session
SSL is a stateful protocol. That's why there is the term "SSL session".
As SSL is not something specific to HTML this session has nothing to do
with HTTP session state (cookies, etc.). More specificly this session is
not tied to a single connection. Like a HTTP session it usually spans
multiple connections between the same endpoints.
_______________________
SSL session stores keys
SSL establishes a key pair with the host during a full handshake. This
key pair is expensive (asymmetric encryption is slow) to generate. It is
used to transfer a symmetric key (symmetric encryption is fast). This
symmetric key and the asymmatric pair is subsequently cached in the SSL
session. Typicall the key will expire after 24 hours and a new one will
be generated.
The abbreviated handshake uses this cached information to resume the
session in a secure way with less computational overhead (by simply
reusing the symmetric key).
________________________
Java SSL implementations
JSSE is the Java standard for SSL implementations. Its interfaces are in
javax.net.ssl. There you find the class SSLSession:
http://java.sun.com/j2se/1.4.2/docs/api/javax/net/ssl/SSLSession.html
SSL implementations have to implement this interface. The interface
provides an invalidate() method.
Access to the SSLSession object is possible through:
* SSLSocket.getSession()
* SSLContext.getInstance(...).getClientSessionContext().getSession(...)
The client SSLSessionContext
http://java.sun.com/j2se/1.4.2/docs/api/javax/net/ssl/SSLSessionContext.html
also has methods to control the session cache size and the session
timeout. This may be useful in your situation.
Hope that helps.
Ortwin Glück
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Ortwin Glück <od...@odi.ch>.
Jeremy Hicks wrote:
> We have written a client that logs into a web application and then gets
> redirected to a web resource. We want to use SSL during this process.
> Everything seems to be working fine, but we noticed that abbreviated
> handshakes are being done instead of a full handshake.
Jeremy,
Here is my understanding of the situation:
___________________________
SSL session != HTTP session
SSL is a stateful protocol. That's why there is the term "SSL session".
As SSL is not something specific to HTML this session has nothing to do
with HTTP session state (cookies, etc.). More specificly this session is
not tied to a single connection. Like a HTTP session it usually spans
multiple connections between the same endpoints.
_______________________
SSL session stores keys
SSL establishes a key pair with the host during a full handshake. This
key pair is expensive (asymmetric encryption is slow) to generate. It is
used to transfer a symmetric key (symmetric encryption is fast). This
symmetric key and the asymmatric pair is subsequently cached in the SSL
session. Typicall the key will expire after 24 hours and a new one will
be generated.
The abbreviated handshake uses this cached information to resume the
session in a secure way with less computational overhead (by simply
reusing the symmetric key).
________________________
Java SSL implementations
JSSE is the Java standard for SSL implementations. Its interfaces are in
javax.net.ssl. There you find the class SSLSession:
http://java.sun.com/j2se/1.4.2/docs/api/javax/net/ssl/SSLSession.html
SSL implementations have to implement this interface. The interface
provides an invalidate() method.
Access to the SSLSession object is possible through:
* SSLSocket.getSession()
* SSLContext.getInstance(...).getClientSessionContext().getSession(...)
The client SSLSessionContext
http://java.sun.com/j2se/1.4.2/docs/api/javax/net/ssl/SSLSessionContext.html
also has methods to control the session cache size and the session
timeout. This may be useful in your situation.
Hope that helps.
Ortwin Glück
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Jeremy Hicks <je...@novell.com>.
Okay, this didn't seem to do the trick for what I'm attempting to do.
I'll explain.
We have written a client that logs into a web application and then gets
redirected to a web resource. We want to use SSL during this process.
Everything seems to be working fine, but we noticed that abbreviated
handshakes are being done instead of a full handshake.
We tested using LoadRunner and it shows full handshakes being done. I
assumed this discrepancy was due to the fact that we are using the
MultiThreadedHttpConnectionManager which will reuse connections when
multiple requests go to the same destination. (Please correct me if this
is incorrect.)
This was why I requested information as to how to force-close the
connections. This was so that the connections wouldn't get reused and a
new connection would have to be made the next time a client requested a
page at the same destination.
I have added the code Oleg gave me and changed the reference in our
code from MultiThreadedHttpConnectionManager to MyHttpConnectionManager.
The client still appears to be doing abbreviated SSL handshakes and I'm
puzzled as to why. Is there something that SSL throws into the mix that
would change the result here?
The user guide threading page says,
"One main side effect of connection management is that connections must
be manually released when no longer used. ... The application therefore
must manually release the connection by calling releaseConnection() on
the method after the response body has been read."
MultiThreadedHttpConnectionManager connectionManager = new
MultiThreadedHttpConnectionManager(); HttpClient client = new
HttpClient(connectionManager); ... // and then from inside some thread
executing a method GetMethod get = new
GetMethod("http://jakarta.apache.org/"); try {
client.executeMethod(get); // print response to stdout
System.out.println(get.getResponseBodyAsStream()); } finally { // be
sure the connection is released back to the connection // manager
get.releaseConnection(); }
So, I guess what I'm confused about is, how does implementing your own
releaseConnection() function in another ConnectionManager class (which
force-closes connections) cause the connections to close, if you have to
manually call the releaseConnection() function associated with an
HttpMethod instance (GetMethod, etc).
>From what I can tell, GetMethod (as an example) ultimately inherits
releaseConnection() from the HttpMethodBase class. I assumed that the
HttpMethodBase class actually implements this method as I can't tell
from the JavaDocs that it inherits or implements this method from
another class. I don't see the complete connection between the
releaseConnection() of the custom ConnectionManger class and that of the
GetMethod class.
Sorry if that was long-winded. If I can clarify any points here, please
let me know.
Thanks again,
Jeremy Hicks
Novell, Inc., the leading provider of information solutions
http://www.novell.com
>>> Oleg Kalnichevski <ol...@apache.org> 6/27/2006 9:09 AM >>>
On Tue, 2006-06-27 at 09:02 -0600, Jeremy Hicks wrote:
> My reason for wanting to join was to thank all of you for a great
> library and to ask if anybody has code available to do exactly what
the
> docs suggest in this section of the user guide:
>
>
http://jakarta.apache.org/commons/httpclient/performance.html#Connection_persistence
>
>
> "The easiest way to disable connection persistence is to provide or
> extend a connection manager that force-closes connections upon
release
> in the releaseConnection (
>
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/HttpConnectionManager.html#releaseConnection(org.apache.commons.httpclient.HttpConnection)
> ) method."
>
> I would like to be able to force connections to not be persistent
while
> still using the multi-threaded http connection manager. If there is
code
> already available, that would be great. I think that just changing
the
> current multi-threaded http connection manager might be trivial, but
I'm
> not exactly sure what code to add to force the connections to close.
>
>
http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java?view=markup
>
Jeremy,
This will do the trick
public class MyHttpConnectionManager extends
MultiThreadedHttpConnectionManager {
public void releaseConnection(final HttpConnection conn) {
if (conn == null) {
return;
}
conn.close();
super.releaseConnection(conn);
}
}
Oleg
>
> Thanks
>
>
> Jeremy Hicks
> Novell, Inc., the leading provider of information solutions
> http://www.novell.com ( http://www.novell.com/ )
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Jeremy Hicks <je...@novell.com>.
Thanks, Oleg. That's just what I was looking for!
Jeremy Hicks
Novell, Inc., the leading provider of information solutions
http://www.novell.com
>>> Oleg Kalnichevski <ol...@apache.org> 6/27/2006 9:09 AM >>>
On Tue, 2006-06-27 at 09:02 -0600, Jeremy Hicks wrote:
> My reason for wanting to join was to thank all of you for a great
> library and to ask if anybody has code available to do exactly what
the
> docs suggest in this section of the user guide:
>
>
http://jakarta.apache.org/commons/httpclient/performance.html#Connection_persistence
>
>
> "The easiest way to disable connection persistence is to provide or
> extend a connection manager that force-closes connections upon
release
> in the releaseConnection (
>
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/HttpConnectionManager.html#releaseConnection(org.apache.commons.httpclient.HttpConnection)
> ) method."
>
> I would like to be able to force connections to not be persistent
while
> still using the multi-threaded http connection manager. If there is
code
> already available, that would be great. I think that just changing
the
> current multi-threaded http connection manager might be trivial, but
I'm
> not exactly sure what code to add to force the connections to close.
>
>
http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java?view=markup
>
Jeremy,
This will do the trick
public class MyHttpConnectionManager extends
MultiThreadedHttpConnectionManager {
public void releaseConnection(final HttpConnection conn) {
if (conn == null) {
return;
}
conn.close();
super.releaseConnection(conn);
}
}
Oleg
>
> Thanks
>
>
> Jeremy Hicks
> Novell, Inc., the leading provider of information solutions
> http://www.novell.com ( http://www.novell.com/ )
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Force-close connections queston
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2006-06-27 at 09:02 -0600, Jeremy Hicks wrote:
> My reason for wanting to join was to thank all of you for a great
> library and to ask if anybody has code available to do exactly what the
> docs suggest in this section of the user guide:
>
> http://jakarta.apache.org/commons/httpclient/performance.html#Connection_persistence
>
>
> "The easiest way to disable connection persistence is to provide or
> extend a connection manager that force-closes connections upon release
> in the releaseConnection (
> http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/HttpConnectionManager.html#releaseConnection(org.apache.commons.httpclient.HttpConnection)
> ) method."
>
> I would like to be able to force connections to not be persistent while
> still using the multi-threaded http connection manager. If there is code
> already available, that would be great. I think that just changing the
> current multi-threaded http connection manager might be trivial, but I'm
> not exactly sure what code to add to force the connections to close.
>
> http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java?view=markup
>
Jeremy,
This will do the trick
public class MyHttpConnectionManager extends
MultiThreadedHttpConnectionManager {
public void releaseConnection(final HttpConnection conn) {
if (conn == null) {
return;
}
conn.close();
super.releaseConnection(conn);
}
}
Oleg
>
> Thanks
>
>
> Jeremy Hicks
> Novell, Inc., the leading provider of information solutions
> http://www.novell.com
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org