I am using following code to connect Elasticsearch from java using jks and basic authentication. But I am getting javax.net.ssl.SSLHandshakeException: General SSLEngine problem at the end while doing search.
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(esConfig.getEsUserName(), esConfig.getEsPassword()));
InputStream actualPath = this.getClass().getClassLoader().getResourceAsStream(esConfig.getJksFileName());
KeyStore truststore = KeyStore.getInstance("JKS");
truststore.load(actualPath, esConfig.getKeystorePassword().toCharArray() );
final SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(truststore, null)
.build();
RestClientBuilder builder = RestClient.builder(new HttpHost(esConfig.getEsHost()[0], esConfig.getEsPort(), "https"))
.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider).setSSLContext(sslContext);
}
});
client = new RestHighLevelClient(builder);
This is the code to create client and i did not see any exception there but when using following code to perform search I am getting this error.
searchResponse = client.search(searchRequest);
Any help is appreciated. JKS pasword is correct as able to open the jks file with that password