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

use*_*353 8 java axis web-services jax-ws wsimport

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

AxisProperties.setProperty("axis.socketSecureFactory",
     "org.apache.axis.components.net.SunFakeTrustSocketFactory");
Run Code Online (Sandbox Code Playgroud)

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

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

kol*_*sus 6

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

  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;
      }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 然后将您的信任管理器提供给一个实例SSLContext,就像轴正在做的那样:

    SSLContext sCtxt = SSLContext.getInstance("SSL"); 
    sCtxt.init(null, new TrustManager[]{new EasyTrustManager()}, new java.security.SecureRandom()); 
    
    Run Code Online (Sandbox Code Playgroud)
  3. 通过HttpsURLConnection#setDefaultSSLSocketFactory基于所有Web服务调用都基于底层实例的事实进行调用来设置自定义上下文HttpsURLConnection.这个调用将建立的背景下,方式SSLContext#getContext,为所有 HTTPS调用

    HttpsURLConnection.setDefaultSSLSocketFactory(sCtxt.getSocketFactory());  
    
    Run Code Online (Sandbox Code Playgroud)