Load keystore as usual:
KeyStore keystore = KeyStore.getInstance("PKCS12");
try (InputStream in = Files.newInputStream("keystore.p12")) {
keystore.load(in, "secret".toCharArray());
}
Build a custom SSL context:
import javax.net.ssl.SSLContext;
import org.apache.http.ssl.SSLContexts;
...
SSLContext sslContext = SSLContexts.custom()
// Where is my key/certificate pair?
.loadKeyMaterial(keystore, keyPassword.toCharArray())
// Where is the list of trusted CA certificates?
.loadTrustMaterial(keystore, /* use default trust strategy */ null)
.build();
Build an HTTP client using the former context:
ClosableHttpClient httpClient = HttpClients.custom()
.setSSLContext(sslContext)
// .. other configurations ...
.build();