I am getting below error even after disabling the TrustManager
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
Below is the code I am using to consumer web service.
public class HttpsDisable {
public static void disableCertificateValidation() {
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() { return null; }
public void checkClientTrusted(X509Certificate[] certs, String authType) { }
public void checkServerTrusted(X509Certificate[] certs, String authType) { }
}
};
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
//Now you can access an https URL without having the certificate in the truststore
try {
disableCertificateValidation();
URL url = new URL("https://162.19.122.114/service.asmx?wsdl");
System.out.println("url ================ "+url);
String sWebserviceurl = "https://172.17.134.214/service.asmx?wsdl";
String sXMLInput = "<KeedAn><PrAge>26</PrAge></KeedAn>";
AnalysisServiceService sl = new AnalysisServiceServiceLocator();
AnalysisService service = sl.getAnalysisService(new URL(sWebserviceurl));
String in = service.getNeedProdRes(sXMLInput);
System.out.println("web service output ----------\n" + in);
} catch (MalformedURLException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Can you please tell me where am I going wrong, since the above code is not working and throws above exception. And I have also save the .cert file in jre/lib/.cert path.
Try this code, It will disable and print response in console,
String send = "https://www.example.com";
URL url = new URL(send);
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager()
{
public java.security.cert.X509Certificate[] getAcceptedIssuers()
{
return null;
}
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
{
}
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
{
}
} };
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
IOUtils.copy(url.openStream(), System.out);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다