Java – how to disable certificate validation in jax-ws client?

How to use javax xml. ws. Service disable certificate validation in jax-ws client?

I try to create a fully trusted trustmanager in sslsocketfactory and try to bind it to bindingprovider

SSLContext sc = SSLContext.getInstance("SSL"); 
sc.init(null,trustAllCerts,new java.security.SecureRandom()); 

Map<String,Object> ctxt = ((BindingProvider) wsport ).getRequestContext(); 
ctxt.put(JAXWSProperties.SSL_SOCKET_FACTORY,sc.getSocketFactory());

But I still get an exception: unable to find a valid authentication path to the requested target

But it works when I use it

HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

There is still a way to make javax xml. ws. Service uses the httpsurlconnection I created?

Solution

I found a solution here:

I am using this solution to call two static methods on the static block of the main class, as shown below:

static {
    SSLUtilities.trustAllHostnames();
    SSLUtilities.trustAllHttpsCertificates();
}

I hope this can help

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>