2

This is my Code of simple java

package com.crunchify;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;

/**
 * @author Crunchify.com
 * 
 */

public class CrunchifyCallUrlAndGetResponse {

    public static void main(String[] args) {
        System.out.println("\nOutput: \n" + callURL("http://cdn3.crunchify.com/wp-content/uploads/code/json.sample.txt"));
    }

    public static String callURL(String myURL) {
        System.out.println("Requeted URL:" + myURL);
        StringBuilder sb = new StringBuilder();
        URLConnection urlConn = null;
        InputStreamReader in = null;
        try {
            URL url = new URL(myURL);
            urlConn = url.openConnection();
            if (urlConn != null)
                urlConn.setReadTimeout(60 * 1000);
            if (urlConn != null && urlConn.getInputStream() != null) {
                in = new InputStreamReader(urlConn.getInputStream(),
                        Charset.defaultCharset());
                BufferedReader bufferedReader = new BufferedReader(in);
                if (bufferedReader != null) {
                    int cp;
                    while ((cp = bufferedReader.read()) != -1) {
                        sb.append((char) cp);
                    }
                    bufferedReader.close();
                }
            }
        in.close();
        } catch (Exception e) {
            throw new RuntimeException("Exception while calling URL:"+ myURL, e);
        } 

        return sb.toString();
    }
}

Error while parsing

Exception in thread "main" java.lang.RuntimeException: Exception while calling URL:https://www.urbanpro.com
        at com.treselle.boilerpipe.demo.CrunchifyCallUrlAndGetResponse.callURL(CrunchifyCallUrlAndGetResponse.java:49)
        at com.treselle.boilerpipe.demo.CrunchifyCallUrlAndGetResponse.main(CrunchifyCallUrlAndGetResponse.java:20)
    Caused by: 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:174)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1611)
        at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:187)
        at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:181)
        at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1035)
        at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:124)
        at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:516)
        at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:454)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:884)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1112)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1139)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123)
        at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:418)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1041)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
        at com.treselle.boilerpipe.demo.CrunchifyCallUrlAndGetResponse.callURL(CrunchifyCallUrlAndGetResponse.java:35)
        ... 1 more
    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:285)
        at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:191)
        at sun.security.validator.Validator.validate(Validator.java:218)
        at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126)
        at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209)
        at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
        at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1014)
        ... 13 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:174)
        at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238)
        at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:280)
        ... 19 more

I want to parse url to html and then html to deta object model dom and then dom to json please provide me details thank you in advance

http://try.jsoup.org/~1YFy1bnDyRDBAVrnnlssXi73li4 enter link description here I want to parse url to html and then html to dom and then dom to jso but i get error like this please provide me datails thank you in advance

user207421
  • 305,947
  • 44
  • 307
  • 483
  • 1
    You are trying to connect "http://cdn3.crunchify.com/wp-content/uploads/code/json.sample.txt", why does "https://www.urbanpro.com" appear in the error stack. – Yiping Huang Jul 01 '15 at 07:10
  • I doubt that the code-example produced the stacktrace. Running your sample code returns the content properly – Roman Vottner Jul 01 '15 at 07:47
  • actually i want content from https://urbanpro.com url so that i can use this please provide @YipingHuang – Abhinay Pandey Jul 01 '15 at 08:01
  • Your client doesn't trust the server's SSL certificate. – user207421 Jul 01 '15 at 08:20
  • As @EJP already mentioned, the certificate used by urbanpro is not trusted by your JVM. You can trust the cert by adding it to your JVMs truststore. HTTPS URIs should automatically create a [HttpsURLConnection](http://docs.oracle.com/javase/7/docs/api/javax/net/ssl/HttpsURLConnection.html) instance to my knowledge. You could try to debug it using this [sample-code](http://www.mkyong.com/java/java-https-client-httpsurlconnection-example/) or setting the logging for the SSL/TLS to debug as explained [here](http://docs.oracle.com/javase/7/docs/technotes/guides/security/jsse/ReadDebug.html) – Roman Vottner Jul 01 '15 at 08:28
  • thanks to All i have solve my problem itself by using boilerpipe parser using http://boilerpipe-web.appspot.com/extract?url= thankyou – Abhinay Pandey Jul 01 '15 at 11:28

0 Answers0