SOAP:无法调用远程方法。远程主机没有响应

时间:2016-10-05 13:11:40

标签: java ssl soap

我通过jar访问https Web服务,创建服务并且端口也被实例化,但是当尝试调用Web服务的远程方法时,它会抛出以下错误。

com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: A remote host did not respond within the timeout period.

请注意我覆盖了hostnameverifier以验证所有主机名,因为添加到密钥库的证书与我通过jar访问的Web Service的URL具有不同的CN。

javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
                            new javax.net.ssl.HostnameVerifier(){

                                public boolean verify(String hostname,
                                        javax.net.ssl.SSLSession sslSession) 
                                {
                                    mylog.setLog("Hostname Verification successfully overriden.");
                                    return true;
                                }
                            });

我使用的工具是CXF。以下是完整的堆栈跟踪。

com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: A remote host did not respond within the timeout period.
    at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:133)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:154)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:95)
    at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:117)
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:599)
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:558)
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:543)
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:440)
    at com.sun.xml.internal.ws.client.Stub.process(Stub.java:223)
    at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:136)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:110)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:90)
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:119)
    at com.sun.proxy.$Proxy25.transferFileService(Unknown Source)
    at com.mywsclient.cxf.transfer.FileTransfer.transferToWebService(FileTransfer.java:183)
    at com.mywsclient.cxf.transfer.FileTransfer.run(FileTransfer.java:236)
    at java.lang.Thread.run(Thread.java:738)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:908)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:931)
    at java.lang.Thread.run(Thread.java:738)
Caused by: java.net.ConnectException: A remote host did not respond within the timeout period.
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:381)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:243)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:230)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:377)
    at java.net.Socket.connect(Socket.java:539)
    at java.net.Socket.connect(Socket.java:488)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:424)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:538)
    at com.ibm.net.ssl.www2.protocol.https.c.<init>(c.java:64)
    at com.ibm.net.ssl.www2.protocol.https.c.a(c.java:65)
    at com.ibm.net.ssl.www2.protocol.https.d.getNewHttpClient(d.java:15)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:978)
    at com.ibm.net.ssl.www2.protocol.https.d.connect(d.java:32)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1043)
    at com.ibm.net.ssl.www2.protocol.https.b.getOutputStream(b.java:79)
    at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:121)
    ... 19 more

1 个答案:

答案 0 :(得分:0)

最后解决了这个问题,使用的端点与wsdl所在的url不同。管理覆盖与wsdl相同的URL并且工作正常。(注意,我使用的是用于定位wsdl的动态URL。。下面是设置端点的代码。

BindingProvider bp = (BindingProvider) port;
Map<String, Object>req_context_map=bp.getRequestContext();
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, my_url);

干杯。