Simple Java Program to Verify SSL Certificate

I was recently install some certificates into my local store and wanted to verify that they were working correctly. I put together a simple Java program that verifies the target sites can be loaded.


/**
* SSL Test -- tests that JVM is configured correctly to load an SSL certificate
*/
package com.meesqa.sample;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;

public class SSLTest
{

public static final String test1URL = "https://www.google.com/";
public static final String test2URL = "https://login.live.com/";

public static void testURL( String url )
{
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod( url );

try
{
client.executeMethod( method );

if( method.getStatusCode() == HttpStatus.SC_OK )
{
System.out.println( url + " access OK." );
}
else
{
System.out.println( url + " access FAILED." );
}
}
catch( Exception e )
{
System.out.println( url + " access FAILED with an exception: " + e.getMessage() );
}
}

public static void main( String[] args )
{
SSLTest.testURL( test1URL );
SSLTest.testURL( test2URL );
}

}

Running the program tests the 2 urls specified:

java com.meesqa.sample.SSLTest
https://www.google.com/ access OK.
https://login.live.com/ access OK.

 

August 2014 mensming Twitter Posts

Follow mensming on Twitter

Aug 29
Posted to testingpodcast.com – Raj Subramanian on Testing Mobile Apps – http://testingpodcast.com/raj-subramanian-on-testing-mobile-apps/

Aug 27
Predicting Website Hacks Before They Happen – http://www.dailydot.com/tech\
nology/website-hack-prediction-big-data-carnegie-mellon/

Aug 26
Doing some accessibility work on one of our sites — The following site is useful when dealing with color contrasts – http\
://www.dasplankton.de/ContrastA/

Aug 11
Finished reading App Quality: Secrets for Agile App Teams by Jason Arbon – http://amzn.to/1nIPO7y