Dan,

Pardon my advice, but... this sounds like a programming/config/illegal
state error that shouldn't make it to production.  

Of course, you could simply add instrumentation to the system to detect
that this servlet didn't do its thing, and route every request to a
holding page.

Joe

-----Original Message-----
From: Dan Armbrust [mailto:daniel.armbrust.l...@gmail.com] 
Sent: Thursday, November 12, 2009 10:48 AM
To: Tomcat Users List
Subject: How to cancel a servlet startup?

If I have a servlet which fails during init() for whatever reason -
the example below takes a null pointer....

public class MyServlet extends HttpServlet
{
        private static final long serialVersionUID =
7997991143724219371L;

        @Override
        public void destroy()
        {
                //do stuff....
                super.destroy();
        }

        @Override
        public void init() throws ServletException
        {
                try
                {
                        String a = null;
                        a.toString();
                }
                catch (Exception e)
                {
                        System.err.println("Startup error - cancelling
startup." +  e);
                        try
                        {
                                destroy();
                        }
                        catch (Exception e1)
                        {
                                //noop
                        }
                        throw new ServletException("Startup failing due
to unexpected error: " + e);
                }
        }
}


How can I make tomcat cancel the deployment of the entire war file
that this servlet was distributed with?

I thought that throwing a ServletException back up to Tomcat would
make the webapp unavailable - but Tomcat continues to serve pages from
this webapp even though the startup failed.  That doesn't seem like
correct behavior... am I missing a setting somewhere?

Thanks,

Dan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to