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( ...
随机推荐
- 差分约束详解&&洛谷SCOI2011糖果题解
差分约束系统: 如果一个系统由n个变量和m个约束条件组成,形成m个形如ai-aj≤k的不等式(i,j∈[1,n],k为常数),则称其为差分约束系统(system of difference const ...
- @Mapper和@Repository
参考地址 https://www.cnblogs.com/jtfr/p/10962205.html 相同点 两者都是作用于dao上 不同点 @Repository需要在Spring中配置扫描地址,然后 ...
- HNOI2004 树的计数 和 HNOI2008 明明的烦恼
树的计数 输入文件第一行是一个正整数n,表示树有n个结点.第二行有n个数,第i个数表示di,即树的第i个结点的度数.其中1<=n<=150,输入数据保证满足条件的树不超过10^17个. 明 ...
- Fetch(原生)的简单使用
前言: Fetch 提供了对 Request 和 Response 等对象通用的定义. 发送请求或者获取资源,需要使用 fetch() 方法. 具体使用代码: <script> fetch ...
- spark 三种数据集的关系(二)
一个Dataset是一个分布式的数据集,而且它是一个新的接口,这个新的接口是在Spark1.6版本里面才被添加进来的,所以要注意DataFrame是先出来的,然后在1.6版本才出现的Dataset,提 ...
- 特征工程之分箱--Best-KS分箱
变量的KS值 KS(Kolmogorov-Smirnov)用于模型风险区分能力进行评估,指标衡量的是好坏样本累计部分之间的差距 .KS值越大,表示该变量越能将正,负客户的区分程度越大.通常来说,KS& ...
- Java-DealString工具类
import java.text.NumberFormat; import java.util.Date; import java.util.Locale; import java.util.Stri ...
- @SpringQueryMap注解 feign的get传参方式(转)
spring cloud项目使用feign的时候都会发现一个问题,就是get方式无法解析对象参数.其实feign是支持对象传递的,但是得是Map形式,而且不能为空,与spring在机制上不兼容,因此无 ...
- (转载) Consul 使用手册(感觉比较全了)
使用consul 介绍 Consul包含多个组件,但是作为一个整体,为你的基础设施提供服务发现和服务配置的工具.他提供以下关键特性: 服务发现 Consul的客户端可用提供一个服务,比如 api 或者 ...
- 08 saltstack生产实例-apahce+php+redis
1.apache+php 前几章的LAMP:https://www.cnblogs.com/venicid/p/11276232.html#_label2 Php放在apache 1.目录结构 2.p ...