sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
httpclient-4.5.jar 定时发送http包,忽然有一天报错,http证书变更引起的。
之前的代码
try {
CloseableHttpClient httpClient = buildDefaultHttpClient();
String url = domain.getUrl();
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("User-Agent", NetUtil.INSPECTOR_USER_AGENT);
httpGet.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
httpGet.addHeader("Accept-Encoding", "gzip, deflate");
httpGet.addHeader("Accept-Language", "zh-CN,zh;q=0.9");
CloseableHttpResponse resp = httpClient.execute(httpGet);
String responseBody = EntityUtils.toString(resp.getEntity(), "utf-8");
respEnd = DateUtil.toEpochMilliseconds(LocalDateTime.now());
len = responseBody.length();
logger.info("http报文响应正文长度:{}B", len);
String extractedTitle = NetUtil.extractTitle(responseBody);
return builder.withRespEnd(respEnd).withRespLen(len)
.withHttpStatus((short) resp.getStatusLine().getStatusCode())
.withRetrieveTitle(extractedTitle)
.withTitleMatched(StringUtils.equals(domain.getTitle(), extractedTitle))
.build();
} catch (IOException e) {
}
之后的代码
try {
CloseableHttpClient httpClient = buildDefaultHttpClientTrustSSL();//信任证书
String url = domain.getUrl();
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("User-Agent", NetUtil.INSPECTOR_USER_AGENT);
httpGet.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
httpGet.addHeader("Accept-Encoding", "gzip, deflate");
httpGet.addHeader("Accept-Language", "zh-CN,zh;q=0.9");
CloseableHttpResponse resp = httpClient.execute(httpGet);
String responseBody = EntityUtils.toString(resp.getEntity(), "utf-8");
respEnd = DateUtil.toEpochMilliseconds(LocalDateTime.now());
len = responseBody.length();
logger.info("http报文响应正文长度:{}B", len);
String extractedTitle = NetUtil.extractTitle(responseBody);
return builder.withRespEnd(respEnd).withRespLen(len)
.withHttpStatus((short) resp.getStatusLine().getStatusCode())
.withRetrieveTitle(extractedTitle)
.withTitleMatched(StringUtils.equals(domain.getTitle(), extractedTitle))
.build();
} catch (IOException e) {
}
/**
* 信任SSL证书
* @return
*/
public static CloseableHttpClient buildDefaultHttpClientTrustSSL()
{
SSLContext sslContext = null;
try {
sslContext = SSLContextBuilder.create().useProtocol(SSLConnectionSocketFactory.SSL).loadTrustMaterial((x, y) -> true).build();
} catch (Exception e) {
e.printStackTrace();
}
RequestConfig config = RequestConfig.custom()
.setSocketTimeout(30000)
.setConnectTimeout(30000)
.setConnectionRequestTimeout(30000)
.setContentCompressionEnabled(true)
.build();
return HttpClientBuilder.create().setDefaultRequestConfig(config).setSSLContext(sslContext).setSSLHostnameVerifier((x, y) -> true).build();
} public static CloseableHttpClient buildDefaultHttpClient()
{
RequestConfig defaultRequestConfig = RequestConfig.custom()
.setSocketTimeout(30000)
.setConnectTimeout(30000)
.setConnectionRequestTimeout(30000)
.setContentCompressionEnabled(true)
.setStaleConnectionCheckEnabled(true)
.build(); return HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build();
}
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target的更多相关文章
- 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: ...
- mvn 编译报错mavn sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targ
mavn 编译报错: mavn sun.security.validator.ValidatorException: PKIX path building failed: sun.security.p ...
- 解决 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 ...
- 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 ...
- Flutter配置环境报错“PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target”
背景:最近看了很多Flutter漂亮的项目,想要尝试一下.所有环境都搭建好之后,按照文档一步一步配置(抄袭),但始终报如下图错误. PKIX path building failed: sun.sec ...
- ES访问遇到sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
cmd命令cd到jre/bin目录下 输入命令keytool -import -alias 别名 -keystore cacerts -file C://certs//elasticsearch// ...
- maven PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path
maven编译的时候遇到的奇葩问题, 非常奇葩, 所有其他同事都没有遇到 , 仅仅是我遇到了 不清楚是因为用了最新的JDK的缘故(1.8 update91)还是其他什么原因. 总之是证书的问题. 当 ...
- 报错PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"
今天在调用第三方HTTPS接口的时候,一直显示这个报错,然后百度很久,有2种解决方法,一个是说自己手动去导入,第二种用代码忽略证书验证.我用二种方式, 复制即用, public void test2( ...
随机推荐
- manjaro开机出现grub 解决办法
# 第一步:输入ls出现(hd0,msods1),(hd0,msdos5),(hd0,msods7)# 不同的电脑不一样,这是我电脑中的磁盘分区,和系统中的表示方法不一样,# linux中一般是/de ...
- [CEOI1999]Sightseeing trip(Floyed)
[CEOI1999]Sightseeing trip Description There is a travel agency in Adelton town on Zanzibar island. ...
- Winform的高DPI问题
现在的屏幕大部分都是高分屏,在这样的屏幕下开发winfrom软件就需要注意高DPI问题了 1.Form和UserControl的AutoScaleMode设置为Dpi 2.为项目添加应用程序清单文件( ...
- No valid Maven installation found. Either set the home directory in the configuration dialog or set
原因: IDEA的maven地址设置出错,系统找不到指定的maven路径 解决: setting---->maven修改正确的maven链接地址. 设置你maven 的地址为你的存放路基就好了
- java多线程批量下载文件
多线程下载文件 平时开发中有时会用到文件下载,为了提高文件的下载速率,采用多线程下载能够达到事半功倍的效果: package test; /** * 文件下载类 * @author luweichen ...
- Count the Buildings ( s1 )
http://acm.hdu.edu.cn/showproblem.php?pid=4372 题意:n个房子在一条线上(n<=2000),高度分别为1~n,现在需要将房子这样放置:从最左往右能看 ...
- TTTTTTTTTTTTTTTTTTT UVA 2045 Richness of words
J - Richness of words Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64 ...
- Comet OJ - Contest #3 D 可爱的菜菜子 线段树+线性基
题意 给你一个长度为 \(n\) 的整数序列 \(a_1, a_2, \ldots, a_n\),你需要实现以下两种操作,每个操作都可以用四个整数 \(opt\ l\ r\ v\) 来表示: \(op ...
- 2019 7.6 T2 虫洞
虫洞(conch) [题目描述] HZY 现在在数轴原点处,她想跑到 2000001 这个点上.听说各路 神犇暑假里都在健♂身,所有 HZY 也想不要只是简单地跑步,于是她 决定在这条数轴上造虫洞,具 ...
- [CSP-S模拟测试]:物理课(数学)
题目传送门(内部题144) 输入格式 从$physics.in$读入数据. 第一行一个数$T$,代表有$T$组数据.接下来$T$行每行$4$个浮点数,分别为$\theta,v,d,g$,保留到小数点后 ...