SSL Connection test using Java

If you want to test if an SSL connection works, the following simple class can do the job.


package com.ardevco.security;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class TestSSL {

public static void main(String[] args) {

if (args.length != 1) {
Runtime.getRuntime().exit(01);
}
System.out.println("Connecting to " + args[0] + "...");
try {
URL url = new URL(args[0]);
URLConnection connection = url.openConnection();
connection.connect();
InputStream inputStream = connection.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
String curline;
while ((curline = in.readLine()) != null) {
System.out.println(curline);
}
inputStream.close();
}
catch (Throwable t) {
t.printStackTrace();
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s