I used JaxwsDynamicClientFactory to call https web service, and use the following code to work around the ssl checking, because the webservice ssl certificate is a self-signed one.
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();
}
But I when i invoke the code, i got the exception:
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
...
Which make me confused is that when I use HttpPost to send the soap message(Of course I used some work-around to skip ssl validation), it can successfully return response, but when using JaxwsDynamicClientFatory to generate dynamic client, it fails.
Is is something related with the ssl work-around part of the code?
Can anyone help me? Thanks very much.