JaxwsDynamicClientFactory无法调用webservice

时间:2016-08-18 02:07:44

标签: web-services ssl https cxf

我使用JaxwsDynamicClientFactory来调用https Web服务,并使用以下代码来解决ssl检查问题,因为webservice ssl证书是一个自签名证书。

    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解决方法有关?

任何人都可以帮助我吗?非常感谢。

2 个答案:

答案 0 :(得分:0)

java.net.ConnectException: Operation timed out表示您的请求未在时间范围内得到回复。查看https://stackoverflow.com/a/5663054/6371459

我已经重现了执行代码的问题。 WSDL指向218.17.179.67/QhicPos/doService,这对我来说是不可访问的。此问题在任何SSL连接之前(实际上不需要,因为端点是使用http发布的)

可能存在防火墙保护或需要代理

答案 1 :(得分:0)

mv-layer