-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Closed
Labels
:Clients/Java Low Level REST ClientMinimal dependencies Java Client for ElasticsearchMinimal dependencies Java Client for Elasticsearch>docsGeneral docs changesGeneral docs changes
Description
The example for Encrypted Communication with the Rest Client isn't working. Seems like the main problem was that the "HttpHost" object needed a 3rd "https" scheme parameter. Tested the following on 5.3.1 and 5.6.0
String keyStoreFile = "file:///opt/elasticsearch-5.6.0/config/x-pack/my_trust_store.jks";
char[] keyStorePass = "password".toCharArray();
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(new URL(keyStoreFile), keyStorePass).build();
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("elastic", "changeme");
credentialsProvider.setCredentials(AuthScope.ANY, creds);
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200, "https"))
.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
return httpClientBuilder.setSSLContext(sslContext).setDefaultCredentialsProvider(credentialsProvider);
}
}).build();
Response response = restClient.performRequest("GET", "/_cluster/health?pretty");
response.getEntity().writeTo(System.out);
Metadata
Metadata
Assignees
Labels
:Clients/Java Low Level REST ClientMinimal dependencies Java Client for ElasticsearchMinimal dependencies Java Client for Elasticsearch>docsGeneral docs changesGeneral docs changes