Rufen Sie den SOAP-Webdienst über die Windows-Proxyeinstellungen in Java auf

Ich schreibe eine eigenständige Java-App. Ich muss die Proxy-Einstellungen des Standardsystems (Windows XP, 7) verwenden, um die SOAP-Webdienste über das HTTPS-Protokoll aufzurufen.

Zum Ermitteln der System-Proxy-Einstellungen verwende ich die ProxySelector-Klasse. Hier ist der Code:

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");

Und so initialisiere ich die Verbindung:

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();

Ich verstehe nicht, warum es keine gibtProxy.Type.HTTPS? Wenn ich eine Webdienstmethode aufrufe, erhalte ich die folgenden Fehler.

Mit eingestelltem http-Proxy:

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.

und mit eingestelltem https-Proxy:

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.

Mache ich es falsch?

Antworten auf die Frage(0)

Ihre Antwort auf die Frage