簡體   English   中英

SOAP Web服務需要在java中使用https協議發送請求

[英]SOAP Web service need to send request using https protocol in java

我需要使用https協議向我的Web服務發送請求。 使用SOAP UI它工作正常並提供對https請求的響應,但是如果我發送https請求它提供以下異常javax.xml.ws.WebServiceException:無法訪問WSDL: https:// abc:8443 / xyz / FileTransferService?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)

如果要使用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/

我知道這是一個相當古老的問題,但也許答案永遠不會錯。

通常,當JVM cacerts文件不包含簽署了服務器SSL證書的根CA證書時,就會發生這種情況。 但是請注意哪個JVM正在運行,因此應編輯哪個cacerts文件。 你可以在$JAVA_HOME/jre/lib/security/下找到cacerts文件

如果您使用的是glassfish 3,則應編輯特定域配置目錄下的cacerts.jks文件,而不要編輯公共JVM運行時文件夾中的文件。

您可能已在SOAP UI中關閉了SSL證書檢查。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM