log.info("Attempting to detect proxy settings using platform specific methods"); //$NON-NLS-1$
// #endif
if (localProxyURL != null && localProxyURL.startsWith("browser://")) { //$NON-NLS-1$
URI uri = new URI(localProxyURL);
/*
* Try to determine the proxy settings by first usng platform /
* browser specific method, then the proxy supplied by the Java
* plugin.
*
* TODO be more intelligent about which browse to try first -
* use the userAgent parameter passed from the JSP
*/
String proxyURL = null;
if (userAgent != null) {
// TODO support more browsers
BrowserProxySettings proxySettings = null;
if (userAgent.indexOf("MSIE") != -1) { //$NON-NLS-1$
try {
// #ifdef DEBUG
log.info("Looking for IE"); //$NON-NLS-1$
// #endif
proxySettings = ProxyUtil.lookupIEProxySettings();
} catch (Throwable t) {
// #ifdef DEBUG
log
.error(
"Failed to get IE proxy settings, trying Firefox.", t); //$NON-NLS-1$
// #endif
}
}
if (proxySettings == null
&& userAgent.indexOf("Firefox") != -1) { //$NON-NLS-1$
try {
// #ifdef DEBUG
log.info("Looking for Firefox"); //$NON-NLS-1$
// #endif
proxySettings = ProxyUtil
.lookupFirefoxProxySettings();
} catch (Throwable t) {
// #ifdef DEBUG
log.error(
"Failed to get Firefox proxy settings.", t); //$NON-NLS-1$
// #endif
}
}
if (proxySettings != null) {
// #ifdef DEBUG
log.info("Found some proxy settings."); //$NON-NLS-1$
// #endif
ProxyInfo[] proxyInfo = proxySettings.getProxies();
for (int i = 0; proxyInfo != null
&& i < proxyInfo.length; i++) {
// #ifdef DEBUG
log
.info("Checking if " + obfuscateURL(proxyInfo[i].toUri()) + " is suitable."); //$NON-NLS-1$
// #endif
if (proxyInfo[i].getProtocol().equals("ssl") || proxyInfo[i].getProtocol().equals("https") //$NON-NLS-1$ //$NON-NLS-2$
|| proxyInfo[i].getProtocol().equals("all")) { //$NON-NLS-1$
StringBuffer buf = new StringBuffer("http://"); //$NON-NLS-1$
if (proxyInfo[i].getUsername() != null
&& !proxyInfo[i].getUsername().equals(
"")) { //$NON-NLS-1$
buf.append(proxyInfo[i].getUsername());
if (proxyInfo[i].getPassword() != null
&& !proxyInfo[i].getPassword()
.equals("")) { //$NON-NLS-1$
buf.append(":"); //$NON-NLS-1$
buf.append(proxyInfo[i].getPassword());
}
buf.append("@"); //$NON-NLS-1$
}
buf.append(proxyInfo[i].getHostname());
if (proxyInfo[i].getPort() != 0) {
buf.append(":"); //$NON-NLS-1$
buf.append(proxyInfo[i].getPort());
}
if (uri.getHost() != null) {
buf.append("?"); //$NON-NLS-1$
buf.append(uri.getHost());
}
proxyURL = buf.toString();
break;
}
}