spring-boot - 对 url 的 POST 请求的 I/O 错误:收到致命警报:handshake_failure Springboot resttemplate
问题描述
我正在尝试通过 SpringRestTemplate
在 Sprin-Boot 应用程序中连接安全 REST API。我收到以下错误:
I/O error on POST request for \"URL\": Received fatal alert: handshake_failure; nested exception is javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
RestTemplate
豆类配置:
public RestTemplate restTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException, UnrecoverableKeyException, CertificateException, FileNotFoundException, IOException {
char[] all = "mypassword".toCharArray();
KeyStore ks = KeyStore.getInstance("JKS");
try (InputStream stream = this.getClass().getClassLoader().getResourceAsStream("mycert.jks")) {
ks.load(stream, all);
IOUtils.closeQuietly(stream);
}
SSLContext sslContext = new SSLContextBuilder()
.loadKeyMaterial(ks, all).loadTrustMaterial(new TrustSelfSignedStrategy()).build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
clientBuilder.setSSLSocketFactory(csf);
CloseableHttpClient httpClient = clientBuilder.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
requestFactory.setBufferRequestBody(false);
return new RestTemplate(requestFactory);
}
应用程序(Pod)控制台日志:
--------> o.s.web.client.RestTemplate : HTTP POST https://URL--------> o.s.web.client.RestTemplate : Accept=[text/plain, application/json, application/*+json, */*]--------> o.s.web.client.RestTemplate : Writing [com.ril.model.json.request] as "application/json"--------> o.a.h.client.protocol.RequestAddCookies : CookieSpec selected: default--------> o.a.h.client.protocol.RequestAuthCache : Auth cache not set in the context--------> h.i.c.PoolingHttpClientConnectionManager : Connection request: [route: {s}->https://url:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]--------> h.i.c.PoolingHttpClientConnectionManager : Connection leased: [id: 0][route: {s}->https://URL:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]--------> o.a.http.impl.execchain.MainClientExec : Opening connection {s}->https://url:443--------> .i.c.DefaultHttpClientConnectionOperator : Connecting to url/10.21.252.51:443--------> o.a.h.c.ssl.SSLConnectionSocketFactory : Connecting socket to url/10.21.252.51:443 with timeout 0--------> o.a.h.c.ssl.SSLConnectionSocketFactory : Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]--------> o.a.h.c.ssl.SSLConnectionSocketFactory : Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]--------> o.a.h.c.ssl.SSLConnectionSocketFactory : Starting handshake--------> h.i.c.DefaultManagedHttpClientConnection : http-outgoing-0: Shutdown connection--------> o.a.http.impl.execchain.MainClientExec : Connection discarded--------> h.i.c.DefaultManagedHttpClientConnection : http-outgoing-0: Close connection--------> h.i.c.PoolingHttpClientConnectionManager : Connection released: [id: 0][route: {s}->https://URL:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]--------> BLActualizationUpdateResponseServiceImpl : Failed to get remote resource because: I/O error on POST request for "url": Received fatal alert: handshake_failure; nested exception is javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure-------->com.ril.aop.LogAop : Exception in ===: -------->com.ril.aop.LogAop : org.springframework.web.client.ResourceAccessException: I/O error on POST request for "url": Received fatal alert: handshake_failure; nested exception is javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
我尝试了很多方法来解决错误。
解决方案
推荐阅读
- c++ - Qt QMainWindow - Valgrind 报告内存泄漏
- php - Azure SQL MSI 与 PHP (PDO)
- python - 如何识别哪些 URL 指向重复内容?
- symfony - Doctrine 对 ENUM 类型的实体做出了不正确的差异
- javascript - Apollo GraphQL 合并缓存数据
- php - 登录测试完成后PHP单元测试设置JWT令牌
- angular - 如何使用 Ionic 生成 Angular 页面而不自动添加新路由
- r - summary.manova 输出显示来自 summary.manova 统计表和 broom tidy() 的不同 p 值
- python-3.x - 在 python 中对数据集的不同特征运行交叉验证时具有相同的准确性
- python - 在 Python 中使用 K-Medoids 聚类提取质心及其数据点?