0

I just have created a Java Filter that, if one of its properties has a true value, the filter will redirect all the requests to a maintenance JSP (the server is not operational). If that property has a false value, the filter will redirect to the right target. The filter reads the boolean value from a config.properties file. It's something like this:

// Read the file property
private static boolean MAINTENANCE = Boolean.parseBoolean(p.getProperty("maintenance"));
...

if(MAINTENANCE) {
   redirectToURL("maintenance.jsp"); // maintenance JSP
}
else {
   chain.doFilter(request, response); // requested jsp/servlet
}
...

The point is... If my Web is running and I want to put it in maintenance mode, how could I do to make the server reads the new value of that property from the file?

I mean: I connect to the server, edit the config file, set "maintenance" property to value equal to true... But, how can I do to make the web application read it?

Thanks!

Ommadawn
  • 1,850
  • 2
  • 14
  • 36
  • 1
    Which application server are you planning on using? Have you tried taking a look at these answers: [update properties file run time](https://stackoverflow.com/questions/1659642/java-update-properties-file-run-time), [change properties file run time](https://stackoverflow.com/questions/4469774/how-to-change-java-properties-at-runtime) and [Update properties file at runtime](https://stackoverflow.com/questions/15761163/update-properties-file-at-runtime). – aribeiro Aug 23 '17 at 14:37
  • I'm using Tomcat with Java 8 – Ommadawn Aug 23 '17 at 14:38
  • 1
    Then take a look at [this answer](https://stackoverflow.com/questions/9350974/modify-properties-file-in-tomcat-during-runtime). Furthermore, you should think about creating a way of modifying your config file through your application. That way you could trigger its reload and replace the values loaded on the container's initialization. – aribeiro Aug 23 '17 at 14:42
  • Thank you, @aribeiro. One of your links gave me the idea :) – Ommadawn Aug 23 '17 at 14:49

1 Answers1

0

Thanks to @aribeiro, I achieved the solution for me.

For the WebApp startup, I would read the properties from the file.

When I want to make a change of some attribute, I would have to use a request that changes explicitly the value (maybe from an own admin panel).

Ommadawn
  • 1,850
  • 2
  • 14
  • 36