Skip to content

Instantly share code, notes, and snippets.

@yunqu
Created March 30, 2020 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yunqu/a324cfd436b7deef29788294e1e994be to your computer and use it in GitHub Desktop.
Save yunqu/a324cfd436b7deef29788294e1e994be to your computer and use it in GitHub Desktop.
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