Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certific
来源:互联网 发布:阿黛尔网络暴力 编辑:程序博客网 时间:2024/05/29 14:37
应用程序客户端访问https服务时报错。直接给出解决方案:
package http;
import java.net.MalformedURLException;
import java.net.URL;
public class HttpClientTest3 {
public static void main(String[] args) throws MalformedURLException {
AbstractCasProtocolUrlBasedTicketValidator validator = new AbstractCasProtocolUrlBasedTicketValidator();
String url = "https://localhost:8443/tms/service/domain/getDomains.action?domainID=1000_1456217771733";
URL hahaUrl = new URL(url);
String content = validator.retrieveResponseFromServer(hahaUrl, null);
System.out.println(content);
}
}
package http;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
/**
* Abstract class that knows the protocol for validating a CAS ticket.
*
* @author Scott Battaglia
* @version $Revision$ $Date$
* @since 3.1
*/
public class AbstractCasProtocolUrlBasedTicketValidator {
protected AbstractCasProtocolUrlBasedTicketValidator() {
}
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
System.out.println("Warning: URL Host: " + urlHostName + " vs. "
+ session.getPeerHost());
return true;
}
};
/**
* Retrieves the response from the server by opening a connection and merely
* reading the response.
*/
protected final String retrieveResponseFromServer(final URL validationUrl,
final String ticket) {
HttpURLConnection connection = null;
//System.out.println("============================================================");
try {
trustAllHttpsCertificates();
HttpsURLConnection.setDefaultHostnameVerifier(hv);
connection = (HttpURLConnection) validationUrl.openConnection();
final BufferedReader in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String line;
final StringBuffer stringBuffer = new StringBuffer(255);
synchronized (stringBuffer) {
while ((line = in.readLine()) != null) {
stringBuffer.append(line);
stringBuffer.append("\n");
}
return stringBuffer.toString();
}
} catch (final IOException e) {
return null;
} catch (final Exception e1){
return null;
}finally {
if (connection != null) {
connection.disconnect();
}
}
}
private static void trustAllHttpsCertificates() throws Exception {
javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
javax.net.ssl.TrustManager tm = new miTM();
trustAllCerts[0] = tm;
javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext
.getInstance("SSL");
sc.init(null, trustAllCerts, null);
javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc
.getSocketFactory());
}
static class miTM implements javax.net.ssl.TrustManager,
javax.net.ssl.X509TrustManager {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public boolean isServerTrusted(
java.security.cert.X509Certificate[] certs) {
return true;
}
public boolean isClientTrusted(
java.security.cert.X509Certificate[] certs) {
return true;
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType)
throws java.security.cert.CertificateException {
return;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType)
throws java.security.cert.CertificateException {
return;
}
}
}
- Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certific
- feign 调用报错sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certifica
- PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to fin
- PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to fin
- 解决 sun.security.provider.certpath.SunCertPathBuilderException
- PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException
- CAS SSO 错误返回PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:
- java掉用接口,报PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: u
- SunCertPathBuilderException: Unable To Find Valid Certification Path To Requested Target
- SunCertPathBuilderException: unable to find valid certification path to requested target
- Caused by: javax.security.auth.login.LoginException: unable to find LoginModule class: com.ibm.secur
- ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderExce
- (已解决)SunCertPathBuilderException: unable to find valid certification path to requested target
- HTTPS中SunCertPathBuilderException: unable to find valid certification path to requested target
- 【cas、tomcat】SunCertPathBuilderException: unable to find valid certification path to requested target
- sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath
- 解决 java 使用ssl过程中出现"PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderExcep
- Caused by: Unable to find interceptor class referenced by ref-name mydefault - interceptor-ref - fil
- hadoop datanode启动不起来
- Java 知识点列表
- 深入分析C++中声明与定义的区别
- 谈谈AOP应用层切面设计
- Java操作excel
- Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certific
- 一起看代码来玩玩QT之09 Signal and SLOT ( 信号和槽)
- MVP模式介绍:
- OkHttp Wiki 笔记
- android内部存储读写文件详解
- SpringMvc定时器自己的配置详细~~~
- fork之源码剖析
- behemoth - 06
- 模板类的继承