title: SSL / HTTPS Connection with Low Level Rest API?
body: <p>I am using low level rest API to access Elastic Search in AWS (AWS Service). AWS provides the HTTPS url. The following code is inside SpringBoot configuration class named <code>com.example.configurations.EsConfig</code>.  </p>
  
  <pre><code>@Bean
  public RestClient restClient() throws Exception {
      RestClient restClient = RestClient.builder(new HttpHost(esHost, esPort))
              .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;
                  }
              })
              .setRequestConfigCallback(requestConfigBuilder -&gt; requestConfigBuilder.setConnectTimeout(5000)
                      .setSocketTimeout(60000))
              .setMaxRetryTimeoutMillis(60000)
              .build();
      return restClient;
  }
  </code></pre>
  
  <p>For esHost I am providing the AWS Elasticsearch endpoint URL only like localhost.</p>
  
  <p>For esPort its 443 in case of HTTPS.</p>
  
  <p>Following are the error messages:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I am not able to get RestClient over SSL connection. Please suggest me what is needed to get a RestClient over SSL connection.
  Thanks</p>