无法调用Web服务

时间:2014-10-29 22:36:47

标签: java web-services ssl keystore client-certificates

我正在尝试调用我通过POST发送xml数据的Web服务,然后我收到回复。

生产网络服务需要我获得的证书。我已将此证书导入我的密钥库并在我的客户端代码中使用它,但我一直在调整错误。

你知道造成这个问题的原因吗?

17:30:15,214 ERROR [stderr] (DefaultQuartzScheduler_Worker-6) java.net.ConnectException: Operation timed out
17:30:15,214 ERROR [stderr] (DefaultQuartzScheduler_Worker-6)   at java.net.PlainSocketImpl.socketConnect(Native Method)
17:30:15,215 ERROR [stderr] (DefaultQuartzScheduler_Worker-6)   at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
17:30:15,215 ERROR [stderr] (DefaultQuartzScheduler_Worker-6)   at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
17:30:15,215 ERROR [stderr] (DefaultQuartzScheduler_Worker-6)   at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
17:30:15,216 ERROR [stderr] (DefaultQuartzScheduler_Worker-6)   at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
17:30:15,216 ERROR [stderr] (DefaultQuartzScheduler_Worker-6)   at java.net.Socket.connect(Socket.java:579)
17:30:15,216 ERROR [stderr] (DefaultQuartzScheduler_Worker-6)   at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:618)
17:30:15,216 ERROR [stderr] (DefaultQuartzScheduler_Worker-6)   at sun.security.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:407)
17:30:15,217 ERROR [stderr] (DefaultQuartzScheduler_Worker-6)   at sun.security.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:88)
17:30:15,217 ERROR [stderr] (DefaultQuartzScheduler_Worker-6)   at hot.com.mhd.erp.action.client.PushStatusClient.pushXML(PushStatusClient.java:478)
17:30:15,217 ERROR [stderr] (DefaultQuartzScheduler_Worker-6)   at main.com.mhd.erp.sched.StatusPushJob.execute(StatusPushJob.java:73)
17:30:15,218 ERROR [stderr] (DefaultQuartzScheduler_Worker-6)   at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
17:30:15,218 ERROR [stderr] (DefaultQuartzScheduler_Worker-6)   at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)

该公司已将IP地址列入白名单而不是在防火墙后运行,此连接问题是否与未正确使用的证书相关?我已经将它们导入我的密钥库但是我需要在我的代码或JBoss(托管应用程序)中做其他事情

我还做了这个来设置密钥库,密码,类型等。

System.setProperty("https.protocols", "SSLv3");
    System.setProperty("javax.net.ssl.trustStore", ERPGetProperty.erpGetProperty("pathToKeyStore"));
    System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
    System.setProperty("javax.net.ssl.trustStoreType", "JKS");
    System.setProperty("javax.net.ssl.keyStore", ERPGetProperty.erpGetProperty("pathToKeyStore"));
    System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
    System.setProperty("javax.net.ssl.keyStoreType", "JKS"); 

URL url = new URL(address);
    HttpsURLConnection con  = (HttpsURLConnection) url.openConnection();

    con.setConnectTimeout(10000);
    SSLSocketFactory sslSocketFactory  = (SSLSocketFactory) SSLSocketFactory.getDefault();


    con.setSSLSocketFactory(sslSocketFactory);

    con.setRequestMethod("POST");
    con.setUseCaches(true);
    con.setRequestProperty("Content-type", "text/xml");
    con.setRequestProperty("Host", "pwspg.newcorp.com");
    con.setRequestProperty("Content-Length", Integer.toString(xml.length()));
    con.setRequestProperty("SOAPAction", address);
    con.setDoOutput(true);
    con.setDoInput(true);

    userPass = username + ":" + password;
    byte[] encodeBytes = Base64.encodeBase64(userPass.getBytes());
    String encode = new String(encodeBytes);
    con.setRequestProperty("Authorization", "Basic " + encode);

    out = con.getOutputStream();

    out.write(b);

更新:我再次得到网络服务所有者的确认,我的IP地址已被列入白名单。我使用telnet测试主机和连接超时。如果我ping它,我会收到数据包。还有什么可能导致无法连接到Web服务的问题?

我被告知这与证书无关,但我似乎无法找到问题所在。这是我的问题吗?

1 个答案:

答案 0 :(得分:0)

我认为这与证书无关。

您是否尝试使用telnet从主机连接到服务的主机?

$ telnet google.com 443
Trying 173.194.44.133...
Connected to google.com.
Escape character is '^]'.

立即连接。

$ telnet pwspg.newcorp.com 443
Trying 38.176.90.103...

永远等待。是否会发生白名单不成功?

来自

的地址
URL url = new URL(address);

是否明确包含'httpS'和端口号?