Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
URL test for java class
// Test for URL in java
//
// Usage:
// $ javac UrlConnect.java
// $ java UrlConnect
//
// If failed, need to check the cacerts store to make sure
// by default this is /etc/ssl/certs/java/cacerts
// Can change the URL in the file to test other sites
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
public class UrlConnect {
public static void main(String[] args) {
String[] defaultArgs = {"https://dl.google.com/go/go1.12.5.linux-armv6l.tar.gz"};
if (args.length == 0) {
args = defaultArgs;
}
for (String url : args) {
try (InputStream stream = new URL(url).openStream()) {
System.out.println("OK: " + url);
} catch (SSLHandshakeException ex) {
// This is bad
System.err.println("ERROR: " + url + ": " + ex.toString());
} catch (IOException ex) {
System.out.println("Warning: " + url + ": " + ex.toString());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment