【问题标题】:SOAP Web service need to send request using https protocol in javaSOAP Web服务需要在java中使用https协议发送请求
【发布时间】:2016-03-14 10:00:44
【问题描述】:

我需要使用 https 协议向我的网络服务发送请求。 使用 SOAP UI 它工作正常并为 https 请求提供响应但是如果我发送 https 请求,它会提供以下异常 javax.xml.ws.WebServiceException:无法访问位于 https://abc:8443/xyz/FileTransferService?wsdl 的 WSDL。它失败了:

    sun.security.validator.ValidatorException: PKIX path building failed:       sun.security.provider.certpath.SunCertPathBuilderException: unable to find   valid certification path to requested target.
        at         com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:184)
       at    ##com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:166)
        at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:131)
        at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:267)
       at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:230)

Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
         at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
         at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
         at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
      at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1497)

【问题讨论】:

    标签: java web-services soap https


    【解决方案1】:

    如果你想使用 https,你只需先下载 wsdl,然后将生成的客户端类中的 wsdlLocation 和 url 指向该文件。

    或者像这样生成你的客户

    URL url = new URL("https://......?wsdl");
    QName qname = new QName("NameSpace of the Service", "ServiceName");
    Service service = Service.create(url, qname);
    
    ServiceClass port= service.getPort(ServiceClass.class);
    

    那么你就可以开始使用端口了。

    你可以在网站上找到后面的例子。

    http://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat-ssl-connection/

    哦,我忘了一件事。您必须在您的 java 密钥库中添加信任密钥。以下网站显示了执行此操作的方法。

    http://java.globinch.com/enterprise-java/security/pkix-path-building-failed-validation-sun-security-validatorexception/

    【讨论】:

      【解决方案2】:

      我知道这是一个相当古老的问题,但也许答案永远不会差。

      当 JVM cacerts 文件不包含签署您的服务器 SSL 证书的根 CA 证书时,通常会发生这种情况。但请注意哪个 JVM 正在运行,以便您应该编辑哪个 cacerts 文件。你可以在$JAVA_HOME/jre/lib/security/下找到cacerts文件

      如果您使用的是 glassfish 3,您应该在您的特定域配置目录下编辑 cacerts.jks 文件,而不是在通用 JVM 运行时文件夹中。

      您可能在 SOAP UI 中关闭了 SSL 证书检查。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多