# SSL / HTTPS Connection with Low Level Rest API?

**URL:** <https://discuss.elastic.co/t/ssl-https-connection-with-low-level-rest-api/94999>\
**Category:** Elasticsearch\
**Created:** [July 28, 2017, 6:28pm UTC](https://discuss.elastic.co/t/ssl-https-connection-with-low-level-rest-api/94999 "2017-07-28T18:28:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![khatkarrohit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/khatkarrohit/32/20293_2.png) [@khatkarrohit](https://discuss.elastic.co/u/khatkarrohit)\
**Post date:** [July 28, 2017, 6:28pm UTC](https://discuss.elastic.co/t/ssl-https-connection-with-low-level-rest-api/94999/1 "2017-07-28T18:28:35Z")

</div>

I am using low level rest API to access Elastic Search in AWS (AWS Service). Aws provides the HTTPS url.

```
    @Bean
    public RestClient restClient() throws Exception {
        RestClient restClient = RestClient.builder(new HttpHost(esHost, esPort))
                .setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(5000)
                        .setSocketTimeout(60000))
                .setMaxRetryTimeoutMillis(60000)
                .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
                    @Override
                    public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                        HttpAsyncClientBuilder httpAsyncClientBuilder = null;
                        try {
                            httpAsyncClientBuilder = httpClientBuilder.setSSLContext(SSLContext.getDefault());
                        } catch (NoSuchAlgorithmException e) {
                            e.printStackTrace();
                        }
                        return httpAsyncClientBuilder;
                    }
                })
                .build();
        return restClient;
    }

```

I am not able to get RestClient over SSL connection.

Following are the error messages:

> 2017-07-31 09:22:43.001 INFO 6239 --- [/O dispatcher 1] com.example.configurations.EsConfig : java.io.IOException: Connection reset by peer  
> 2017-07-31 09:22:43.018 INFO 6239 --- [/O dispatcher 2] com.example.configurations.EsConfig : java.io.IOException: Connection reset by peer  
> 2017-07-31 09:22:43.037 INFO 6239 --- [/O dispatcher 3] com.example.configurations.EsConfig : org.apache.http.ConnectionClosedException: Connection closed  
> 2017-07-31 09:22:43.043 INFO 6239 --- [/O dispatcher 4] com.example.configurations.EsConfig : java.io.IOException: Connection reset by peer  
> 2017-07-31 09:22:43.075 INFO 6239 --- [/O dispatcher 6] com.example.configurations.EsConfig : java.io.IOException: Connection reset by peer  
> 2017-07-31 09:22:43.075 INFO 6239 --- [/O dispatcher 5] com.example.configurations.EsConfig : java.io.IOException: Connection reset by peer  
> 2017-07-31 09:22:43.075 INFO 6239 --- [/O dispatcher 7] com.example.configurations.EsConfig : java.io.IOException: Connection reset by peer  
> 2017-07-31 09:22:43.077 INFO 6239 --- [/O dispatcher 8] com.example.configurations.EsConfig : org.apache.http.ConnectionClosedException: Connection closed  
> 2017-07-31 09:22:43.099 INFO 6239 --- [/O dispatcher 2] com.example.configurations.EsConfig : java.io.IOException: Connection reset by peer

Please suggest me what is needed to get a RestClient over SSL connection.  
Thanks

---

<div class="post-metadata">

**Author:** ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)\
**Post date:** [August 4, 2017, 6:09am UTC](https://discuss.elastic.co/t/ssl-https-connection-with-low-level-rest-api/94999/2 "2017-08-04T06:09:16Z")

</div>

> [@khatkarrohit](#):
>
> `new HttpHost(esHost, esPort)`

Try passing `"https"` as a third argument to the constructor.

---

<div class="post-metadata">

**Author:** ![khatkarrohit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/khatkarrohit/32/20293_2.png) [@khatkarrohit](https://discuss.elastic.co/u/khatkarrohit)\
**Post date:** [August 4, 2017, 5:56pm UTC](https://discuss.elastic.co/t/ssl-https-connection-with-low-level-rest-api/94999/3 "2017-08-04T17:56:28Z")

</div>

@TimV Thank you so much. It really worked. Now I don't have to use JEST or other api's.

---

<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:** [September 1, 2017, 5:56pm UTC](https://discuss.elastic.co/t/ssl-https-connection-with-low-level-rest-api/94999/4 "2017-09-01T17:56:53Z")

</div>

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