views:

92

answers:

3

I'm new to Wicket and would like to maintain a web application from inside itself using some sort of maintenance admin page for running clean-up, DB updates, recovery and so on. Since I plan to use Hibernate or similar for data binding I would like to trigger a complete reboot of the application from inside itself without giving everybody who will be able to run these actions the accompanying Tomcat manager password.

As far as I found out, there does not seem to be an easy way to trigger a real restart of a Java web application without the manager password? However, since there are many Java webapps having such restart functionality in their admin panels, I assume it should be possible to trigger a restart in either specific servlet containers or some web frameworks. They somehow have to do the trick? (or maybe they don't really restart from scratch but just reinitialize without a clean restart?)

I could not find anything about Wicket or Tomcat being able to be triggered with a shutdown and restart from their applications although there are some internal methods in Wicket that might be able to do that? (can be accessed publically but JavaDoc advises against it since they are only for internal use)

From a security point of view I don't really see why an application should not be able to request such a restart from its own code.

Can this be done and if yes, what will I have to do in my application to have it restarted?

Edit: Just to make my question more precise: Neither the user nor the app should have any password that could be used to access the Tomcat manager interface. I was thinking of some method to call or some flag to set to have the servlet container be triggered to restart that particular application without the need of authorization to do so. My thoughts are that since the application is running in a servlet container it should have some way to shutdown and be restarted. If that's not possible in general with Java app servers, there may be some way to do it on application level by doing a call to the underlaying framework (Wicket in this case) to end all running threads, clean up as much as possible and restart the application using the framework; something like a "soft reboot" of the app stack.

+1  A: 

It's mostly irrelevant to your question that your app is using Wicket. It's a java web application using the Wicket framework. Worded like this, your looking for how to restart a web app, using the Tomcat container. If you choose another web application container (jetty etc) then you would need to change the procedure.

You can hit this URL to start an app: http://localhost:8080/manager/start?path=/myapp and http://localhost:8080/manager/stop?path=/myapp to stop your app. Change /myapp to your applications context, and you have start/stop control.

You can then deal with password issues internally in your code.

In light of your clarification you might look at this tomcat documentation and use JMX. However, even JMX is password protected. There is no standard for getting at the container controls from your web app.

Jim Barrows
But that would require the user to have the manager password (as well as a second account to access the manager interface since I block direct access to port 8080 and proxy it through an Apache with HTTP Authentication). The question title may not have been precise enough: The user should be able to restart the app but neither the app itself nor the user should have to access the manager this way, using any manager password. I was thinking of something like getServletContext().restartApplication(); (which does not exist with such a name, obviously)
Energiequant
Using something like HttpClient, and those URLs you can enter the password for the user, so the user never sees it, and never has to enter it.There is no access to the containers controls from the web application.
Jim Barrows
perilandmishap
+1  A: 

I'm trying to think if/what other web frameworks really support this. I think Jim is on to pointing to the right level of the solution. Regardless of what framework being used a web container should allow for the restart of a contained web app. Tomcat would require the manager application to be available. It appears that (from my googling) that Jetty exposes this functionality through JMX MBeans. So the restart functionality may not be portable between containers.

To make this portable, in any framework, I think you'd have to isolate what things are needed to restart. If it's hibernate re-initialize the session factory. If it's spring configuration, this may certainly be more intrusive, but replacing or reconfiguring beans seems the way to go. If it's i18n or markup resources wicket I believes can help with that already.

Matt
A: 

I also encourage you to take a look at JMX. You can turn off authentication for JMX in which case make sure the JMX port is not reachable from the internet (filter the port on your host based firewall, or bind it only to a local ip address). JMX was intended to standardize remote monitoring and control of applications, containers in a Java EE world, so it more or less provides the infrastructure you're looking for.

Or alternatively use another web container (preferably an embedded one) and handle even container restarts from your java code.

cserepj