* @throws ProxyDetectionException if detection failed
*/
private static ProxyHost detectProxySettingsJDK13(URL sampleURL)
throws ProxyDetectionException
{
ProxyHost result = null;
try {
// Attempt to discover proxy info by asking internal plugin
// code to locate proxy path to server sampleURL...
Class pluginProxyHandler =
Class.forName("sun.plugin.protocol.PluginProxyHandler");
Method getDefaultProxyHandlerMethod =
pluginProxyHandler.getDeclaredMethod("getDefaultProxyHandler",
null);
Object proxyHandlerObj =
getDefaultProxyHandlerMethod.invoke(null, null);
if (proxyHandlerObj != null) {
Class proxyHandlerClass = proxyHandlerObj.getClass();
Method getProxyInfoMethod =
proxyHandlerClass.getDeclaredMethod("getProxyInfo",
new Class[]{URL.class});
Object proxyInfoObject =
getProxyInfoMethod.invoke(proxyHandlerObj,
new Object[] { sampleURL });
if (proxyInfoObject != null) {
Class proxyInfoClass = proxyInfoObject.getClass();
Method getProxyMethod =
proxyInfoClass.getDeclaredMethod("getProxy", null);
boolean useProxy =
(getProxyMethod.invoke(proxyInfoObject, null) != null);
if (useProxy) {
String proxyIP =
(String)getProxyMethod.invoke(proxyInfoObject, null);
Method getProxyPortMethod =
proxyInfoClass.getDeclaredMethod("getPort", null);
Integer portInteger =
(Integer)getProxyPortMethod.invoke(proxyInfoObject, null);
int proxyPort = portInteger.intValue();
if (LOG.isDebugEnabled()) {
LOG.debug("1.3.X: proxy=" + proxyIP+
" port=" + proxyPort);
}
result = new ProxyHost(proxyIP, proxyPort);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("1.3.X reported NULL for " +
"proxyInfo.getProxy (no proxy assumed)");
}