等效于wsimport的org.apache.axis.components.net.SunFakeTrustSocketFactory

当我使用Apache Axis生成webservice客户端存根时,我通过调用以下方法使用客户端存根在我的代码中禁用服务器证书信任检查

AxisProperties.setProperty("axis.socketSecureFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory"); 

如何禁用通过运行wsimport生成的客户端存根的信任检查?

我在运行一些测试代码时使用它。

在该类中发生的所有事情都是提供虚假的信任存储管理器 ,它信任任何东西 。 知道了这一点,你可以使用这篇文章并把它放在一起。

  1. 首先是易信任经理

     public class EasyTrustManager implements X509TrustManager { public void checkClientTrusted(X509Certificate[] chain, String authType) { //do nothing } public void checkServerTrusted(X509Certificate[] chain, String authType) { //do nothing } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } } 
  2. 然后将您的信任管理器提供给SSLContext的实例,就像轴正在执行的操作 :

     SSLContext sCtxt = SSLContext.getInstance("SSL"); sCtxt.init(null, new TrustManager[]{new EasyTrustManager()}, new java.security.SecureRandom()); 
  3. 通过基于所有Web服务调用都基于HttpsURLConnection的基础实例的事实调用HttpsURLConnection#setDefaultSSLSocketFactory来设置自定义上下文。 此调用将通过SSLContext#getContext所有 https调用设置上下文

     HttpsURLConnection.setDefaultSSLSocketFactory(sCtxt.getSocketFactory());