tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Hanna <Phil.Ha...@sas.com>
Subject Bug in org.apache.tomcat.core.ServletWrapper - UnavailableExcepti on ignored
Date Mon, 31 Jul 2000 17:09:26 GMT
The servlet API says that a servlet cannot be placed into service if the init() method throws
a ServletException.  However, Tomcat does not respect this restriction.  If a servlet throws
an UnavailableException in init(), the servlet is loaded anyway and requests get through to
doGet().  This may possibly relate to this code in ServletWrapper.initServlet():

catch( UnavailableException ex ) {
   unavailable=ex;
   unavailableTime=System.currentTimeMillis();
   unavailableTime += ex.getUnavailableSeconds() * 1000;
}
since ex.getUnavailableSeconds() returns -1 when the UnavailableException is permanent.

Here is a minimal servlet that will demonstrate the bug:

--- cut here ---

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class BlowupServlet extends HttpServlet
{
   public void init(ServletConfig config)
      throws ServletException
   {
      super.init(config);

      // Intentionally throw an UnavailableException
      // to prevent the servlet from being placed
      // into service

      throw new UnavailableException
         ("Never accept requests!");
   }

   public void doGet(
         HttpServletRequest request,
         HttpServletResponse response)
      throws ServletException, IOException
   {
      response.setContentType("text/html");
      response.getWriter().println
         ("This should have blown up."
         + " How did it get through?");
   }
}

--- cut here ---

Phil Hanna
E-Commerce Solutions
SAS Institute, Inc.
Phil.Hanna@sas.com
(919) 677-8000 x4284


Mime
View raw message