users@glassfish.java.net

Re: How to stop application deployment after failed initialization

From: Jan Luehe <Jan.Luehe_at_Sun.COM>
Date: Fri, 08 May 2009 10:02:06 -0700

On 05/ 8/09 09:18 AM, glassfish_at_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:
> <listener>
> <listener-class>
> packagepath.ApplicationInitializer
> </listener-class>
> </listener>
> [Message sent by forum member 'frankwhofmann' (frankwhofmann)]
>
> http://forums.java.net/jive/thread.jspa?messageID=345550
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>