Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to programmatically stop deploying a web application  RSS feed

 
Veeresh Hosur
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a servletContextListner which will configure the required configurations for application. If any exception has been thrown during the time of startup I need to stop the deployment in tomcat server. How can I achieve this requirement. Please help me.

Thanks
Veeresh
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deployment is container specific.
I don't know of any way, from within a webapp, to stop deployment in Tomcat.
Any solution, would probably involve putting Tomcat specific code into your application which would make it less portable.

What the servlet spec does offer is the UnavailableException.
http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/UnavailableException.html

Once this is thrown from within a servlet, the container will not try to invoke it until the application is restarted.
If you have a front controller, this only needs to happen in one place. This solution is better than stopping deployment of the app because it gives you the chance to make an informative JSP error handler that can let the users know that this app is down for maintenance and should be running again within (amount of time it would take you to restart the app).

 
Veeresh Hosur
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben,

Thanks for your prompt reply. My use case is something like this. I have a ServleteContextListner within the application which does configuration required for the application. While reading the configuration or while setting up the database connection pool I may get exception. I need to catch the exception and make sure that deployment of my app abruptly stops, so that no one accesses my app. How can I handle that?

Thanks
Veeresh
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try throwing a RuntimeException from the contextInitialized method.
I haven't tried it but that should stop your app from deploying.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try throwing a RuntimeException from the contextInitialized method.
I haven't tried it but that should stop your app from deploying.


We do that in our application. It will

cheers,
ram.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!