# Couldn't instantiate rest high level client when the cluster is secured with searchguard and ssl is enabled for the http layer

**URL:** <https://discuss.elastic.co/t/couldnt-instantiate-rest-high-level-client-when-the-cluster-is-secured-with-searchguard-and-ssl-is-enabled-for-the-http-layer/105709>\
**Category:** Elasticsearch\
**Created:** [October 30, 2017, 4:45am UTC](https://discuss.elastic.co/t/couldnt-instantiate-rest-high-level-client-when-the-cluster-is-secured-with-searchguard-and-ssl-is-enabled-for-the-http-layer/105709 "2017-10-30T04:45:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kumar1993](https://avatars.discourse-cdn.com/v4/letter/k/8baadc/32.png) [@kumar1993](https://discuss.elastic.co/u/kumar1993)\
**Post date:** [October 30, 2017, 4:45am UTC](https://discuss.elastic.co/t/couldnt-instantiate-rest-high-level-client-when-the-cluster-is-secured-with-searchguard-and-ssl-is-enabled-for-the-http-layer/105709/1 "2017-10-30T04:45:38Z")

</div>

Hey, Guys i have a cluster which is running with elasticsearch 5.6.2, and it has searchguard plugin enabled, also SSL is enabled for both the transport layer as well as the http layer, when i execute the following curl command from the terminal  
curl -k -u user:password [https://localhost:9200](https://localhost:9200), the response is returned and its fine, but when i instantiate a high level rest client using the following code

```
    public RccRestClient()
    throws NodeValidationException, IOException, CertificateException, NoSuchAlgorithmException,
    KeyStoreException, KeyManagementException, UnrecoverableKeyException {
    SSLContextBuilder sslBuilder = SSLContexts.custom()
        //.loadTrustMaterial(new File("/Users/kumard/Desktop/elasticsearch-5.6.2/config/truststore.jks"),"password".toCharArray());
                .loadKeyMaterial(new File("/Users/kumard/Desktop/elasticsearch-5.6.2/config/0-keystore.jks"),"password".toCharArray(),"password".toCharArray());
    final SSLContext sslContext = sslBuilder.build();

    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY,
        new UsernamePasswordCredentials("user", "password"));

    Header[] defaultHeaders = new Header[] {
        new BasicHeader("Authorization", "Basic " + encodeBase64("user:password".getBytes())) };
    RestClientBuilder restClientBuilder = RestClient
        .builder(new HttpHost("localhost",
            Integer.valueOf("9200"), "https"))
        .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
            @Override
            public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
            }
        });
// .setHttpClientConfigCallback(
// new RestClientBuilder.HttpClientConfigCallback() {
// @Override

```

// public HttpAsyncClientBuilder customizeHttpClient(  
// HttpAsyncClientBuilder httpClientBuilder) {  
// httpClientBuilder.setDefaultHeaders(Arrays.asList(defaultHeaders));  
// httpClientBuilder.setSSLContext(sslContext);  
// return httpClientBuilder;  
// }  
// }  
//  
// );

```
    restClientBuilder.setMaxRetryTimeoutMillis(10000);
    restClientBuilder.setDefaultHeaders(defaultHeaders);
    restClientBuilder.setFailureListener(new RestClient.FailureListener() {
        @Override
        public void onFailure(HttpHost host) {
            LOGGER.error("Couldn't initialize Low Level Rest Client");
            System.exit(-1);
        }
    }); 

```

i am getting IO exception saying with timeouts, there is no error being logged. what is the correct way to achieve this.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 27, 2017, 4:53am UTC](https://discuss.elastic.co/t/couldnt-instantiate-rest-high-level-client-when-the-cluster-is-secured-with-searchguard-and-ssl-is-enabled-for-the-http-layer/105709/2 "2017-11-27T04:53:23Z")

</div>

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