From c1019a7f86251ebeaa1233b52fd335875b7e01c9 Mon Sep 17 00:00:00 2001 From: "DESKTOP-QD770NQ\\Jing" Date: Thu, 23 Mar 2017 01:50:08 +1300 Subject: [PATCH] Issue #23231 : RestClient should use system properties for SSL * RestClientBuilder.java: use method - SystemProperties() to apply system properties in th Rest Client. * RestClientBuilderTest: add new test - testSetSystemProperties() to test if the Rest Client is actully using system properties. TODO: Add detail comments --- .../org/elasticsearch/client/RestClientBuilder.java | 4 +++- .../elasticsearch/client/RestClientBuilderTests.java | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/client/rest/src/main/java/org/elasticsearch/client/RestClientBuilder.java b/client/rest/src/main/java/org/elasticsearch/client/RestClientBuilder.java index 4466a61d9df6d..14ef673c05b71 100644 --- a/client/rest/src/main/java/org/elasticsearch/client/RestClientBuilder.java +++ b/client/rest/src/main/java/org/elasticsearch/client/RestClientBuilder.java @@ -202,7 +202,9 @@ private CloseableHttpAsyncClient createHttpClient() { HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClientBuilder.create().setDefaultRequestConfig(requestConfigBuilder.build()) //default settings for connection pooling may be too constraining - .setMaxConnPerRoute(DEFAULT_MAX_CONN_PER_ROUTE).setMaxConnTotal(DEFAULT_MAX_CONN_TOTAL); + .setMaxConnPerRoute(DEFAULT_MAX_CONN_PER_ROUTE) + .setMaxConnTotal(DEFAULT_MAX_CONN_TOTAL) + .useSystemProperties(); if (httpClientConfigCallback != null) { httpClientBuilder = httpClientConfigCallback.customizeHttpClient(httpClientBuilder); } diff --git a/client/rest/src/test/java/org/elasticsearch/client/RestClientBuilderTests.java b/client/rest/src/test/java/org/elasticsearch/client/RestClientBuilderTests.java index c9243d3aaf6ce..22e79088a663b 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RestClientBuilderTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RestClientBuilderTests.java @@ -176,5 +176,15 @@ private static void assertSetPathPrefixThrows(final String pathPrefix) { assertThat(e.getMessage(), containsString(pathPrefix)); } } + + public void testSetSystemProperties(){ + System.setProperty("http.maxConnections", "??"); + try (RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build()) { + fail("should have failed"); + } catch (NumberFormatException | IOException e1) { + System.clearProperty("http.maxConnections"); + } + + } }