Friday, October 03, 2008

Proxy And Java Web Start

When running on client environent, Java Web Start is using JavaScript PAC file (proxy auto-config), completely ignoring system environment settings, for example, like "(protocol).nonProxyHosts" etc. In my case, users are not authorized to change their own default proxy settings and everybody are enforced to use some specific address.

The problem occurs, when you need something, like a different port for a web service that is running with SSL. In that case Proxy server will return an error, encouraging client to connect only through defined ports.

Here is a cure how to turn off proxy settings within Java Web Start, having no deal with the system configuration (including javaws.cfg):

ProxySelector.setDefault(new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
List<Proxy> proxyList = new ArrayList<Proxy>();
proxyList.add(Proxy.NO_PROXY);
return proxyList;
}

@Override
public void connectFailed(URI uri,
SocketAddress socketAddress,
IOException ioException) {
}
});

The object ProxySelector is a global object that is used by all the handlers. Now in this case it will return a default Proxy object that is DIRECT connection. It is equivalent to setting javaws.cfg.proxy.setting=NONE in javaws.cfg file.

No comments: