我正在编写一个独立的Java应用程序。 我必须使用默认系统(Windows XP,7)代理设置来使用HTTPS协议调用SOAP Web服务。
要确定系统代理设置,我使用ProxySelector类。这是代码:
System.setProperty("java.net.useSystemProxies", "true");
List proxies = ProxySelector.getDefault().select(new URI("https://www.google.com/"));
for (Iterator iter = proxies.iterator(); iter.hasNext();) {
Proxy proxy = (Proxy) iter.next();
InetSocketAddress address = (InetSocketAddress) proxy.address();
if (address == null) {
UTLogger.getLogger().debug("No proxy (direct connection)");
} else {
if (proxy.type().equals(Proxy.Type.HTTP)) {
System.setProperty("http.proxyHost", address.getHostName());
System.setProperty("http.proxyPort", String.valueOf(address.getPort()));
System.setProperty("https.proxyHost", address.getHostName());
System.setProperty("https.proxyPort", String.valueOf(address.getPort()));
} else if (proxy.type().equals(Proxy.Type.SOCKS)) {
System.setProperty("socksProxyHost", address.getHostName());
System.setProperty("socksProxyPort", String.valueOf(address.getPort()));
}
}
}
System.setProperty("java.net.useSystemProxies", "false");
以下是我初始化连接的方法:
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[]{new TrustDummy()}, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
servicePort = new MyPort(new URL(wsdlLocation), new QName(nameSpaceURI, localPart)).getMyPortSoap();
我不明白为什么没有Proxy.Type.HTTPS
?如果我调用Web服务方法,我会收到以下错误。
使用http代理设置:
javax.xml.ws.WebServiceException: Failed to access the WSDL at: ht tps://...?wsdl. It failed with: Got Unrecognized SSL message, plaintext connection? while opening stream from ht tps://...?wsdl.
并使用https代理集:
javax.xml.ws.WebServiceException: Failed to access the WSDL at: ht tps://...?wsdl. It failed with: Got Unable to tunnel through proxy. Proxy returns "HTTP/1.0 403 Forbidden" while opening stream from ht tps://...?wsdl.
我做错了吗?