I have looked at HttpClient and it does not seem
to offer a way to use it as simply a means of
doing the CONNECT and proxy auth stuff and then
returning the resulting Socket. I would like to
do this to tunnel a non-HTTP protocol,
specifically the JXTA TCP-based protocol (not
JXTA's HTTP stuff).
Is there an way to do this with the existing
HttpClient API? The fact that HttpConnection
holds the Socket as private instance variable
and provides no get/setters suggests that there
is not.
If not, what do you think of the following
suggestions to make HttpClient work for to this
type of use. The design below is geared for the
minimal distrubance of the existing HttpClient
API and is not the cleanest way to do it.
Changes to HttpClient:
1. augment the Protocol class to include a
"getProxySocketFactory()" method and make
HttpConnection class use this method instead
of creating DefaultProtocolSocketFactory for
secure and proxied connections. The Protocol
constructor that had the
SecureProtcolSocketFactory arg also needs an
additional arg to specifiy this new factory.
2. add public getSocket() and setSocket()
methods to the HttpConnection class.
3. Provide a NullMethod class whose execute()
method does nothing but keep the
HttpConnection parameter for later retrival
via getter on the NullMethod object.
4. Provide a NoOpSecureProtocolSocketFactory
whose create(socket,...) method simply
returns back the socket argument.
To use the above setup to tunnel through a web
proxy you'd do the following
- create/register a Protocol object that
returns NoOpSecureProtocolSocketFactory
from its getSocketFactory and returns a
DefaultProtocolSocketFactory or other for
the new "getProxySocketFactory()" method
described above. In JXTA'S case the
proxySocketFactory would not be the
default one from HttpClient in order to
leverage Jxta's socket creation class for
the hop to the web proxy).
- create NullMethod object
- create HttpClient
- create HostConfiguration with appropriate
proxy info
- create HttpState and add appropriate
authentication credentials
- create SimpleHttpConnectionManager
- call httpClient.executeMethod(
hostConfiguration, nullMethod, httpState)
- get HttpConnection from NullMethod
(NullMethod captures httpConnection on its
execute() call)
- get Socket from HttpConnection and stash
it, then setSocket( null ) on
HttpConnection so releasing the connection
does not close it. This socket is the goal
of the whole exercise.
- httpState.getConnectinManger.releaseConnection();
What do you think?
Thanks in advance,
/Mike Sample
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]