0
我使用一個wsdl文件創建了一個JAX-WS客戶端。所有在localhost中運行正常,但不在服務器上運行。 我得到產生的原因:javax.net.ssl.SSLHandshakeException ...... 產生的原因:sun.security.validator.ValidatorException:PKIX路徑建設失敗:sun.security.provider.certpath.SunCertPathBuilderException:無法找到有效的認證路徑要求的目標在sun.security.validator.PKIXValidatorJAX WS客戶端和SSL握手異常
我知道,我的JAX-WS客戶端不信任的certificate.So我發現一個快速和骯髒的解決方案在這裏:http://ws.apache.org/xmlrpc/ssl.html,並試圖實施它:
ApiVersion1Service apiVersion1Service = new ApiVersion1Service(wsdlURL, SERVICE_NAME);
APIport = apiVersion1Service.getApiVersion1Port();
// SOAP Header
BindingProvider bindingProvider = (BindingProvider) APIport;
Binding binding = bindingProvider.getBinding();
Map<String, Object> requestContext = bindingProvider.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, WS_URL + accountID);
List<Handler> handlers = binding.getHandlerChain();
handlers.add(new SOAPAuthenticationHandler(username, password));
binding.setHandlerChain(handlers);
// SSL
SSLContext context = SSLContext.getInstance("SSL");
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException {
return;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException {
return;
}
} };
context.init(null, trustAllCerts, new SecureRandom());
SSLSocketFactory sslSocketFactory = context.getSocketFactory();
bindingProvider.getRequestContext().put(/*JAXWSProperties.SSL_SOCKET_FACTORY*/ "com.sun.xml.ws.transport.https.client.SSLSocketFactory" , sslSocketFactory);
....但是我s直到獲得SSLHandshakeException。你有什麼主意嗎? 感謝您的幫助!
不知道這是否會工作,但context.init後添加一行:SSLContext.setDefault(背景); – Xargos
您是否嘗試過使用-Djavax.net.debug = all?仔細追蹤蹤跡,它將變得非常明顯,你的下一個問題應該是:-) – user924272