To get the proxy address

Hi Is there any api in jdk1.4 to get the proxy address.. RegardsSharon
[99 byte] By [Sharon_Homea] at [2007-11-27 8:50:33]
# 1

hi,

try with out execute webstart,

import java.net.InetSocketAddress;

import java.net.Proxy;

import java.net.ProxySelector;

import java.net.URI;

import java.net.URL;

import java.util.Iterator;

import java.util.List;

import com.sun.java.browser.net.ProxyInfo;

import com.sun.java.browser.net.ProxyService;

public class MainTest {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

//detect("http://www.myuniportal.com");

detect2();

}

public static void detect2() {

try {

System.setProperty("java.net.useSystemProxies","true");

List l = ProxySelector.getDefault().select(

new URI("http://www.yahoo.com/"));

for (Iterator iter = l.iterator(); iter.hasNext(); ) {

Proxy proxy = (Proxy) iter.next();

System.out.println("proxy type : " + proxy.type());

InetSocketAddress addr = (InetSocketAddress)

proxy.address();

if(addr == null) {

System.out.println("No Proxy");

} else {

System.out.println("proxy hostname : " +

addr.getHostName());

System.out.println("proxy port : " +

addr.getPort());

}

}

} catch (Exception e) {

e.printStackTrace();

}

}

public static void detect(String location)

{

String proxyHost;

int proxyPort;

try {

ProxyInfo info[] = ProxyService.getProxyInfo(new URL(location));

if(info != null && info.length>0)

{

proxyHost = info[0].getHost();

proxyPort = info[0].getPort();

System.out.println("PROXY = " + proxyHost + ":" + proxyPort);

}

}catch (Exception ex) {

System.err.println(

"could not retrieve proxy configuration, attempting direct connection." + ex);

}

}

}

**code taken from tdanecito, in java.net forums

drvijayy2k2a at 2007-7-12 21:01:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...