Skip to content

Commit 8bb4da7

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 f471d1c commit 8bb4da7

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
@@ -116,11 +116,13 @@ https://hc.apache.org/httpcomponents-asyncclient-dev/httpasyncclient/apidocs/org
116116

117117
[source,java]
118118
--------------------------------------------------
119-
KeyStore keystore = KeyStore.getInstance("jks");
119+
KeyStore truststore = KeyStore.getInstance("jks");
120120
try (InputStream is = Files.newInputStream(keyStorePath)) {
121-
keystore.load(is, keyStorePass.toCharArray());
121+
truststore.load(is, keyStorePass.toCharArray());
122122
}
123-
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200))
123+
SSLContextBuilder sslBuilder = SSLContexts.custom().loadTrustMaterial(truststore, null);
124+
final SSLContext sslContext = sslBuilder.build();
125+
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200, "https"))
124126
.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
125127
@Override
126128
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {

0 commit comments

Comments
 (0)