我有证书的位置。有人可以指导我如何将证书添加到RestTemplate中的HTTP标头。下面是我如何构建RestTemplate。证书需要名称为ssl-client-cert。这应该在代码中完成还是在Web服务器上配置?
public RestTemplate restTemplate(RestTemplateBuilder builder) throws Exception {
SSLContext sslContext;
KeyStore keystore = KeyStore.getInstance("JKS");
FileInputStream ks = new FileInputStream("<path>");
FileInputStream ts = new FileInputStream("<path>");
keystore.load(ks,"changeit".toCharArray());
KeyStore truststore = KeyStore.getInstance("JKS");
truststore.load(ts,"changeit".toCharArray());
sslContext = SSLContextBuilder.create()
.loadKeyMaterial(keystore, global.getstorePass().toCharArray())
.loadTrustMaterial(truststore, new TrustSelfSignedStrategy())
.build();
HttpClient client = HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.build();
return builder.requestFactory(new HttpComponentsClientHttpRequestFactory(client))
.build();
}