resttemplate 调用https 出错 unable to find valid certification path to requested target
resttemplate 调用https使用下面代码:
@Bean
@Primary
public RestTemplate restTemplate(ClientHttpRequestFactory httpRequestFactory) {
return new RestTemplate(httpRequestFactory);
}
@Bean
public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
//单位为ms
factory.setReadTimeout(10 * 1000);
//单位为ms
factory.setConnectTimeout(30 * 1000);
return factory;
}
调用没有证书的https出现的错误
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://gateway.fat.demo.com/service-commodity/providerInventory/queryInventory": sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
修改为下面的java代码后,一切OK:
@Primary
@Bean
public RestTemplate restTemplate() {
return new RestTemplate(generateHttpsRequestFactory());
}
public HttpComponentsClientHttpRequestFactory generateHttpsRequestFactory() {
try {
TrustStrategy acceptingTrustStrategy = (x509Certificates, authType) -> true;
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
SSLConnectionSocketFactory connectionSocketFactory =
new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
HttpClientBuilder httpClientBuilder = HttpClients.custom();
httpClientBuilder.setSSLSocketFactory(connectionSocketFactory);
CloseableHttpClient httpClient = httpClientBuilder.build();
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
factory.setHttpClient(httpClient);
factory.setConnectTimeout(10 * 1000);
factory.setReadTimeout(30 * 1000);
return factory;
} catch (Exception e) {
log.error("创建HttpsRestTemplate失败", e);
throw new RuntimeException("创建HttpsRestTemplate失败", e);
}
}
resttemplate 调用https 出错 unable to find valid certification path to requested target的更多相关文章
- https编程遇到PKIX:unable to find valid certification path to requested target 的问题
https编程遇到PKIX:unable to find valid certification path to requested target 的问题 2016-12-01 解决方案见:解决PKI ...
- java程序中访问https时,报 PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
在java中使用https访问数据时报异常: Caused by: sun.security.validator.ValidatorException: PKIX path building fail ...
- PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
注:网上搜来的快照,暂未验证 在java代码中请求https链接的时候,可能会报下面这个错误javax.net.ssl.SSLHandshakeException: sun.security.vali ...
- 解决 java 使用ssl过程中出现"PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"
今天,封装HttpClient使用ssl时报一下错误: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorExc ...
- 解决PKIX(PKIX path building failed) 问题 unable to find valid certification path to requested target
最近在写java的一个服务,需要给远程服务器发送post请求,认证方式为Basic Authentication,在请求过程中出现了 PKIX path building failed: sun.se ...
- 解决flutter:unable to find valid certification path to requested target 的问题
1.问题 周末在家想搞搞flutter,家里电脑是windows的,按照官网教程一步步安装好以后,创建flutter工程,点击运行,一片红色弹出来,WTF? PKIX path building fa ...
- 工作日志,证书无效 unable to find valid certification path to requested target
工作日志,证书无效 unable to find valid certification path to requested target 最近被这个问题弄得头大.导致所有用到 se.transmod ...
- IDEA unable to find valid certification path to requested target
一.报错 Could not transfer artifact org.apache.maven.plugins:maven-install-plugin:pom:2.4 from/to alima ...
- Maven:sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
还是记录使用 maven 时遇到的问题. 一.maven报错 maven package 进行打包时出现了以下报错: Non-resolvable parent POM for com.wpbxin: ...
- Android Studio出现:Cause: unable to find valid certification path to requested target问题解决
Android Studio , Flutter , IDEA 工程报错 unable to find valid certification path to requested target 最新解 ...
随机推荐
- wpf之样式
在Window.Resources中书写样式 : <Window.Resources> <Style TargetType="Button" > </ ...
- ABP VNext 系列:框架启动流程以及依赖注入原理和源码分析
简单介绍 ABP VNext Github 地址:https://github.com/abpframework/abp 官网文档地址:https://abp.io/docs/latest 官网:ht ...
- Notepad--特色功能:拷贝另存为
Notepad--特色功能:拷贝另存为 你是否纠结如下的使用场景: 正在编辑的文件,还没有想好,保存担心把原文件给覆盖了. 使用"另存为"后当前编辑界面的文档又变成新的文件了,可是 ...
- C#通过JS变量提取天天基金API返回的基金净值
目录 天天基金API 添加项目依赖项 请求 API 数据 获取所有基金代码 获取基金净值信息 功能测试 参考链接 天天基金API 常见的 API 如下: 所有基金代码:http://fund.east ...
- KubeSphere 社区双周报 | 2023.12.21-2024.01.04
KubeSphere 社区双周报主要整理展示新增的贡献者名单和证书.新增的讲师证书以及两周内提交过 commit 的贡献者,并对近期重要的 PR 进行解析,同时还包含了线上/线下活动和布道推广等一系列 ...
- Vue 中 v-html 无法被 style scoped 渲染的问题
假设有这么一个 vue 组件: <template> <div v-html="docPreview"/> </template> <st ...
- 别再忽视!PostgreSQL Public 模式的风险以及安全迁移
别再忽视!PostgreSQL Public 模式的风险以及安全迁移 作者:桦仔 10余年DBA工作经验 微信:debolop QQ交流群:740052625 公众号:数据库实战派 问题起因 前几天 ...
- github/gitee个人博客到底是什么一个运行原理?
本文主要讲的是GitHub.Gitee这样的代码存储网站上提供的个人博客建站的原理分析,需要注意的是,本文并不介绍GitHub.Gitee上建立个人blog的操作步骤,本文只介绍原理,不介绍实操步骤. ...
- Redis示例配置文件
# 注意单位问题:当需要设置内存大小的时候,可以使用类似1k.5GB.4M这样的常见格式: # # 1k => 1000 bytes # 1m => # 1kb => 1024 by ...
- 鸿蒙NEXT开发案例:光强仪
[引言] 本文将介绍如何使用鸿蒙NEXT框架开发一个简单的光强仪应用,该应用能够实时监测环境光强度,并给出相应的场景描述和活动建议. [环境准备] 电脑系统:windows 10 开发工具:DevEc ...