以下のようにトラストストアをロードし、HttpsUrlConnectionに設定できるSSLContextに設定することができます。これはデフォルトを使用した例なので、適切なアルゴリズム、プロトコル、トラストストアのタイプに置き換える必要があります。
try (FileInputStream truststoreFile = new FileInputStream("path/to/your/truststore.jks")) {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore truststore = KeyStore.getInstance(KeyStore.getDefaultType());
char[] trustorePassword = "<truststorePassword".toCharArray();
truststore.load(truststoreFile, trustorePassword);
trustManagerFactory.init(truststore);
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
KeyManager[] keyManagers = {};//if you have key managers;
sslContext.init(keyManagers, trustManagerFactory.getTrustManagers(), new SecureRandom());
URL httpsUrl = new URL("<your https url>");
URLConnection urlConnection = httpsUrl.openConnection();
} catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException e) {
//handle exception
} catch (KeyManagementException e) {
//handle exception
}
あなたの 'server.xml'とは何ですか? ''要素では、 'trustStoreRef =" defaultTrustStore "を設定することができます。これは設定されたトラストストアを指します。これを省略すると、デフォルトのトラストストアがキーストアになります。詳細については、[Liberty:SSL構成属性](https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.wlp.nd.doc/ae/rwlp_ssl.html)を参照してください。 。 –
Gas
ありがとうございます。私はすでにSSLを私の 'server.xml'に設定しています。私は以下の最初の答えに記述されていることをやり終えた。 – Westy