Configure Java web-app to use Https

Steps:

>Create a sample web-app
> It’s all in web.xml

Create a sample web-app using maven, give the following command

mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-webapp -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false -DgroupId=com.test -DartifactId=simple-webapp -Dpackage=com.test -DarchetypeVersion=2.23.2

above command will create a simple jersey web project “simple-webapp”,
edit the web.xml under the WEB-INF directory, add the following lines just above </web-app> tag

<security-constraint>
    <web-resource-collection>
        <web-resource-name>jersey</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>
Here <web-resource-name>jersey</web-resource-name> is the application context

navigate to simple-webapp directory and build the project using

mvn clean install -Dskiptests

deploy the the a war generated under target on tomcat

check if the browser accepts using

https://localhost:8443/jersey/webapi/myresource

Download the example from here

Add exception when your browser prompts, That’s it!
But above all you are required to configure your tomcat server.xml to accept https protocol, refer to this post

Advertisements
Configure Java web-app to use Https

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