Skip to content

Commit

Permalink
Issue elastic#23231 : RestClient should use system properties for SSL
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
DESKTOP-QD770NQ\Jing committed Mar 22, 2017
1 parent 2163b23 commit c1019a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

}

}

2 comments on commit c1019a7

@hwan531
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work.

Simple yet effective

@C-Bish
Copy link

@C-Bish C-Bish commented on c1019a7 Mar 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good self-documenting code with a good test case to back it up. Could add in comments but not essential as it is easy to understand

Please sign in to comment.