views:

78

answers:

4

I have a web application which needs to do some checking before user is allowed to use the application. I want to throw some kind of exception that undeploys or kills the the web application if these checks fails, however I am not sure if there are any exceptions I can throw that kills the web application RuntimeException()? or if I have to System.exit(0)

What is the correct way to kill/stop a web application by force?

+1  A: 

Do not use System.exit(0), this will also kill your container!. A RuntimeException won't stop the application from running also.

I would persist somewhere the result of the check and use it whenever I needed to serve a request.

kgiannakakis
System.exit() can be disallowed by the SecurityManager; I would expect web and application containers to do this.
Michael Borgwardt
+3  A: 

Any exception thrown in the init() method of a servlet that is loaded with in web.xml will undeploy the web application.

nhnb
I cant do that in this example. I have to wait for the application to be fully deployed before I can do my check, and first then I need to force a undeploy or a kill of the web application
Shervin
Thanks. I didn't think of this. I can create a workaround and kill throw exception here that will prevent it to be deployed.
Shervin
+2  A: 

Assumtion

You sayed

to do some checking before user is allowed to use the application

sounds to me like a login screen and maybe some additional environmental checking (licensing, os, ...).

If this is true:

Simply don't let the user log in but give him some hint whats wrong (eg: "Buy a Licence")

If this is false:

Give us some more informations about the kind of your web application (is it interactive? is it a webservice? ...)

tweber
+3  A: 

e.g. in Tomcat You could give your application access to the manager, and when you want to undeploy your application let it call http://localhost:8080/manager/undeploy?path=/examples I think you could also achieve this through a jmx proxy.

For JBoss you could e.g. look at jsr-88 implementation ( which is being pruned in JEE6 but ... maybe jboss keeps it) or also use JMX (i.e. through RMI or so)

note: undeploying a web application because someone authenticated falsly is strange, any next user will not be able to access the app

note2: And indeed as stated before, calling System.exit in a web container will kill the whole container and thus any other applicaiton running in it.

Redlab
Yes, I don't want to kill entire JBoss App server. I just want to kill the app it self
Shervin
i added some hints for jboss
Redlab