Skip to main content

[webtier] Re: How to stop application deployment after failed initialization

1 reply [Last post]
Anonymous

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Jan Luehe

On 05/ 8/09 09:18 AM, glassfish@javadesktop.org wrote:
> I'm using an instance of 'ServletContextListener' to do some initialization work not just on the first request but immediately after deployment. As it happens in real world, such kind of initialization can fail (because a required database is down or alike).
>
> Now the question that arises: Like in any other runtime environment, the most natural reaction upon an initialization failure would be do abort the application start (which in case of an web app means: stop deployment or somehow shutdown the non-working web-app, of course after emitting an appropriate error message, which would be sent back to the deployment tool or go to the log file). Unfortunately the 'contextInitialized' method doesn't have a signature that allows an exception to be thrown.
>
You can throw a RuntimeException, though, which does not need to be
declared in any
method signature.
> Does anybody have an idea how to accomplish this? A fallback solution that I can see would be to set an error flag and upon this redirect any request to an additional web page that says that even though requests being served the application is nonetheless not working. Not too elegant.
>
> most probably the code used is clear to readers of this forum, but to be on the safe side:
>
> public class ApplicationInitializer implements ServletContextListener {
> public void contextInitialized(ServletContextEvent event) {
> // how to handle fatal error here (no Exception in method signature)
> }
> }
>
>

Sounds like the fix for

https://glassfish.dev.java.net/issues/show_bug.cgi?id=7482
("Have any runtime exceptions thrown by
javax.servlet.ServletContextListener#contextInitialized
abort deployment")

is what you are looking for. :)

Let us know if you have any questions.

Thanks,

Jan

> in web.xml:
>
>
> packagepath.ApplicationInitializer
>
>
> [Message sent by forum member 'frankwhofmann' (frankwhofmann)]
>
> http://forums.java.net/jive/thread.jspa?messageID=345550
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net