【发布时间】:2018-01-04 22:08:28
【问题描述】:
我正在使用低级别的 rest API 来访问 AWS(AWS 服务)中的 Elastic Search。 AWS 提供 HTTPS 网址。以下代码位于名为 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,例如 localhost。
对于 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 需要什么。 谢谢
【问题讨论】:
标签: amazon-web-services ssl elasticsearch spring-boot https