我使用JaxwsDynamicClientFactory調用https web服務,並使用以下代碼來解決ssl檢查問題,因爲webservice ssl證書是自簽名證書。JaxwsDynamicClientFactory無法調用webservice
String wsUrl = "https://218.17.179.67:8443/QhicPos/doService?wsdl";
String method = "doPosRequest";
QName qName = new QName("http://service.pos.qhic.com/", method);
HttpsURLConnection.setDefaultSSLSocketFactory(TrustAnyFactory.getInstance().getSslContext().getSocketFactory());
HostnameVerifier allHostsValid = (hostname, sslSession) -> true;
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
Client client = clientFactory.createClient(wsUrl);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
conduit.getClient().setReceiveTimeout(0);
httpClientPolicy.setConnectionTimeout(6000000);
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setReceiveTimeout(6000000);
conduit.setClient(httpClientPolicy);
try {
Object[] rst = client.invoke(qName, new Object[]{xmlRequest});
System.out.println(rst[0].toString());
} catch (Exception e) {
e.printStackTrace();
}
但我當我調用的代碼中,我得到了異常:
org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
Waring: Interceptor for {http://service.pos.qhic.com/}PosServiceImplService# {http://service.pos.qhic.com/}doPosRequest has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Operation timed out
at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:108)
at org.apache.cxf.wsdl.interceptors.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:324)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:277)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:297)
at HttpsWebServiceClient.getClient(HttpsWebServiceClient.java:65)
at HttpsWebServiceClient.main(HttpsWebServiceClient.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: com.ctc.wstx.exc.WstxIOException: Operation timed out
at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:255)
at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:106)
... 14 more
Caused by: java.net.ConnectException: Operation timed out
...
這使我感到困惑的是,當我使用HttpPost發送SOAP消息(當然,我用了一些工作 - 繞過跳過ssl驗證),它可以成功返回響應,但是當使用JaxwsDynamicClientFatory生成動態客戶端時,它會失敗。
是什麼與代碼的ssl工作區部分有關?
任何人都可以幫助我嗎?非常感謝。
我注意到,Web服務使用IP過濾,使我的ip進入白名單後,現在我被困在另一個異常: 連接出 – user2605926