Reputation: 20890
I have a servlet filter that adds a random amount of latency to each request. Right now I toggle it on when I am developing, and switch it off before I deploy to the production server, but I have to do it manually.
Is there something I can do to automatically detect the development environment and only apply the filter there?
Upvotes: 0
Views: 735
Reputation: 3200
We use system properties to set a property on each application server that allows the application to determine whether it is running on live or dev. This works best if you have control of these environments which means you can standardise naming conventions etc.
We use Tomcat, and the startup and shutdown scripts have been modified to add some extra properties to the JVM. For example:
JVM_OPTS="-Dfuturemedium.javalogs=/usr/share/tomcat_a/logs/ \
-Dfuturemedium.server.development=false \
-Dfuturemedium.smtp.server=localhost"
This means that environment-specific properties are taken out of the hands of each individual developer and pushed into the environment itself where they can be controlled by the sys admin and not duplicated throughout build files etc.
We can then access these properties in code via:
boolean dev = Boolean.parseBoolean(System.getProperty("futuremedium.server.development", "false"));
in order to conditionally perform some action based on whether it is live or dev. Or in log4j.properties we can use:
log4j.appender.myapplication_file.File=${futuremedium.javalogs}myapplication.log
It is easy enough to specify these same properties on the command line for any CLI apps as well so it is fairly transparent inside or outside the container.
Not sure what IDE you use, but if you are running an app server within it then it should be possible to control those extra properties via the IDE too. For Tomcat inside Netbeans go to Tools --> Servers --> Tomcat --> Platform --> VM Options
Upvotes: 2
Reputation: 2637
If you have some property that is accessible via the build.xml , then the build.xml could manipulate your web.xml to enable disable the filters that you need depending on the environment. - assuming that you are using build.xml.
Upvotes: 0