Hi,Yes, very ugly.
You can't do it from a servlet's init method. System.exit is an ugly
solution: what if there are other webapps on the container?
Two options come to mind:That sounds like the best/simplest option. We'll try it, thanks!
- Move this init code to a ServletContextListener's contextInitialized
method. If an error occurs, throw a RuntimeException (or any subclass
thereof). The container will mark the context as unavailable and
requests will be rejected with a 500-level response.
- Have the init servlet set some sort of marker variable in a singleton,That sounds good, too. There is one important benefit to this approach - the context could display something about why it's not available or some other nice thing rather than providing a generic 500 response.
making the app unavailable. Have a filter mapped to /* check this
marker variable for every request, and reject the request in whatever
way you see fit if the app is marked as unavailable.
Whatever you do, remember to handle the case of a webapp reload
appropriately. (This is one reason why the ContextListener approach is
good).
I'm not sure what you mean about handling webapp reload. Is your concern that the singleton static field "marker" could still be hanging around in a possibly invalid state? Or is there something more to your words of caution?
Thanks again, Yoav.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
