Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What to do in case of servlet initialization failure ?

 
James Adams
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a web application in which I will want to successfully initialize all servlets before making it available to users. As such I will want all servlets which access a database to make their connections in their init() methods, and if these don't succeed I want to alert the administrator, log the errors, and disallow access to the servlets. Is there a standard way of doing this ?
I have thought that I could load all servlets on startup which would call the init() methods in which the database connections are made. If any of these fail then I will want to disallow access to any of the servlets of the web application. Is there a way of disabling these servlets programmatically, or am I limited to paying attention to the console and error logs when I deploy the web application, and undeploy if any errors are encountered ?
Thanks in advance for any feedback.

-James
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the servlet API - javax.servlet.UnavailableException - if a servlet throws this exception, either at the init stage or later, the servlet container will not try to send any requests to it.
Bill
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic