Mario Mohr

Consultant, Developer, IT Enthusiast

Environment specific web.xml settings in JBoss 7

April 27, 2013

In our build process we try to keep the resulting artifacts (e.g. ear or war files) environment independent so that we can easily deploy the same artifact in different environments.
One problem I stumbled across recently, was the need to configure our web application to set the secure flag on the session cookie. This is done in the packaged web.xml.
This post will show an alternative solution for this problem by using the jboss specific jboss-web.xml and system properties.

In earlier JBoss versions the secure cookie flag could be configured on the server level by editing server/<CONFIG>/deploy/jbossweb.sar/context.xml and adding the following line:

conext.xml

1

<SessionCookie secure="true" httpOnly="true" />

In JBoss 7 there is no server specific configuration for this any more.
You have to edit the web.xml file of your web application to contain something like the following:

As the web.xml is packaged into the artifact during the build process, this setting is effective in every environment the application is deployed to. On our local machines, we do not want to set up certificates and https configuration for the development JBoss. But this setting prevents us from logging in without https because the session cookie was configured to only work via https.
Therefore, we needed a solution to make this web.xml setting environment specific without changing the artifact for different environments.

JBoss 7.1 allows property replacements in deployment descriptors like ejb-jar.xml but not in the web.xml.
There is a jboss specific jboss-web.xml which can be used to configure some JBoss specific settings.
Apart from JBoss specific settings, this file also supports everything you could write in the normal web.xml.
And, most importantly, jboss-web.xml supports property replacement. Therefore, you can use the following jboss-web.xml:

Mario Mohr

In a lot of network setups users are forced to use some kind of gateway server or bastion host to connect to their target server via SSH.
Being able to connect to the target server with one click via putty saved me a lot of time.

In our build process we try to keep the resulting artifacts (e.g. ear or war files) environment independent so that we can easily deploy the same artifact in different environments. One problem I stumbled across recently, was the need to configure our web application to set the secure flag on the session cookie. This is done in the packaged web.xml. This post will show an alternative solution for this problem by using the jboss specific jboss-web.