HTTP传输错误:java.net.ConnectException:连接超时:连接

时间:2017-11-15 12:48:15

标签: java web-services ssl https

在这里,我正在创建客户端项目并尝试调用/使用soap webservice。

但每次都会遇到同样的错误 HTTP传输错误:java.net.ConnectException:连接超时:connect

它非常安全,供应商提供了使用它的证书和密码。

我对SSL配置有点困惑。如果错误,请检查以下代码并建议正确的方法来执行所有SSL配置。

systemProps.setProperty("javax.net.ssl.keyStore", new File("Path of Certificate").getAbsolutePath());
            systemProps.setProperty("javax.net.ssl.keyStorePassword", "***");
            systemProps.setProperty("javax.net.ssl.keyStoreType", "pkcs12");
            systemProps.setProperty("java.net.useSystemProxies", "true");


            String provider = System.getProperty("javax.net.ssl.keyStoreProvider");
            String keyStoreType = systemProps.getProperty("javax.net.ssl.keyStoreType");
            KeyStore ks = null;
            if (provider != null) {
                ks = KeyStore.getInstance(keyStoreType, provider);
            } else {
                ks = KeyStore.getInstance(keyStoreType);
            }

            InputStream ksis = null;
            String keystorePath = systemProps.getProperty("javax.net.ssl.keyStore");
            String keystorePassword = systemProps.getProperty("javax.net.ssl.keyStorePassword");
            if (keystorePath != null && !"NONE".equals(keystorePath)) {
                ksis = new FileInputStream(keystorePath);
            }

            try {
                ks.load(ksis, keystorePassword.toCharArray());
            } finally {
                 if (ksis != null) { ksis.close(); }
            }

            KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            kmf.init(ks, keystorePassword.toCharArray());
            // Note that there is no property for the key password itself, which may be different.
            // We're using the keystore password too.

            SSLContext sc = SSLContext.getInstance("SSLv3");
            sc.init(kmf.getKeyManagers(), null, null);
            ((BindingProvider) ps).getRequestContext().put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory", sc.getSocketFactory());

            Response response = ps.submitRequest(request); service call. 
            System.out.println(response.toString());

在这里,我没有在任何地方提供网络服务URL,我也不知道在上面的代码中提供了哪些内容。任何建议,如果这可能是问题。

0 个答案:

没有答案