HI, I am trying to connect to the elasticsearch server using basic credentials and receiving the "Unrecognized SSL message, plaintext connection?" error.
Appreciate your help. Thanks!
if (restClient == null) {
try {
Header[] headers = {new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), new BasicHeader("Role", "Read")};
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("email@domain.com", "password"));
restClient = RestClient.builder(new HttpHost("myhost", "9200" "https")).setDefaultHeaders(headers)
.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
httpClientBuilder.disableAuthCaching(); //if received 401 , then try sending authentication, if not,reuse previous credentials.
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
}).build();
}catch (Exception e ){
System.out.println("Error Creating RestClient:" + e.getMessage());
}
}
return restClient;
}