gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:22:32 27 4
gpt4 key购买 nike

我正在使用低级 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com