Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ValidatorException: PKIX path building failed: unable to find certificate

tahirakramDec 12 2008 — edited Sep 11 2009
Hello;

I am getting an following exception while hitting on a HTTPS URL. The strange thing is some times this exception comes and some time it works just fine.

ValidatorException: PKIX path building failed: unable to find valid certification path to requested target

I am unable to understand why it is happening.
What thing on my end need to be managed for HTTPS communication to avoid this exception?

I am sharing my code with you people, if you can give me any idea about it.

Exception trace:
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 
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:150) 
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1476) 
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:174) 
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:168) 
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:847) 
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:106) 
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495) 
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433) 
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:815) 
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1025) 
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1038) 
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:402) 
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:170) 
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:836) 
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230) 
at com.paymentservice.impl.ecash.CommunicationHandler.communicateForTransReports(CommunicationHandler.java:165) 
at java.lang.Thread.run(Thread.java:595) 
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:221) at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:145) at sun.security.validator.Validator.validate(Validator.java:203) at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:172) at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(SSLContextImpl.java:320) at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:840) ... 18 more 
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:236) 
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:194)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:216) ... 23 more 
Code:
public  String communicateForTransReports (String data)
		throws Exception{
		HttpURLConnection httpCon = null;
		OutputStreamWriter wr = null;
		StringBuffer respBuff = null;
		try{
			URL url = new URL("https://secure.electracash.net/ElectracashDirect/getCIE.aspx");

			httpCon = (HttpURLConnection)url.openConnection();

			httpCon.setRequestMethod("POST");
			httpCon.setDoOutput(true);
			httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			httpCon.setRequestProperty("Content-Length", String.valueOf(data));

			wr = new OutputStreamWriter(httpCon.getOutputStream());
			wr.write(data);
			wr.flush();
			wr.close();

			InputStreamReader isr = new InputStreamReader(httpCon.getInputStream());

			BufferedReader rd = new BufferedReader(isr);
			String line;
			respBuff = new StringBuffer();

			while ((line = rd.readLine()) != null) {
				respBuff.append(line);
			}
			System.out.println(respBuff.toString());
		}catch(Exception e){
		}
		return respBuff.toString();
	}
--
Thanks,
Tahir
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 9 2009
Added on Dec 12 2008
10 comments
692 views