Getting ssl error while trying to create httpclient

I am getting the below error while trying to create new http client in 7.8.1 version. Please help.
code : RestHighLevelClient client = new RestHighLevelClient(RestClient. builder ( new HttpHost(getLocalHost(), getPort(), "http")));
Caused by: java.lang.IllegalStateException: could not create the default ssl context
at org.elasticsearch.client.RestClientBuilder.createHttpClient(
at Method)
at org.elasticsearch.client.RestHighLevelClient.(
at org.elasticsearch.client.RestHighLevelClient.(

You can try this:

final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        AuthScope.ANY, new UsernamePasswordCredentials(username, password));
    RestClientBuilder restClientBuilder = RestClient
        .builder(new HttpHost(ip, port, "http"))
        .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
          public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) {
            return httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
    client = new RestHighLevelClient(restClientBuilder);

Thanks for the reply. We are replacing transportclient/ssl plugin with resthighlevelclient and planning to use stunnel. we don't use any username/password. Why is this required.

I saw ssl in your description,and I thought you configured ssl in your ES cluster and kibana

we had it configured but I have removed the ssl plugin and just using RestClient. Do you know from where is the http connection trigerring this SSL.

the RestClientBuilder createHttpClient uses SSL. Is there anyway we can avoid SSL to build this CLient. We do not want to use SSL and use stunnel instead
private CloseableHttpAsyncClient createHttpClient() {
//default timeouts are all infinite
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
if (requestConfigCallback != null) {
requestConfigBuilder = requestConfigCallback.customizeRequestConfig(requestConfigBuilder);

    try {
        HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClientBuilder.create().setDefaultRequestConfig(
            //default settings for connection pooling may be too constraining
            .setTargetAuthenticationStrategy(new PersistentCredentialsAuthenticationStrategy());
        if (httpClientConfigCallback != null) {
            httpClientBuilder = httpClientConfigCallback.customizeHttpClient(httpClientBuilder);

        final HttpAsyncClientBuilder finalBuilder = httpClientBuilder;
        return AccessController.doPrivileged((PrivilegedAction<CloseableHttpAsyncClient>) finalBuilder::build);
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("could not create the default ssl context", e);

If your cluster don't use ssl and your cluster configurations are correct, maybe you can try this:

i tried this RestClientBuilder restClientBuilder = RestClient. builder ( new HttpHost("localhost", 9200, "http"));

client = new RestHighLevelClient(restClientBuilder);
but still the same issue.
Caused by: java.lang.IllegalStateException: could not create the default ssl context
at org.elasticsearch.client.RestClientBuilder.createHttpClient(

it goes to createHttpClient and there i see .setSSLContext(SSLContext.getDefault()) is being used to build http. I think this error is due to that ssl. how can we avoid this.

You can check the configuration in you cluster if there are some configuration like this:*:

Hmm checked yml fime but nothing related to ssl is set.

Caused by: Error constructing implementation (algorithm: Default, provider: SunJSSE, class:$DefaultSSLContext)






at org.elasticsearch.client.RestClientBuilder.createHttpClient(

... 8 more

Caused by: load failed






at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(

at java.lang.reflect.Constructor.newInstance(


... 13 more

Caused by: no password provided, and no callback handler available for retrieving password




... 22 more

In my local environment,I comment the configuration: true true certificate elastic-certificates.p12 elastic-certificates.p12

and then I wrote a demo to get the healthy info of the cluster, the code is following:

public static void main(String[] args) {
    RestHighLevelClient client = new RestHighLevelClient(
            new HttpHost("localhost", 9200, "http")));
    ClusterHealthRequest request = new ClusterHealthRequest();
      ClusterHealthResponse response = client.cluster().health(request, RequestOptions.DEFAULT);
      System.out.println("cluster name: " +response.getClusterName() + " cluster health status: " +response.getStatus());
    }catch (Exception e){


there was no error in the result.

i just ran the program you wrote above in my IDE and got the below error. we are using apache license. In which file do we have to comment the xpack settings.

client*** org.elasticsearch.client.RestHighLevelClient@797b0699 Connection refused

at org.elasticsearch.client.RestClient.extractAndWrapCause(

at org.elasticsearch.client.RestClient.performRequest(

at org.elasticsearch.client.RestClient.performRequest(

at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(

at org.elasticsearch.client.RestHighLevelClient.performRequest(

at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(



Caused by: Connection refused

at Method)


at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvent(

at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(

at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(

at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(

at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$


we have pkcs11 enable at apache tomcat level. is that an issue.

Hi Sunxi,

we are just creating HttpClient, can you please let me know why do we need SSL. The RestCLientBuilder's createHttpClient method calls SSLContext.getDefault, just wanted to check why we need SSL here. This is where my code is erroring out.

at org.elasticsearch.client.RestClientBuilder.createHttpClient(

maybe, I think something wrong in your configuration

Do I have to remove transport jar ; i am still keeping transport jar along with rest client. I will remove it eventually but this should not cause any issues right.
{elasticsearch.version}</version> <exclusions> <exclusion> <groupId>org.elasticsearch.plugin</groupId> <artifactId>transport-netty4-client</artifactId> </exclusion> <exclusion> <groupId>org.elasticsearch.plugin</groupId> <artifactId>transport-netty3-client</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-high-level-client</artifactId> <version>{elasticsearch.version}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.