0

I have an issue in Glassfish regarding dealing with properties wehn setting up a web application We are moving from using Jetty to a clustered environment setup with GlassFish on Amazon AWS

Conventionally speaking when dealing with Servlets you are meant to use a .properties file when you want to parse in environment variables, however this causes issues when you use a distributed environment (you would have to place the .properties file in every cluster node). GlassFish has the ability to configure properties of the web container through their Admin Console, which means the properties would automatically distribute through the cluster

The problem is, I am getting random behavior regarding retrieving the variables. The first time I ran a test application, I couldn't retrieve the variables, however no it no longer works

Basically I am setting the environment variables through the admin UI. Under Configurations there are 3 configuration stetings, one for the cluster (usually named .config), one default-config and one server-config. Under Web Container, I have put a test property in all 3 of the called "someVal".

I then created a quick Scalatra app in Scala (which uses Servlet 2.5) and I used this line to attempt to get the properties

getServletContext.getInitParameter("someVal")

Any ideas what I am doing incorrectly, it always returns null?

Update It appears what I was attempting to do isn't the "correct" way of doing things. So my question is, what is the standard way of providing specific application settings (outside of the .war and outside of runtime) when dealing with clusters in GlassFish. myfear stated that using a database is the standard approach, however I use these configuration settings themselves to define the JDBC connection

mdedetrich
  • 1,899
  • 1
  • 18
  • 29
  • can you please elaborate on "when dealing with Servlets you are meant to use a .properties file"? You could easily use the Servlet1 test.Servlet1 sleep-time-in-seconds 10 to initialize them ... ? – Markus Eisele Jul 12 '12 at 04:58
  • The web.xml is packaged into the .war file however we have variables that is separate from the .war file (for example host IP which is the IP that is running the .war application). This is why we used a .properties file Essentially I want to configure the website from outside i.e. pass values into the website from outside the .war file (which also includes the web.xml file). GlassFish gives the option where it passes parameters into the web container (what I described earlier) however it appears it doesn't work with the servlet – mdedetrich Jul 12 '12 at 05:43

1 Answers1

0

I got it. You are referring to the Web Container Settings http://docs.oracle.com/cd/E18930_01/html/821-2431/abedw.html

I'm afraid that this never has been thought of as providing application specific configuration and I strongly believe that you will never be able to access those properties from the servlet context. So, you could (should) use the servlet init params in web.xml if you are talking about application specific information. if you use

getServletContext().setInitParameter("param", "value");

you might be able to set them (at least for the runtime of the application). I'm not sure about cluster replication here. The normal way would be to have you configuration settings in the database.

Markus Eisele
  • 712
  • 4
  • 9
  • Yes I was referring to the Web Container Settings and it can't be done during runtime The configuration settings in the database seems like overkill (and more importantly, I use those configuration settings to actually define the JDBC database connection, so I would have to specify some a way to define a database to connect to another database which stores application specific configuration settings) What is the standard way to deal with this situation? It appears that everyone uses .properties however GlassFish must provide some automated way to configure a .war outside of the application – mdedetrich Jul 12 '12 at 07:32
  • Not really. Configuring DataSources is mostly done by admins directly in the runtime. If you need to define your datasource you should think about http://docs.oracle.com/javaee/6/api/javax/annotation/sql/DataSourceDefinition.html and here is an overview where and how this is going to work. http://henk53.wordpress.com/2012/06/30/the-state-of-datasourcedefinition-in-java-ee/ you end up with having a dependent build if you need to switch them for different clients (or whatever). – Markus Eisele Jul 12 '12 at 09:58