This is a Java, SSL-based client which facilitates both RESTFul and SOAP web service calls to different servers. To better understand the topic at hand, you should also have knowledge of the below-mentioned topics:

What is an SSL certificate?

What is an SSL handshake?

What is a Java Key Store (JKS)?

What is a Java Trust Store (JTS)?

What is a PKCS certificate/key store?

What is HTTPS network protocol?

This is going to be a complete SSL-based client application for both RESTFul and SOAP calls. The beauty of this project is that it supports both JKS and PKCS certificates through different configuration facilities provided with this project. You can download the project and just need to refractor this framework/codebase and replace the existing Java classes with your classes to make this framework fulfill your business needs. You can download the project from here.

We are going to develop this small project in Eclipse. Let’s go over, step-by-step, how to create the client application.

1. Create a simple Java project, like below:

Give the project the name SSLClient, like below:

Click 'Finish' to create the project.

Now, right-click on source folder, src,and add a new package, com.bhaiti.kela.common.config, and add a new class, ApplicationConfig, to it.

First, add a new package: New->package

Now to add the class to it, click on the package and from the menu and select New->class.

Copy and paste the below code into this class. This is our config class where we will store all the config information for this application.

Now we are going to add a new class call SSLContextConfig this class will initialize the truststore, keystore and certificate detail to connect to the remove server through a SSL based HTTPS connection. Here based on trust store, key store and certificate detail the below class will create an object of type SSLContext and returns it to caller for establish an SSL based HTTPS connection. Beauty of this class is that I have design it in such a way that your can use both jks and pkcs certificate and that also can be configurable through system.properties file.

Now we need to add the two config files below to the root directory of this project. The first one is holding all the config information for this project (please read the certificate configuration part carefully) and the second file is a log property file. Please keep in mind that the below files are just sample files only, so do not blindly copy them to your project. Create the below two files in your project as per your config information.

LOG_PROPERTY_FILE_PATH=C:\\Projects\\SSLClient\\log.properties
KEYSTOREPATH=C:\\Projects\\SSLClient\\key\\etc\\mykestore.jks
TRUSTSTOREPATH=kelabhalkoikoribi
KEYSTOREPW=kelapitonpabi
TRUSTSTOREPW=kelabhalkoikoribi
KEYPASS=kelapitonpabi
keystoreType=jks
;assign above key as 'keystoreType=p12' if you are using a PKCS certificate/store
trustAllCertificate=yes
; assign 'no' if you don't want your application to force whether a site should be trusted or not, if you are getting a error like not a trusted site you can
;put the value as 'no' to avoid such issue. But not recomented.
keymanageralgorithm=SunX509 // For IBM it should be IbmX509