Created
March 30, 2020 05:56
-
-
Save yunqu/a324cfd436b7deef29788294e1e994be to your computer and use it in GitHub Desktop.
URL test for java class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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