users@jax-ws.java.net

JAX-WS and HTTP Proxies

From: Brad Peabody <bradpeabody_at_scientology.net>
Date: Fri, 5 May 2006 22:24:00 -0700

A simple point, but it would probably be useful to make a mention somewhere in
the JAX-WS-RI docs that you can setup a web service to use an HTTP proxy using
the java.net.ProxySelector facility.

I spent quite some time digging around to find this. I know that this is not
a JAX-WS specific point and is just part of the overall JSE API, but still, in
my case I didn't even think to look in the java.net package until I had
exhausted my googling and had dug into the JAX-WS-RI source, etc. (I didn't
even know about ProxySelector as I'd been using other HTTP clients like Apache
Commons HttpClient, etc.)

Here's the sample code I used to get it up and running:


    public static class LocatorManagerProxySelector extends ProxySelector {
        public List<Proxy> select(URI uri) {
            List<Proxy> myList = new ArrayList<Proxy>();
            myList.add(new Proxy(Type.HTTP,
                        new InetSocketAddress("PROXY_HOST", 8008)));
            return myList;
        }

        public void connectFailed(URI uri,
                SocketAddress sa,
                IOException ioe) {
        }
    }
    
    public static void METHOD_HERE() throws Exception {
        
        ProxySelector.setDefault(new LocatorManagerProxySelector());

        ...

    }


Minor point, but it might help others to just mention it somewhere.