Good evening together. My problem is that if I open an url and fetch the content it ALWAYS fails on the second loop run (yes the urls are all correct). SDK: 11.0.1
public String getUrlContent(String url) {
System.out.println("URL: " + url);
for (int i = 0; i < 100; i++) {
try (Scanner scanner = new Scanner(new URL(url).openStream(),
StandardCharsets.UTF_8.toString())) {
scanner.useDelimiter("\\A");
String returnString = scanner.hasNext() ? scanner.next() : "";
scanner.close();
return returnString;
} catch (Exception e) {
e.printStackTrace();
System.out.println("###############################################");
System.out.println("#Connection failed..#");
System.out.println("#Trying again... #");
System.out.println(e);
System.out.println("###############################################");
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
System.out.println("Connection failed to often. Program closed.");
System.exit(0);
return null;
}
What did I try? when i call the function in a test file, the error does not occur. however, the function contains the same code. do you have any ideas? As I said, it always aborts at the second url. the code around the function should have no impact, because only the results are stored in an array, which I can get from the object.
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.ssl.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.java:185)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1581)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1509)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:245)
at java.base/java.net.URL.openStream(URL.java:1117)
at helper.webHelper.getUrlContent(webHelper.java:42)
at urlParser.parser.checkLastUpdate(parser.java:41)
at main.main(main.java:29)