web-services - JaxwsDynamicClientFactory 无法调用 webservice

标签 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 变通部分相关?

谁能帮帮我?非常感谢。

最佳答案

java.net.ConnectException: Operation timed out 表示您的请求没有在时间范围内得到响应。检查https://stackoverflow.com/a/5663054/6371459

我已经重现了执行您的代码时遇到的问题。 WSDL 指向我无法访问的 218.17.179.67/QhicPos/doService。此问题早于任何 SSL 连接(实际上不需要,因为端点是使用 http 发布的)

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

关于web-services - JaxwsDynamicClientFactory 无法调用 webservice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39008884/

相关文章:

php - 无法访问 Web 服务代码中的 HTTP PUT 数据

asp.net - 你如何将http请求转发到https url

SSL 证书在连接时过期

ios https和基本身份验证和发布请求

ssl - 当 HTTPS 站点使用 "ISRG Root X1"CA 时,Python3.4+requests 2.26 无法验证 SSL 证书 - 为什么?

尝试将文本文件传递到 POST 并将内容转换为 List<Integer> 时出现 Java FileNotFoundException

java - Tomcat 服务处于 Activity 状态但已退出

java - Axis2 实现客户端

java - Nginx SSL 终止代理到 tomcat 8

SSL 编程接口(interface)