hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Claassen <mclaas...@ocie.net>
Subject RE: HttpClient, SOCKS proxy, and webstart
Date Tue, 23 Jan 2007 19:12:46 GMT
I feel as if I am on a bit of a roll, so I went ahead and tried my own
socket factory.  Is this all I need to do?  Is the connection timeout all I
need to worry about here?  Granted, I may be making my app not work with a
SOCKS proxy, but does anyone use SOCKS anymore?

public class MySocketFactory implements ProtocolSocketFactory {
        public MySocketFactory() {

        public Socket createSocket(String host, int port) throws
IOException, UnknownHostException {
                return new Socket(host,port);

        public Socket createSocket(String host, int port, InetAddress
localAddress, int localPort) throws IOException, UnknownHostException {
                return new Socket(host,port,localAddress,localPort);

        public Socket createSocket(String host, int port, InetAddress
localAddress, int localPort, HttpConnectionParams params) throws
IOException, UnknownHostException, ConnectTimeoutException {
                Socket rval;
                if (params == null) {
                        throw new IllegalArgumentException("Parameters may
not be null");
                int timeout = params.getConnectionTimeout();
                if (timeout == 0) {
                        rval = new Socket(host, port, localAddress,
                else {
                        rval = new Socket();
                        SocketAddress localaddr = new
InetSocketAddress(localAddress, localPort);
                        SocketAddress remoteaddr = new
InetSocketAddress(host, port);
                        rval.connect(remoteaddr, timeout);
                return rval;

-----Original Message-----
From: Mark Claassen [ <mailto:mclaassen@ocie.net> mailto:mclaassen@ocie.net]
Sent: Tuesday, January 23, 2007 1:45 PM
To: 'HttpClient User Discussion'
Subject: RE: HttpClient, SOCKS proxy, and webstart

Well, I have some good news for you.

Just running the JRE (like through an IDE) the ProxySelector.getDefault()
gives a ProxySelector class or sun.net.spi.DefaultProxySelector Running
through webstart gives class a ProxySelector class of

So, when running in webstart, you can use the
ProxySelector.getDefault().select(URI) to get a list of proxies.  For here,
it is easy to set the proxy in the
org.apache.commons.httpclient.HostConfiguration.  For all the tests I have
performed, this works as expected.

So, now to restate what I was trying to say before:
As long as I set the proxy information in
org.apache.commons.httpclient.HostConfiguration, I don't need to create a
Socket with Socket(Proxy), I just need to create a socket using the values
in the createSocket method and and HttpClient will worry about the Proxy

Thanks again,

-----Original Message-----
From: Roland Weber [ <mailto:ROLWEBER@de.ibm.com>
Sent: Tuesday, January 23, 2007 12:28 PM
To: HttpClient User Discussion
Subject: RE: HttpClient, SOCKS proxy, and webstart

Hi Mark,

> The class sun.net.NetworkClient just basically creates a new socket
> via
> Socket() or Socket(Proxy p).  Inefficiencies aside, could I just
> create
> SocketFactory that just creates a new socket every time?

Yes you could. Efficiency is not a problem, you'll have to create a new
Socket object anyway.

> Since it seems
> that HttpClient manages the proxies and all that, it seems I would not
> to bother with that.

You do need to bother. HttpClient expects to be *told* which proxy to use.
That's for HTTP proxies. If "and all that" refers to SOCKS proxies,
HttpClient does not do anything with them. This has to be handled in the
socket factories. IIRC, standard sockets will pick up SOCKS settings that
are passed to the JVM as system properties. But I don't know what else
happens in web start.
The feature of web start to determine browser settings for SOCKS and HTTP
proxies is supposed to make your life easier. Unfortunately that happens
only if you use HttpURLConnection. I have no idea how you could get to the
browser settings for HTTP proxy in web start. If you find something out,
please let us know.

hope that helps,

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

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