views:

171

answers:

1

Is there a way of getting internet connection settings (proxy information) being used by java to connect to the internet?

With Java 1.5 you can use the ProxySelector introduced then, is there any way of doing it in jdk1.4?

I tried getting these seeting using the following code snippet, but returning nulls even though i have set my proxy.

String javaVersion = System.getProperty("java.version");
String ip = null;
String port = null;
String noProxyHosts = null;

if (javaVersion.startsWith("1.4")) {
    ip = System.getProperty("proxyHost");
    port = System.getProperty("proxyPort");
    noProxyHosts = System.getProperty("http.nonProxyHosts");
} else {
    ip = System.getProperty("deployment.proxy.http.host");
    port = System.getProperty("deployment.proxy.http.port");
    noProxyHosts = System.getProperty("deployment.proxy.override.hosts");
}

A brief background; I have a webstart Java application that spawns an internal web browser which needs these setting to get going.

+1  A: 

I found this code sample on the Java forums:

  sun.plugin.net.proxy.ProxyInfo pi = sun.plugin.net.proxy.PluginProxyManager.getProxyInfo(url);
  String host = pi.getProxy();
  int port = pi.getPort();

You need to add plugin.jar to your classpath to use this code. I found it in /jre/lib.

The URL to the forum post is: http://forums.sun.com/thread.jspa?threadID=364342&forumID=30

Granger44
i found the code snippet really helpful. http://forums.sun.com/thread.jspa?messageID=1535962#1535962
n002213f