amazon-web-services - 与低级 Rest API 的 SSL/HTTPS 连接?

标签 amazon-web-services ssl elasticsearch spring-boot https

我正在使用低级 rest API 访问 AWS 中的 Elastic Search(AWS 服务)。 AWS 提供 HTTPS url。以下代码位于名为 com.example.configurations.EsConfig 的 SpringBoot 配置类中。

@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 -> requestConfigBuilder.setConnectTimeout(5000)
                    .setSocketTimeout(60000))
            .setMaxRetryTimeoutMillis(60000)
            .build();
    return restClient;
}

对于 esHost,我仅像本地主机一样提供 AWS Elasticsearch 端点 URL。

对于 esPort,在 HTTPS 的情况下为 443。

错误信息如下:

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

我无法通过 SSL 连接获取 RestClient。请建议我通过 SSL 连接获得 RestClient 需要什么。 谢谢

最佳答案

我在创建 HttpPost 对象作为第三个参数时解决了传递“https”的问题。

RestClient restClient = RestClient.builder(new HttpHost(esHost, esPort, "https"))
            .setHttpClientConfigCallback(httpClientBuilder -> {
                HttpAsyncClientBuilder httpAsyncClientBuilder = httpClientBuilder.setSSLContext(sslcontext);
                return httpAsyncClientBuilder;
            })
            .build();

现在它工作正常。

关于amazon-web-services - 与低级 Rest API 的 SSL/HTTPS 连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45380255/

相关文章:

java - AWS Lambda 中的 Spring Cloud 配置服务器

java - 为什么 java 在 cacert.org : "keyCertSign bit is not set"? 上制作的证书上阻塞

symfony - HWIOAuthBundle - SSL 证书

java - com.notnoop.exceptions.NetworkIOException : javax.net.ssl.SSLException:收到致命警报:internal_error

amazon-web-services - Terraform 为 Auto Scaling 组实例分配弹性 IP

node.js - AWS API Gateway OPTIONS 请求返回 500 错误

amazon-web-services - 如何删除具有 RDS 实例的 CloudFormation 堆栈?

java - 如何为spring data elasticsearch添加排序

Elasticsearch : singular and plural results

elasticsearch - ElasticSearch能否返回相关段落而不是整个文档