|
33 | 33 | import org.apache.http.impl.nio.reactor.IOReactorConfig;
|
34 | 34 | import org.apache.http.message.BasicHeader;
|
35 | 35 | import org.apache.http.nio.entity.NStringEntity;
|
| 36 | +import org.apache.http.ssl.SSLContextBuilder; |
| 37 | +import org.apache.http.ssl.SSLContexts; |
36 | 38 | import org.apache.http.util.EntityUtils;
|
37 | 39 | import org.elasticsearch.client.HttpAsyncResponseConsumerFactory;
|
38 | 40 | import org.elasticsearch.client.Response;
|
|
47 | 49 | import java.nio.file.Path;
|
48 | 50 | import java.nio.file.Paths;
|
49 | 51 | import java.security.KeyStore;
|
50 |
| -import java.security.KeyStoreException; |
51 |
| -import java.security.NoSuchAlgorithmException; |
52 |
| -import java.security.cert.CertificateException; |
53 | 52 | import java.util.Collections;
|
54 | 53 | import java.util.Map;
|
55 | 54 | import java.util.concurrent.CountDownLatch;
|
@@ -258,7 +257,7 @@ public void onFailure(Exception exception) {
|
258 | 257 | }
|
259 | 258 |
|
260 | 259 | @SuppressWarnings("unused")
|
261 |
| - public void testCommonConfiguration() throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { |
| 260 | + public void testCommonConfiguration() throws Exception { |
262 | 261 | {
|
263 | 262 | //tag::rest-client-config-timeouts
|
264 | 263 | RestClientBuilder builder = RestClient.builder(new HttpHost("localhost", 9200))
|
@@ -318,13 +317,14 @@ public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpCli
|
318 | 317 | {
|
319 | 318 | Path keyStorePath = Paths.get("");
|
320 | 319 | String keyStorePass = "";
|
321 |
| - final SSLContext sslContext = null; |
322 | 320 | //tag::rest-client-config-encrypted-communication
|
323 |
| - KeyStore keystore = KeyStore.getInstance("jks"); |
| 321 | + KeyStore truststore = KeyStore.getInstance("jks"); |
324 | 322 | try (InputStream is = Files.newInputStream(keyStorePath)) {
|
325 |
| - keystore.load(is, keyStorePass.toCharArray()); |
| 323 | + truststore.load(is, keyStorePass.toCharArray()); |
326 | 324 | }
|
327 |
| - RestClientBuilder builder = RestClient.builder(new HttpHost("localhost", 9200)) |
| 325 | + SSLContextBuilder sslBuilder = SSLContexts.custom().loadTrustMaterial(truststore, null); |
| 326 | + final SSLContext sslContext = sslBuilder.build(); |
| 327 | + RestClientBuilder builder = RestClient.builder(new HttpHost("localhost", 9200, "https")) |
328 | 328 | .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
|
329 | 329 | @Override
|
330 | 330 | public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
|
|
0 commit comments