2

I'm using the following:

  • Spring 3.1
  • Java EE 6 (GlassFish 3.1.2)
  • Maven for project builds, etc
  • Ant for live deployment

We have a bunch of environments at work: DEV, UAT, TRAINING, PROD, etc. In our TRAINING environment a request has been made for me to up the session timeout to 8 hours. It is 2 hours in all other environments. What I'd love to do is simply use a property placeholder in web.xml. But I don't think this is possible:

<session-config>
    <session-timeout>${session.timeout}</session-timeout>
</session-config>

The solutions I have thought of are:

  1. Use Maven filtering - I really do not wish to do this. It would mean a separate war for training.
  2. Remove the session timeout from web.xml and configure GlassFish in TRAINING to timeout after 8 hours - I don't like this too much, as I'd prefer to keep all our environments pure and in sync.
  3. Set this manually in some initialisation code. Yuck.

I should mention that we use <env>.properties files to configure the web-app. The properties file is selected using a VM argument.

Can anyone think of another, nicer solution?

Thanks in advance, Muel.

Muel
  • 4,309
  • 1
  • 23
  • 32

2 Answers2

0

If you can set it in some initialisation code then you'd be able to fetch it from spring. The web.xml is the first thing that is read so no pre-processing is possible on it.

So why not do that create some "manual initialisation code" which is deployed with the war that loads the session timeout from spring.

Michael Wiles
  • 20,902
  • 18
  • 71
  • 101
  • Aye, this is what I had in mind in number 3. Was hoping to avoid this, but I prefer it to the other two options. That said, if I spend some time to create some auto deploy scripts for GlassFish itself (the app server not the web app), then this is my preferred option. – Muel Jul 06 '12 at 03:20
0

Check out this question on SO, There can be two ways but not sure -

  1. You can have different web.xml files for each environment and build the war file with corresponding web.xml. This is perfectly possible.

  2. You can use custom HttpSessionListener as shown in the above link. Though it has session time out set from hard coded value, I would try accessing context initialization parameter from the servlet like

    Session().getServletContext().getInitParameter("paramName");
    

and will define init params with different session timeout values for different environment. I have not tested this code so not sure if you get context params.

Community
  • 1
  • 1
Sunil Chavan
  • 2,934
  • 4
  • 25
  • 24
  • Thanks for the comment. Your number 1 is equivalent to using Maven filtering. It's (generally speaking) bad practice to have a different WAR per environment. Regarding your number 2, this combined with Spring is what I had in mind for my number 3! – Muel Jul 06 '12 at 03:20