1

I am trying to parse some url's with Jsoup but I get this error:

javax.net.ssl.SSLException: Received fatal alert: protocol_version
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:512)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:493)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:205)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:194)

here is my code:

public Elements getLinks(String link){
    Document doc = null;
    try {
        doc = Jsoup.connect(link)
                 .userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
                 .referrer("http://www.google.com") 
                 .timeout(5000) //it's in milliseconds, so this means 5 seconds.              
                 .get();
    }  
    catch (SSLException e) {

        e.printStackTrace();
    }
    catch (IOException e) {
        if(e.getCause() instanceof SocketTimeoutException) {
            try {
                throw new SocketTimeoutException();
            } catch (SocketTimeoutException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
   }
        e.printStackTrace();
    }

    Elements links = doc.select("a[href]");

    return links;
}

I have a catch section for the SSLException but my program stops. I don't care to parse the specific url, I just want my program not to crash. Any ideas how to fix this problem?

yasuo
  • 37
  • 6
  • 2
    Well, you have the stacktrace so your catch worked and did what you wanted it to do (to print the stacktrace). As for the exception itself, there's a [question](http://stackoverflow.com/questions/16541627/javax-net-ssl-sslexception-received-fatal-alert-protocol-version) addressing what the error is saying about your code – Alfabravo Dec 15 '15 at 20:03

1 Answers1

2

As the exception is beeing thrown during the initialization of

Document doc;

this line

Elements links = doc.select("a[href]");

will probably throw some other exception that you are not catching, or the returned value will not be correctly initialized

snovelli
  • 5,804
  • 2
  • 37
  • 50