2012-11-16 18 views
0

我对我的Web服务建立SSL连接有一些疑问。 所以我用CXF的工具“WsdlToJava”生成了一个java web服务项目。现在我不想使用我的Web服务,该服务托管在使用SSL协议访问的服务器上。用于使用Web服务的SSL连接

当我尝试关注此页面How to configure the HTTPConduit for the SOAP Client时,我收到一些SSL问题。我更换这一部分:

URL wsdl = getClass().getResource("wsdl/greeting.wsdl"); 
SOAPService service = new SOAPService(wsdl, serviceName); 
Greeter greeter = service.getPort(portName, Greeter.class); 

由:

URL WSDL_LOC = new URL("https://myserver.com/ws/myWS?wsdl"); 
MyWS_Service myws_serv = new MyWS_Service(WSDL_LOC); 
MyWS mywebservice = myws_serv.getMyWSSOAP(); 

,但它不能对这个代码的行Seconde系列,用于SSL的原因。在本教程中,SSL连接在此部分之后建立,并且我认为他们没有问题,因为他们的示例不会尝试在某个服务器上获取wsdl文件,但会在本地获取它。

在获取WSDL文件之前建立SSL连接需要做些什么? 谢谢

错误消息:

Exception in thread "main" javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service. 
    at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:150) 
    at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:91) 
    at javax.xml.ws.Service.<init>(Service.java:92) 
    at com.myserver.MyWS_Service.<init>(MyWS_Service.java:37) 
    at tests.MyWSTest.main(MyWSTest.java:49) 
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service. 
    at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:94) 
    at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:204) 
    at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:148) 
    ... 4 more 
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'https://myserver.com/ws/myWS?wsdl'.: 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 com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source) 
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source) 
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source) 
    at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:244) 
    at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:191) 
    at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:92) 
    ... 6 more 
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 com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source) 
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown Source) 
    at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source) 
    at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source) 
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source) 
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source) 
    at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source) 
    at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source) 
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source) 
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) 
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source) 
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source) 
    at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source) 
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) 
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source) 
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source) 
    at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source) 
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) 
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) 
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) 
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) 
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source) 
    ... 12 more 
Caused by: 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.validator.PKIXValidator.doBuild(Unknown Source) 
    at sun.security.validator.PKIXValidator.engineValidate(Unknown Source) 
    at sun.security.validator.Validator.validate(Unknown Source) 
    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(Unknown Source) 
    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source) 
    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source) 
    ... 31 more 
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
    at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source) 
    at java.security.cert.CertPathBuilder.build(Unknown Source) 
    ... 37 more 
+1

“*由于SSL原因而失败*”:任何详细信息?也许是一个例外? – Bruno

+0

原因:javax.wsdl.WSDLException:WSDLException:faultCode = PARSER_ERROR:解析问题'https://myserver.com/ws/myWS?wsdl':javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException :PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到有效的证书路径到所请求的目标 –

+0

我编辑了我的第一篇文章的所有细节 –

回答

1

你需要有谁颁发的证书“https://myserver.com/”的签字权的CA证书。最简单的方法是通过Web浏览器获取“https://myserver.com/”的证书,然后检查CA层次结构。获得父证书后,将其导入JKS信任库。当您运行Java程序时,将其作为系统属性“-Djavax.net.ssl.trustStore = yourtruststore.jks”