Redirect from HTTP to HTTPS on Glassfish

Introduction
This tutorial is intended to show you how you can force various url patterns to use HTTPS if a user tries to use HTTP.

Build

  • Glassfish 4.1
  • Netbeans 8.1 (Not necessary, will have instruction for both)
  • JavaEE 7 (Don’t think its necessary)

Instructions
Navigate to your Web Application Archive’s (WAR’s) web.xml file.

Method 1: Netbeans

NB Step 1

NB Step 2

Method 2: Good ol’ Copy n’ Paste

The above steps would have created the following code which you would add into your file. I apologize it would not save the spaces.

<web-app>

<security-constraint>
<display-name>Constraint1</display-name>
<web-resource-collection>
<web-resource-name>Anything</web-resource-name>
<description>This will make the constraint affect all pages of the application</description>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<description/>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

</web-app>

References

Set context-root of Application running on Glassfish as the Domain Base

Introduction

Whether you want to set your ear, war or whatever type of application up on Glassfish, we typically want to get rid of the default landing page and replace it with one of the apps. This guide will show you how, with one image. This method is the easiest but has a caveat which I will mention later. It should work in Glassfish 3 and beyond, at the least.

Build

  • Glassfish 4.1
  • Using an Enterprise Application Archive (EAR)

Assumptions

  • Name of configuration and virtual server are default

Instructions

  1. Deploy your application
  2. Navigate to Configurations > server-config > Virtual Servers > server
  3. Select desired application on Default Web Module
  4. Save

Instruction Image

Caveat
If you specified in the configurations of your file a different context root (file depends on what type of application) then you will be able to access the application from the Domain Base as well as the context root defined in the application’s configuration file.