Skip to content

Commit 92830ec

Browse files
committed
[DOCS] improve encrypted communication example in java REST low-level client docs
Include SSLContext creation and add the missing "https" scheme to the host creation. Relates to #26534 Closes #26670
1 parent 7ade7df commit 92830ec

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

docs/java-rest/configuration.asciidoc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ https://hc.apache.org/httpcomponents-asyncclient-dev/httpasyncclient/apidocs/org
9393

9494
[source,java]
9595
--------------------------------------------------
96-
KeyStore keyStore = KeyStore.getInstance("jks");
96+
KeyStore truststore = KeyStore.getInstance("jks");
9797
try (InputStream is = Files.newInputStream(keyStorePath)) {
98-
keyStore.load(is, keyStorePass.toCharArray());
98+
truststore.load(is, keyStorePass.toCharArray());
9999
}
100-
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200))
100+
SSLContextBuilder sslBuilder = SSLContexts.custom().loadTrustMaterial(truststore, null);
101+
final SSLContext sslContext = sslBuilder.build();
102+
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200, "https"))
101103
.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
102104
@Override
103105
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {

0 commit comments

Comments
 (0)