简体   繁体   中英

Why do I get a handshake_failure error when I try to get more than 1 Document in my class using Jsoup?

It seems as if I can only create one get request with Jsoup per class because, when I swap out CITYPARKSURL for CITYPARKSURL2 , the one that I put in getParkNames() compiles and the other gives the error.

I had this code running in IntelliJ but, when I moved it into Eclipse, it started giving me these handshake errors. Does anyone know why this is? (I have to do my project in Eclipse unfortunately.)

Here is my code and the error:

public class DublinCityParksParse{

private final String CITYPARKSURL = "https://www.dublincity.ie/residential/parks/dublin-city-parks/visit-park";
private final String CITYPARKSURL1 = "https://www.dublincity.ie/residential/parks/dublin-city-parks/visit-park?page=1";
private final String CITYPARKSURL2 = "https://www.dublincity.ie/residential/parks/dublin-city-parks/visit-park?page=2";
private final String CITYPARKSURL3 = "https://www.dublincity.ie/residential/parks/dublin-city-parks/visit-park?page=3";

private String[] parkNamesHyphs = {"/eamonn-ceannt-park", "/balcurris"};

private List<String> parkNames = new ArrayList<String>();

private ArrayList<String> parkNamesHyphen = new ArrayList<String>();

private List<Park> parks = new ArrayList<Park>();

public DublinCityParksParse() {
    getParkNames();
    getParkNames1();
}
    
public void getParkNames() {        
    try {       
        Document docGetDetails = Jsoup.connect(CITYPARKSURL).get();
                
        Elements elsClass = docGetDetails.getElementsByClass("search-result__title");

        for(Element els : elsClass) {               
            parkNames.add(els.text());
        }
        
     // System.out.println(docGetDetails.toString());
        System.out.println(parkNames.toString());

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();        
    }
}

public void getParkNames1() {

    try {       
        Document docGetDetails1 = Jsoup.connect(CITYPARKSURL1).get();
                
        Elements elsClass1 = docGetDetails1.getElementsByClass("search-result__title");

        for(Element els : elsClass1) {              
            parkNames.add(els.text());
        }
        
        System.out.println(docGetDetails1.toString());
        System.out.println(parkNames.toString());

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    
    }
}

    
public static void main(String[]args) {     
    new DublinCityParksParse();
}} 

Error:

javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:128) at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:308) at java.base/sun.security.ssl.Alert$AlertConsumer.consume(Alert.java:279) at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:181) at java.base/sun.security.ZF 9D5C16A7F42203F8C195432354A3271Z.SSLTransport.decode(SSLTransport.java:164) at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1152) at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1063) at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:402) at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:567) at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.Z93F725A07423FE1C889 F448B33D21F46Z:185) at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:163) at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:732) at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:707) at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:297) at org.jsoup.helper.HttpConnection.get(HttpConnection.java:286) at DublinCityParksParse.getParkNames1(DublinCityParksParse.java:68) at DublinCityParksParse.(DublinCityParksParse.java:30) at DublinCityParksParse.main(DublinCityParksParse.java:182)

My bet is that you are running different Java versions between IntelliJ and Eclipse, and the Eclipse version is old (like 1.7 or an old 1.8). And that's why it worked in the first IDE and not the second.

You should update your JDK to a currently supported version . Those old versions of Java have troubles with current TLS / SSL websites. They re missing many cipher suites, SNI support, TLS 1.3 support, etc. You can patch all that in for old versions, but I can't imagine that's something you want to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM