Using SSL(Secure Socket Layer) in JAX-WS webservice


In this tutorial I will show how to use SSL/TSL or https in JAX-WS based SOAP webservice. For using SSL with JAX-WS webservice you need one keystore file. I will use here Java tool to generate the keystore file. I also need to configure SSL in Tomcat server because I am going to deploy our application into Tomcat server.


Please have a look at deploy jax-ws webservice into tomcat server before reading this tutorial.

Java at least 8, Gradle 6.5.1, JAX-WS API, Tomcat 9.0.24

Generating Keystore File

First generate the keystore file using the below command from the command prompt. C:\keystore the target location where the keystore file will be generated.

The file name is keystore.jks. You can also give a file name with .keystore.

C:\Java\jdk-12.0.2\bin\keytool -genkey -alias tomcat -keyalg RSA -keystore C:\keystore\keystore.jks

Make sure to change the JDK path in the above command with your system’s JDK path. Also if you want to change the keystore file location then you can change accordingly.

Next after executing the above command in the command line tool you will be prompted for below options. So enter the values as required.

Using SSL(Secure Socket Layer) in JAX-WS webservice

Text version of the above image:

Enter keystore password:
Re-enter new password:
What is your first and last name?
What is the name of your organizational unit?
  [Unknown]:  development
What is the name of your organization?
What is the name of your City or Locality?
  [Unknown]:  Earth
What is the name of your State or Province?
  [Unknown]:  Earth
What is the two-letter country code for this unit?
  [Unknown]:  IN
Is, OU=development,, L=Earth, ST=Earth, C=IN correct?
  [no]: yes

You may also like to read the similar example on:

SOAP over https with client certificate authentication

Configuring Tomcat to use SSL

Open <tomcat home directory>\conf\server.xml file and search for <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" .../>

If the above line is not commented out then comment the above line and add a new entry as shown below:

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />

For more information on SSL configuration you can have a look at the URL

Now start the Tomcat Server and verify whether SSL connection gets established using https://localhost:8443/ in the browser.

Accessing WSDL

Deploy the application into Tomcat server and try to access the WSDL file using SSL URL https://localhost:8443/jax-ws-webservice-tomcat/hello?wsdl from the browser.

You will get below output on the browser:

<definitions xmlns:wsu="" xmlns:wsp="" xmlns:wsp1_2="" xmlns:wsam="" xmlns:soap="" xmlns:tns="" xmlns:xsd="" xmlns="" targetNamespace="" name="HelloImplService">
<import namespace="" location="https://localhost:8443/jax-ws-webservice-tomcat/hello?wsdl=1"/>
	<binding xmlns:ns1="" name="HelloImplPortBinding" type="ns1:Hello">
		<soap:binding transport="" style="rpc"/>
		<operation name="sayHello">
			<soap:operation soapAction=""/>
				<soap:body use="literal" namespace=""/>
				<soap:body use="literal" namespace=""/>
	<service name="HelloImplService">
		<port name="HelloImplPort" binding="tns:HelloImplPortBinding">
			<soap:address location="https://localhost:8443/jax-ws-webservice-tomcat/hello"/>

Testing the Service

Create a class with main method as shown below to test the JAX-WS based SOAP service for SSL.

import javax.xml.namespace.QName;
public class HelloSSLClient {
	public static void main(String[] args) throws Exception {
		URL url = new URL("https://localhost:8443/jax-ws-webservice-tomcat/hello?wsdl");
		QName qname = new QName("", "HelloImplService");
		Service service = Service.create(url, qname);
		Hello hello = service.getPort(Hello.class);

Executing the above class you will get below exceptions in localhost.

So click on the below exception links to resolve the issues.

Thanks for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *