Recursively change system property at runtime in java

旧时模样 提交于 2019-12-04 15:34:33

Sounds like you want to use a dynamic trust store. You could do this before you open any connection:

    KeyStore ts = KeyStore.getInstance("JKS");
    ts.load(new FileInputStream(new File("Your_New_Trust_Store_Path")), "password".toCharArray());

    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    tmf.init(ts);

    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, tmf.getTrustManagers(), null);

    HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());

    // Open Connection .... etc. ....

You could do this each time your trustStorePath changes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!