You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/05/16 22:26:28 UTC

cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/util SimplePool.java

craigmcc    00/05/16 13:26:27

  Modified:    proposals/catalina build.xml
               proposals/catalina/src/bin catalina.bat catalina.sh
               proposals/catalina/src/conf web.xml
               proposals/catalina/src/share/org/apache/tomcat Response.java
                        Wrapper.java
               proposals/catalina/src/share/org/apache/tomcat/connector
                        HttpResponseBase.java ResponseBase.java
               proposals/catalina/src/share/org/apache/tomcat/core
                        LocalStrings.properties StandardWrapper.java
                        StandardWrapperValve.java
               proposals/catalina/src/share/org/apache/tomcat/logger
                        FileLogger.java LoggerBase.java
               proposals/catalina/src/share/org/apache/tomcat/resources
                        StandardResources.java
               proposals/catalina/src/share/org/apache/tomcat/servlets
                        InvokerServlet.java
               proposals/catalina/src/share/org/apache/tomcat/session
                        ManagerBase.java
  Added:       proposals/catalina/src/share/org/apache/tomcat/util
                        SimplePool.java
  Log:
  Adjust build and runtime commands so that TOMCAT_HOME is not required
  at runtime.  This will facilitate creating testable distributions of
  Catalina.
  
  Enhance standard logging capabilities such that, if a ServletException
  is logged and a "rootCause" exception is present, the root cause
  exception will be traced as well.
  
  Create response pages for exceptions and HTTP statuses set by a servlet.
  FIXME - does not yet deal with custom error pages from web.xml.
  
  Respect an UnavailableException thrown by a servlet (either the init()
  method or the service() method) per the spec requirements.  In particular,
  Catalina will return SERVICE_UNAVAILABLE errors during the period of
  unavailability.
  
  Revision  Changes    Path
  1.14      +12 -3     jakarta-tomcat/proposals/catalina/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/build.xml,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- build.xml	2000/05/12 00:47:22	1.13
  +++ build.xml	2000/05/16 20:25:39	1.14
  @@ -18,7 +18,6 @@
       <mkdir dir="${catalina.build}/lib"/>
       <mkdir dir="${catalina.build}/logs"/>
       <mkdir dir="${catalina.build}/sessions"/>
  -    <mkdir dir="${catalina.build}/webapps"/>
     </target>
   
     <!-- Copy static files -->
  @@ -42,8 +41,18 @@
       </copydir>
     </target>
   
  -  <!-- Copy the web applications from Tomcat -->
  +  <!-- Copy the JSP compiler and web applications from Tomcat -->
     <target name="tomcat">
  +    <mkdir   dir="${catalina.build}/classes/org/apache/jasper"/>
  +    <copydir src="${tomcat.build}/classes/org/apache/jasper"
  +            dest="${catalina.build}/classes/org/apache/jasper"/>
  +    <mkdir   dir="${catalina.build}/classes/org/apache/tomcat/logging"/>
  +    <copydir src="${tomcat.build}/classes/org/apache/tomcat/logging"
  +            dest="${catalina.build}/classes/org/apache/tomcat/logging"/>
  +    <mkdir   dir="${catalina.build}/classes/org/apache/tomcat/util/xml"/>
  +    <copydir src="${tomcat.build}/classes/org/apache/tomcat/util/xml"
  +            dest="${catalina.build}/classes/org/apache/tomcat/util/xml"/>
  +    <mkdir   dir="${catalina.build}/webapps"/>
       <copydir src="${tomcat.build}/webapps"
               dest="${catalina.build}/webapps"/>
     </target>
  @@ -71,6 +80,6 @@
     </target>
   
     <!-- Clean up and compile everything -->
  -  <target name="all" depends="clean,dist.clean,main,tomcat,dist"/>
  +  <target name="all" depends="clean,dist.clean,main,tomcat,watchdog,dist"/>
   
   </project>
  
  
  
  1.10      +6 -24     jakarta-tomcat/proposals/catalina/src/bin/catalina.bat
  
  Index: catalina.bat
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/bin/catalina.bat,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- catalina.bat	2000/05/07 01:59:09	1.9
  +++ catalina.bat	2000/05/16 20:25:40	1.10
  @@ -4,9 +4,6 @@
   rem
   rem Environment Variable Prequisites:
   rem
  -rem   ANT_HOME      Must point at your Ant installation.
  -rem   ANT_OPTS      (Optional) Java runtime options used when the "ant"
  -rem                 command is executed.
   rem   CATALINA_HOME (Optional) May point at your Catalina "build" directory.
   rem                 If not present, the current working directory is assumed.
   rem   CATALINA_OPTS (Optional) Java runtime options used when the "start",
  @@ -17,12 +14,9 @@
   rem   JAVA_HOME     Must point at your Java Development Kit installation.
   rem   SERVLET_JAR   (Optional) May point at a copy of the "servlet.jar" file
   rem                 to be used.  If not present, the file at
  -rem                 "%TOMCAT_HOME%\lib\servlet.jar" will be assumed.
  -rem   TOMCAT_HOME   (Optional) May point at your Tomcat "build" directory.
  -rem                 If not present, the directory "%CATALINA_HOME%\..\tomcat"
  -rem                 is assumed.
  +rem                 "%CATALINA_HOME%\lib\servlet.jar" will be assumed.
   rem
  -rem $Id: catalina.bat,v 1.9 2000/05/07 01:59:09 craigmcc Exp $
  +rem $Id: catalina.bat,v 1.10 2000/05/16 20:25:40 craigmcc Exp $
   rem ---------------------------------------------------------------------------
   
   
  @@ -31,16 +25,10 @@
   set _CATALINA_HOME=%CATALINA_HOME%
   set _CP=CP
   set _SERVLET_JAR=%SERVLET_JAR%
  -set _TOMCAT_HOME=%TOMCAT_HOME%
   
   
   rem ----- Verify and Set Required Environment Variables -----------------------
   
  -if not "%ANT_HOME%" == "" goto gotAntHome
  -echo You must set ANT_HOME to point at your Ant installation
  -goto cleanup
  -:gotAntHome
  -
   if not "%JAVA_HOME%" == "" goto gotJavaHome
   echo You must set JAVA_HOME to point at your Java Development Kit installation
   goto cleanup
  @@ -50,24 +38,20 @@
   set CATALINA_HOME=.
   :gotCatalinaHome
   
  -if not "%TOMCAT_HOME%" == "" goto gotTomcatHome
  -set TOMCAT_HOME=%CATALINA_HOME%\..\tomcat
  -:gotTomcatHome
  -
   if not "%SERVLET_JAR%" == "" goto gotServletJar
  -set SERVLET_JAR=%TOMCAT_HOME%\lib\servlet.jar
  +set SERVLET_JAR=%CATALINA_HOME%\lib\servlet.jar
   :gotServletJar
   
   
   rem ----- Set Up The Runtime Classpath ----------------------------------------
   
   if "%CLASSPATH%" == "" goto noClassPath
  -set CP=%TOMCAT_HOME%\classes;%CLASSPATH%
  +set CP=%SERVLET_JAR%;%CLASSPATH%
   goto finishClassPath
   :noClassPath
  -set CP=%TOMCAT_HOME%\classes
  +set CP=%SERVLET_JAR%
   :finishClassPath
  -set CP=%CATALINA_HOME%\classes;%SERVLET_JAR%;%CP%;%JAVA_HOME%\lib\tools.jar
  +set CP=%CATALINA_HOME%\classes;%CP%;%JAVA_HOME%\lib\tools.jar
   echo Using CLASSPATH: %CP%
   
   
  @@ -114,6 +98,4 @@
   set _CP=
   set SERVLET_JAR=%_SERVLET_JAR%
   set _SERVLET_JAR=
  -set TOMCAT_HOME=%_TOMCAT_HOME%
  -set _TOMCAT_HOME=
   :finish
  
  
  
  1.7       +7 -23     jakarta-tomcat/proposals/catalina/src/bin/catalina.sh
  
  Index: catalina.sh
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/bin/catalina.sh,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- catalina.sh	2000/05/12 00:47:22	1.6
  +++ catalina.sh	2000/05/16 20:25:40	1.7
  @@ -4,9 +4,6 @@
   #
   # Environment Variable Prequisites
   #
  -#   ANT_HOME      Must point at your Ant installation.
  -#   ANT_OPTS      (Optional) Java runtime options used when the "ant"
  -#                 command is executed.
   #   CATALINA_HOME (Optional) May point at your Catalina "build" directory.
   #                 If not present, the current working directory is assumed.
   #   CATALINA_OPTS (Optional) Java runtime options used when the "start",
  @@ -17,22 +14,14 @@
   #   JAVA_HOME     Must point at your Java Development Kit installation.
   #   SERVLET_JAR   (Optional) May point at a copy of the "servlet.jar" file
   #                 to be used.  If not present, the file at
  -#                 "%TOMCAT_HOME%\lib\servlet.jar" will be assumed.
  -#   TOMCAT_HOME   (Optional) May point at your Tomcat "build" directory.
  -#                 If not present, the directory "%CATALINA_HOME%\..\tomcat"
  -#                 is assumed.
  +#                 "$CATALINA_HOME/lib/servlet.jar" will be assumed.
   #
  -# $Id: catalina.sh,v 1.6 2000/05/12 00:47:22 craigmcc Exp $
  +# $Id: catalina.sh,v 1.7 2000/05/16 20:25:40 craigmcc Exp $
   # -----------------------------------------------------------------------------
   
   
   # ----- Verify and Set Required Environment Variables -------------------------
   
  -if [ "$ANT_HOME" = "" ] ; then
  -  echo You must set ANT_HOME to point at your Ant installation
  -  exit 1
  -fi
  -
   if [ "$CATALINA_HOME" = "" ] ; then
     CATALINA_HOME=`pwd`
   fi
  @@ -46,23 +35,18 @@
     exit 1
   fi
   
  -if [ "$TOMCAT_HOME" = "" ] ; then
  -  TOMCAT_HOME=$CATALINA_HOME/../tomcat
  -fi
  -
   if [ "$SERVLET_JAR" = "" ] ; then
  -  SERVLET_JAR=$TOMCAT_HOME/lib/servlet.jar
  +  SERVLET_JAR=$CATALINA_HOME/lib/servlet.jar
   fi
   
  -
   # ----- Set Up The Runtime Classpath
   
   if [ "$CLASSPATH" = "" ] ; then
  -  CP=$TOMCAT_HOME/classes
  +  CP=$SERVLET_JAR
   else
  -  CP=$TOMCAT_HOME/classes:$CLASSPATH
  +  CP=$SERVLET_JAR:$CLASSPATH
   fi
  -CP=$CATALINA_HOME/classes:$SERVLET_JAR:$CP:$JAVA_HOME/lib/tools.jar
  +CP=$CATALINA_HOME/classes:$CP:$JAVA_HOME/lib/tools.jar
   echo Using CLASSPATH: $CP
   
   
  @@ -70,7 +54,7 @@
   
   if [ "$1" = "env" ] ; then
   
  -  export CATALINA_HOME CP SERVLET_JAR TOMCAT_HOME
  +  export CATALINA_HOME CP SERVLET_JAR
     exit 0
   
   elif [ "$1" = "run" ] ; then
  
  
  
  1.10      +1 -3      jakarta-tomcat/proposals/catalina/src/conf/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/conf/web.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- web.xml	2000/05/14 02:28:59	1.9
  +++ web.xml	2000/05/16 20:25:42	1.10
  @@ -60,9 +60,7 @@
         <param-value>org.apache.jasper.compiler.JikesJavaCompiler</param-value>
       </init-param>
   -->
  -<!--
  -    <load-on-startup>4</load-on-startup>
  --->
  +<!--    <load-on-startup>4</load-on-startup> -->
     </servlet>
   
   
  
  
  
  1.7       +18 -4     jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Response.java
  
  Index: Response.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Response.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Response.java	2000/05/05 06:08:44	1.6
  +++ Response.java	2000/05/16 20:25:44	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Response.java,v 1.6 2000/05/05 06:08:44 craigmcc Exp $
  - * $Revision: 1.6 $
  - * $Date: 2000/05/05 06:08:44 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Response.java,v 1.7 2000/05/16 20:25:44 craigmcc Exp $
  + * $Revision: 1.7 $
  + * $Date: 2000/05/16 20:25:44 $
    *
    * ====================================================================
    *
  @@ -67,6 +67,7 @@
   
   import java.io.IOException;
   import java.io.OutputStream;
  +import java.io.PrintWriter;
   import java.util.Enumeration;
   import javax.servlet.ServletException;
   import javax.servlet.ServletOutputStream;
  @@ -79,7 +80,7 @@
    * based on the processing of a corresponding <code>Request</code>.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.6 $ $Date: 2000/05/05 06:08:44 $
  + * @version $Revision: 1.7 $ $Date: 2000/05/16 20:25:44 $
    */
   
   public interface Response {
  @@ -192,10 +193,23 @@
   
   
       /**
  +     * Return a PrintWriter that can be used to render error messages,
  +     * regardless of whether a stream or writer has already been acquired.
  +     */
  +    public PrintWriter getReporter();
  +
  +
  +    /**
        * Release all object references, and initialize instance variables, in
        * preparation for reuse of this object.
        */
       public void recycle();
  +
  +
  +    /**
  +     * Reset the data buffer but not any status or header information.
  +     */
  +    public void resetBuffer();
   
   
   }
  
  
  
  1.6       +44 -9     jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Wrapper.java
  
  Index: Wrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Wrapper.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Wrapper.java	2000/04/23 01:42:28	1.5
  +++ Wrapper.java	2000/05/16 20:25:45	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Wrapper.java,v 1.5 2000/04/23 01:42:28 craigmcc Exp $
  - * $Revision: 1.5 $
  - * $Date: 2000/04/23 01:42:28 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Wrapper.java,v 1.6 2000/05/16 20:25:45 craigmcc Exp $
  + * $Revision: 1.6 $
  + * $Date: 2000/05/16 20:25:45 $
    *
    * ====================================================================
    *
  @@ -89,7 +89,7 @@
    * <code>IllegalArgumentException</code>.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.5 $ $Date: 2000/04/23 01:42:28 $
  + * @version $Revision: 1.6 $ $Date: 2000/05/16 20:25:45 $
    */
   
   public interface Wrapper extends Container {
  @@ -99,6 +99,27 @@
   
   
       /**
  +     * Return the available date/time for this servlet, in milliseconds since
  +     * the epoch.  If this date/time is in the future, any request for this
  +     * servlet will return an SC_SERVICE_UNAVAILABLE error.  If it is zero,
  +     * the servlet is currently available.  A value equal to Long.MAX_VALUE
  +     * is considered to mean that unavailability is permanent.
  +     */
  +    public long getAvailable();
  +
  +
  +    /**
  +     * Set the available date/time for this servlet, in milliseconds since the
  +     * epoch.  If this date/time is in the future, any request for this servlet
  +     * will return an SC_SERVICE_UNAVAILABLE error.  A value equal to
  +     * Long.MAX_VALUE is considered to mean that unavailability is permanent.
  +     *
  +     * @param available The new available date/time
  +     */
  +    public void setAvailable(long available);
  +
  +
  +    /**
        * Return the context-relative URI of the JSP file for this servlet.
        */
       public String getJspFile();
  @@ -142,6 +163,11 @@
       public void setServletClass(String servletClass);
   
   
  +    /**
  +     * Is this servlet currently unavailable?
  +     */
  +    public boolean isUnavailable();
  +
   
       // --------------------------------------------------------- Public Methods
   
  @@ -174,8 +200,12 @@
        * <code>SingleThreadModel</code>, the Wrapper implementation must ensure
        * that this instance is not allocated again until it is deallocated by a
        * call to <code>deallocate()</code>.
  +     *
  +     * @exception ServletException if the servlet init() method threw
  +     *  an exception
  +     * @exception ServletException if a loading error occurs
        */
  -    public Servlet allocate();
  +    public Servlet allocate() throws ServletException;
   
   
       /**
  @@ -184,8 +214,10 @@
        * no action is actually required.
        *
        * @param servlet The servlet to be returned
  +     *
  +     * @exception ServletException if a deallocation error occurs
        */
  -    public void deallocate(Servlet servlet);
  +    public void deallocate(Servlet servlet) throws ServletException;
   
   
       /**
  @@ -226,8 +258,9 @@
        * load servlets that are marked in the deployment descriptor to be loaded
        * at server startup time.
        *
  -     * @exception ServletException if thrown by the init() method of the
  -     *  loaded servlet
  +     * @exception ServletException if the servlet init() method threw
  +     *  an exception
  +     * @exception ServletException if some other loading problem occurs
        */
       public void load() throws ServletException;
   
  @@ -254,8 +287,10 @@
        * for example, prior to shutting down the entire servlet engine, or
        * prior to reloading all of the classes from the Loader associated with
        * our Loader's repository.
  +     *
  +     * @exception ServletException if an unload error occurs
        */
  -    public void unload();
  +    public void unload() throws ServletException;
   
   
   }
  
  
  
  1.8       +19 -20    jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpResponseBase.java
  
  Index: HttpResponseBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpResponseBase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HttpResponseBase.java	2000/05/13 01:12:20	1.7
  +++ HttpResponseBase.java	2000/05/16 20:25:46	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpResponseBase.java,v 1.7 2000/05/13 01:12:20 craigmcc Exp $
  - * $Revision: 1.7 $
  - * $Date: 2000/05/13 01:12:20 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpResponseBase.java,v 1.8 2000/05/16 20:25:46 craigmcc Exp $
  + * $Revision: 1.8 $
  + * $Date: 2000/05/16 20:25:46 $
    *
    * ====================================================================
    *
  @@ -93,7 +93,7 @@
    * methods need to be implemented.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.7 $ $Date: 2000/05/13 01:12:20 $
  + * @version $Revision: 1.8 $ $Date: 2000/05/16 20:25:46 $
    */
   
   public class HttpResponseBase
  @@ -811,25 +811,24 @@
   	    throw new IllegalStateException
   		(sm.getString("httpResponseBase.sendError.ise"));
   
  -
  -	// Format a default output message for this error
  -	// FIXME - need to handle web.xml declared error pages
  -	reset();
  -	setContentType("text/html");
  +	// Record the status code and message.
   	this.status = status;
   	this.message = message;
  -	flushBuffer();
   
  -	PrintWriter outputWriter = getWriter();
  -	outputWriter.print("<html>\r\n");
  -	outputWriter.print("<head>\r\n");
  -	outputWriter.print("<title>Tomcat Error Report</title>\r\n");
  -	outputWriter.print("</head>\r\n");
  -	outputWriter.print("<body bgcolor=\"white\">\r\n");
  -	outputWriter.print(message);
  -	outputWriter.print("</body>\r\n");
  -	outputWriter.print("</html>\r\n");
  -	outputWriter.flush();
  +	// Cause the response to be committed but generate no output
  +	try {
  +	    resetBuffer();
  +	} catch (Throwable t) {
  +	    ;
  +	}
  +	String contentType = getContentType();
  +	if ((contentType == null) || "text/plain".equals(contentType))
  +	    setContentType("text/html");
  +	try {
  +	    flushBuffer();
  +	} catch (IOException e) {
  +	    ;
  +	}
   
       }
   
  
  
  
  1.10      +25 -4     jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/ResponseBase.java
  
  Index: ResponseBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/ResponseBase.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ResponseBase.java	2000/05/05 06:08:45	1.9
  +++ ResponseBase.java	2000/05/16 20:25:46	1.10
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/ResponseBase.java,v 1.9 2000/05/05 06:08:45 craigmcc Exp $
  - * $Revision: 1.9 $
  - * $Date: 2000/05/05 06:08:45 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/ResponseBase.java,v 1.10 2000/05/16 20:25:46 craigmcc Exp $
  + * $Revision: 1.10 $
  + * $Date: 2000/05/16 20:25:46 $
    *
    * ====================================================================
    *
  @@ -87,7 +87,7 @@
    * the connector-specific methods need to be implemented.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.9 $ $Date: 2000/05/05 06:08:45 $
  + * @version $Revision: 1.10 $ $Date: 2000/05/16 20:25:46 $
    */
   
   public abstract class ResponseBase
  @@ -360,6 +360,17 @@
   
   
       /**
  +     * Return a PrintWriter that can be used to render error messages,
  +     * regardless of whether a stream or writer has already been acquired.
  +     */
  +    public PrintWriter getReporter() {
  +
  +	return (new PrintWriter(output));
  +
  +    }
  +
  +
  +    /**
        * Release all object references, and initialize instance variables, in
        * preparation for reuse of this object.
        */
  @@ -379,6 +390,16 @@
   	request = null;
   	stream = null;
   	writer = null;
  +
  +    }
  +
  +
  +    /**
  +     * Reset the data buffer but not any status or header information.
  +     */
  +    public void resetBuffer() {
  +
  +	bufferCount = 0;
   
       }
   
  
  
  
  1.15      +60 -8     jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/LocalStrings.properties
  
  Index: LocalStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/LocalStrings.properties,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- LocalStrings.properties	2000/05/15 02:45:05	1.14
  +++ LocalStrings.properties	2000/05/16 20:25:49	1.15
  @@ -39,11 +39,63 @@
   standardServer.start.connectors=At least one connector is not associated with any container
   standardServer.start.started=This server has already been started
   standardServer.stop.notStarted=This server has not yet been started
  -standardWrapper.containerServlet=Loading container servlet class {0}
  -standardWrapper.loadError=Exception loading servlet of class {0}
  -standardWrapper.noChild=Wrapper cannot have a child Container
  -standardWrapper.noClass=Wrapper cannot load class {0}
  -standardWrapper.noLoader=Wrapper cannot find the Loader to use
  -standardWrapper.noServlet=No servlet class has been configured
  -standardWrapper.servletException=Servlet execution threw exception
  -standardWrapper.servletInit=Servlet init() threw exception
  +standardWrapper.allocate=Error allocating a servlet instance
  +standardWrapper.allocateException=Allocate exception for servlet {0}
  +standardWrapper.containerServlet=Loading container servlet {0}
  +standardWrapper.deallocateException=Deallocate exception for servlet {0}
  +standardWrapper.destroyException=Servlet.destroy() for servlet {0} threw exception
  +standardWrapper.exception0=Tomcat Exception Report
  +standardWrapper.exception1=A Servlet Exception Has Occurred
  +standardWrapper.exception2=Exception Report:
  +standardWrapper.exception3=Root Cause:
  +standardWrapper.initException=Servlet.init() for servlet {0} threw exception
  +standardWrapper.intantiate=Error instantiating servlet class {0}
  +standardWrapper.isUnavailable=Servlet {0} is currently unavailable
  +standardWrapper.missingClass=Wrapper cannot find servlet class {0} or a class it depends on
  +standardWrapper.missingLoader=Wrapper cannot find Loader for servlet {0}
  +standardWrapper.notChild=Wrapper container may not have child containers
  +standardWrapper.notClass=No servlet class has been specified for servlet {0}
  +standardWrapper.notContext=Parent container of a Wrapper must be a Context
  +standardWrapper.notServlet=Class {0} is not a Servlet
  +standardWrapper.serviceException=Servlet.service() for servlet {0} threw exception
  +standardWrapper.statusHeader=HTTP Status {0} - {1}
  +standardWrapper.statusTitle=Tomcat Error Report
  +standardWrapper.unavailable=Marking servlet {0} as unavailable
  +http.100=The client may continue ({0}).
  +http.101=The server is switching protocols according to the "Upgrade" header ({0}).
  +#http.201=The request succeeded and a new resource ({0}) has been created on the server.
  +http.202=This request was accepted for processing, but has not been completed ({0}).
  +http.203=The meta information presented by the client did not originate from the server ({0}).
  +http.204=The request succeeded but there is no information to return ({0}).
  +http.205=The client should reset the document view which caused this request to be sent ({0}).
  +#http.206=The server has fulfilled a partial GET request for this resource ({0}).
  +http.300=The requested resource ({0}) corresponds to any one of a set of representations, each with its own specific location.
  +#http.301=The requested resource ({0}) has moved permanently to a new location.
  +#http.302=The requested resource ({0}) has moved temporarily to a new location.
  +http.303=The response to this request can be found under a different URI ({0}).
  +http.304=The requested resource ({0}) is available and has not been modified.
  +http.305=The requested resource ({0}) must be accessed through the proxy given by the "Location" header.
  +http.400=The request sent by the client was syntactically incorrect ({0}).
  +http.401=This request requires HTTP authentication ({0}).
  +http.402=Payment is required for access to this resource ({0}).
  +http.403=Access to the specified resource ({0}) has been forbidden.
  +http.404=The requested resource ({0}) is not available.
  +http.405=The specified HTTP method is not allowed for the requested resource ({0}).
  +http.406=The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ({0}).
  +http.407=The client must first authenticate itself with the proxy ({0}).
  +http.408=The client did not produce a request within the time that the server was prepared to wait ({0}).
  +http.409=The request could not be completed due to a conflict with the current state of the resource ({0}).
  +http.410=The requested resource ({0}) is no longer available, and no forwarding address is known.
  +http.411=This request cannot be handled without a defined content length ({0}).
  +http.412=A specified precondition has failed for this request ({0}).
  +http.413=The request entity is larger than the server is willing or able to process.
  +http.414=The server refused this request because the request URI was too long ({0}).
  +http.415=The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ({0}).
  +http.416=The requested byte range cannot be satisfied ({0}).
  +http.417=The expectation given in the "Expect" request header ({0}) could not be fulfilled.
  +http.500=The server encountered an internal error ({0}) that prevented it from fulfilling this request.
  +http.501=The server does not support the functionality needed to fulfill this request ({0}).
  +http.502=This server received an invalid response from a server it consulted when acting as a proxy or gateway ({0}).
  +http.503=The requested service ({0}) is not currently available.
  +http.504=The server received a timeout from an upstream server while acting as a gateway or proxy ({0}).
  +http.505=The server does not support the requested HTTP protocol version ({0}).
  
  
  
  1.13      +192 -50   jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapper.java
  
  Index: StandardWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapper.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- StandardWrapper.java	2000/05/15 03:16:35	1.12
  +++ StandardWrapper.java	2000/05/16 20:25:50	1.13
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapper.java,v 1.12 2000/05/15 03:16:35 craigmcc Exp $
  - * $Revision: 1.12 $
  - * $Date: 2000/05/15 03:16:35 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapper.java,v 1.13 2000/05/16 20:25:50 craigmcc Exp $
  + * $Revision: 1.13 $
  + * $Date: 2000/05/16 20:25:50 $
    *
    * ====================================================================
    *
  @@ -74,6 +74,7 @@
   import javax.servlet.ServletContext;
   import javax.servlet.ServletException;
   import javax.servlet.SingleThreadModel;
  +import javax.servlet.UnavailableException;
   import javax.servlet.http.HttpServletResponse;
   import org.apache.tomcat.Container;
   import org.apache.tomcat.Context;
  @@ -96,7 +97,7 @@
    * make them efficient are counter-productive.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.12 $ $Date: 2000/05/15 03:16:35 $
  + * @version $Revision: 1.13 $ $Date: 2000/05/16 20:25:50 $
    */
   
   public final class StandardWrapper
  @@ -128,6 +129,15 @@
   
   
       /**
  +     * The date and time at which this servlet will become available (in
  +     * milliseconds since the epoch), or zero if the servlet is available.
  +     * If this value equals Long.MAX_VALUE, the unavailability of this
  +     * servlet is considered permanent.
  +     */
  +    private long available = 0L;
  +
  +
  +    /**
        * The debugging detail level for this component.
        */
       private int debug = 0;
  @@ -190,6 +200,40 @@
   
   
       /**
  +     * Return the available date/time for this servlet, in milliseconds since
  +     * the epoch.  If this date/time is in the future, any request for this
  +     * servlet will return an SC_SERVICE_UNAVAILABLE error.  If it is zero,
  +     * the servlet is currently available.  A value equal to Long.MAX_VALUE
  +     * is considered to mean that unavailability is permanent.
  +     */
  +    public long getAvailable() {
  +
  +	return (this.available);
  +
  +    }
  +
  +
  +    /**
  +     * Set the available date/time for this servlet, in milliseconds since the
  +     * epoch.  If this date/time is in the future, any request for this servlet
  +     * will return an SC_SERVICE_UNAVAILABLE error.
  +     *
  +     * @param available The new available date/time
  +     */
  +    public void setAvailable(long available) {
  +
  +	long oldAvailable = this.available;
  +	if (available > System.currentTimeMillis())
  +	    this.available = available;
  +	else
  +	    this.available = 0L;
  +	support.firePropertyChange("available", new Long(oldAvailable),
  +				   new Long(this.available));
  +
  +    }
  +
  +
  +    /**
        * Return the debugging detail level for this component.
        */
       public int getDebug() {
  @@ -206,7 +250,10 @@
        */
       public void setDebug(int debug) {
   
  +	int oldDebug = this.debug;
   	this.debug = debug;
  +	support.firePropertyChange("debug", new Integer(oldDebug),
  +				   new Long(this.debug));
   
       }
   
  @@ -340,7 +387,7 @@
   
   	try {
   	    load();
  -	} catch (ServletException e) {
  +	} catch (Throwable t) {
   	    ;
   	}
   	return (singleThreadModel);
  @@ -348,6 +395,22 @@
       }
   
   
  +    /**
  +     * Is this servlet currently unavailable?
  +     */
  +    public boolean isUnavailable() {
  +
  +	if (available == 0L)
  +	    return (false);
  +	else if (available <= System.currentTimeMillis()) {
  +	    available = 0L;
  +	    return (false);
  +	} else
  +	    return (true);
  +
  +    }
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -360,7 +423,7 @@
       public void addChild(Container child) {
   
   	throw new IllegalStateException
  -	    (sm.getString("standardWrapper.noChild"));
  +	    (sm.getString("standardWrapper.notChild"));
   
       }
   
  @@ -394,7 +457,6 @@
       }
   
   
  -
       /**
        * Allocate an initialized instance of this Servlet that is ready to have
        * its <code>service()</code> method called.  If the servlet class does
  @@ -405,24 +467,31 @@
        * call to <code>deallocate()</code>.
        * <p>
        * <b>FIXME:  Provide a way to avoid waiting forever.</b>
  +     *
  +     * @exception ServletException if the servlet init() method threw
  +     *  an exception
  +     * @exception ServletException if a loading error occurs
        */
  -    public Servlet allocate() {
  +    public Servlet allocate() throws ServletException {
   
  -	if (debug > 0)
  +	if (debug >= 1)
   	    log("Allocating an instance");
   
   	// Load and initialize our instance if necessary
   	if (instance == null) {
   	    try {
   		load();
  -	    } catch (Exception e) {
  -		return (null);
  +	    } catch (ServletException e) {
  +		throw e;
  +	    } catch (Throwable e) {
  +		throw new ServletException
  +		    (sm.getString("standardWrapper.allocate"), e);
   	    }
   	}
   
   	// If not SingleThreadedModel, return the same instance every time
   	if (!singleThreadModel) {
  -	    if (debug > 1)
  +	    if (debug >= 2)
   		log("  Returning non-STM instance");
   	    return (instance);
   	}
  @@ -430,7 +499,7 @@
   	// Lock and return this instance
   	synchronized (instance) {
   	    if (allocated) {
  -		if (debug > 1)
  +		if (debug >= 2)
   		    log("  Waiting for allocated STM instance");
   		try {
   		    instance.wait();
  @@ -438,7 +507,7 @@
   		    ;
   		}
   	    }
  -	    if (debug > 1)
  +	    if (debug >= 2)
   		log("  Returning allocated STM instance");
   	    allocated = true;
   	    return (instance);
  @@ -453,8 +522,10 @@
        * no action is actually required.
        *
        * @param servlet The servlet to be returned
  +     *
  +     * @exception ServletException if a deallocation error occurs
        */
  -    public void deallocate(Servlet servlet) {
  +    public void deallocate(Servlet servlet) throws ServletException {
   
   	// If not SingleThreadModel, no action is required
   	if (!singleThreadModel)
  @@ -545,66 +616,90 @@
        * for the current web application.  This gives such classes access to Tomcat
        * internals, which are prevented for classes loaded for web applications.
        *
  -     * @exception ServletException if thrown by the init() method of the
  -     *  loaded servlet
  +     * @exception ServletException if the servlet init() method threw
  +     *  an exception
  +     * @exception ServletException if some other loading problem occurs
        */
       public synchronized void load() throws ServletException {
   
  +	// Nothing to do if we already have an instance
   	if (instance != null)
   	    return;
   
   	// Complain if no servlet class has been specified
   	// FIXME - support for JSP file servlets!!!
   	if (servletClass == null) {
  -	    log(sm.getString("standardWrapper.noServlet"));
  +	    unavailable(null);
   	    throw new ServletException
  -		(sm.getString("standardWrapper.noServlet"));
  +		(sm.getString("standardWrapper.notClass", getName()));
   	}
   
   	// Acquire an instance of the class loader to be used
  -	Loader loader = ((Context) getParent()).getLoader();
  +	Loader loader = getLoader();
   	if (loader == null) {
  -	    log(sm.getString("standardWrapper.noLoader"));
  +	    unavailable(null);
   	    throw new ServletException
  -		(sm.getString("standardWrapper.noLoader"));
  +		(sm.getString("standardWrapper.missingLoader", getName()));
   	}
   	ClassLoader classLoader = loader.getClassLoader();
   	if (isContainerServlet(servletClass)) {
   	    classLoader = this.getClass().getClassLoader();
   	    log(sm.getString
  -	          ("standardWrapper.containerServlet", servletClass));
  +	          ("standardWrapper.containerServlet", getName()));
           }
   
  -	// Load and initialize an instance of the specified servlet class
  +	// Load the specified servlet class from the appropriate class loader
  +	Class classClass = null;
   	try {
  -	    Class classClass = null;
   	    if (classLoader != null)
   		classClass = classLoader.loadClass(servletClass);
   	    else
   		classClass = Class.forName(servletClass);
  -	    if (classClass == null) {
  -		log(sm.getString("standardWrapper.noClass", servletClass));
  -		throw new ServletException
  -		    (sm.getString("standardWrapper.noClass", servletClass));
  -	    }
  -	    Servlet servlet = (Servlet) classClass.newInstance();
  -	    if (servlet == null) {
  -		log(sm.getString("standardWrapper.noInstance", servletClass));
  -		throw new ServletException
  -		    (sm.getString("standardWrapper.noInstance", servletClass));
  -	    }
  -	    try {
  -		servlet.init((ServletConfig) this);
  -	    } catch (ServletException f) {
  -		log(sm.getString("standardWrapper.servletInit"), f);
  -		throw f;	// FIXME - UnavailableException handling
  -	    }
  -	    instance = servlet;
  -	} catch (Exception e) {
  -	    log(sm.getString("standardWrapper.loadError", servletClass), e);
  -	    throw new ServletException("load: " + e);
  +	} catch (ClassNotFoundException e) {
  +	    unavailable(null);
  +	    throw new ServletException
  +		(sm.getString("standardWrapper.missingClass", servletClass),
  +		 e);
  +	}
  +	if (classClass == null) {
  +	    unavailable(null);
  +	    throw new ServletException
  +		(sm.getString("standardWrapper.missingClass", servletClass));
  +	}
  +
  +	// Instantiate and initialize an instance of the servlet class itself
  +	Servlet servlet = null;
  +	try {
  +	    servlet = (Servlet) classClass.newInstance();
  +	} catch (ClassCastException e) {
  +	    unavailable(null);
  +	    throw new ServletException
  +		(sm.getString("standardWrapper.notServlet", servletClass), e);
  +	} catch (Throwable e) {
  +	    unavailable(null);
  +	    throw new ServletException
  +		(sm.getString("standardWrapper.instantiate", servletClass), e);
   	}
   
  +	// Call the initialization method of this servlet
  +	try {
  +	    servlet.init((ServletConfig) this);
  +	} catch (UnavailableException f) {
  +	    unavailable(f);
  +	    throw f;
  +	} catch (ServletException f) {
  +	    // If the servlet wanted to be unavailable it would have
  +	    // said so, so do not call unavailable(null).
  +	    throw f;
  +	} catch (Throwable f) {
  +	    // If the servlet wanted to be unavailable it would have
  +	    // said so, so do not call unavailable(null).
  +	    throw new ServletException
  +		(sm.getString("standardWrapper.initException", getName()), f);
  +	}
  +
  +	// Register our newly initialized instance
  +	instance = servlet;
   	singleThreadModel = instance instanceof SingleThreadModel;
   	fireContainerEvent("load", this);
   
  @@ -665,12 +760,28 @@
        * for example, prior to shutting down the entire servlet engine, or
        * prior to reloading all of the classes from the Loader associated with
        * our Loader's repository.
  +     *
  +     * @exception ServletException if an exception is thrown by the
  +     *  destroy() method
        */
  -    public synchronized void unload() {
  +    public synchronized void unload() throws ServletException {
   
  +	// Nothing to do if we have never loaded the instance
   	if (instance == null)
   	    return;
  -	instance.destroy();
  +
  +	// Call the servlet destroy() method
  +	try {
  +	    instance.destroy();
  +	} catch (Throwable t) {
  +	    instance = null;
  +	    fireContainerEvent("unload", this);
  +	    throw new ServletException
  +		(sm.getString("standardWrapper.destroyException", getName()),
  +		 t);
  +	}
  +
  +	// Deregister the destroyed instance
   	instance = null;
   	fireContainerEvent("unload", this);
   
  @@ -733,6 +844,33 @@
       }
   
   
  +    // -------------------------------------------------------- Package Methods
  +
  +
  +    /**
  +     * Process an UnavailableException, marking this servlet as unavailable
  +     * for the specified amount of time.
  +     *
  +     * @param unavailable The exception that occurred, or <code>null</code>
  +     *  to mark this servlet as permanently unavailable
  +     */
  +    void unavailable(UnavailableException unavailable) {
  +	log(sm.getString("standardWrapper.unavailable", getName()));
  +	if (unavailable == null)
  +	    setAvailable(Long.MAX_VALUE);
  +	else if (unavailable.isPermanent())
  +	    setAvailable(Long.MAX_VALUE);
  +	else {
  +	    int unavailableSeconds = unavailable.getUnavailableSeconds();
  +	    if (unavailableSeconds <= 0)
  +		unavailableSeconds = 60;	// Arbitrary default
  +	    setAvailable(System.currentTimeMillis() +
  +			 (unavailableSeconds * 1000L));
  +	}
  +
  +    }
  +
  +
       // -------------------------------------------------------- Private Methods
   
   
  @@ -769,7 +907,7 @@
   	super.start();
   
   	// Load and initialize an instance of this servlet if requested
  -	if (loadOnStartup < 0)
  +	if (loadOnStartup <= 0)
   	    return;
           try {
   	    load();
  @@ -789,7 +927,11 @@
       public void stop() throws LifecycleException {
   
   	// Shut down our servlet instance (if it has been initialized)
  -	unload();
  +	try {
  +	    unload();
  +	} catch (ServletException e) {
  +	    throw new LifecycleException("stop:  " + e);
  +	}
   
   	// Shut down this component
   	super.stop();
  
  
  
  1.9       +269 -40   jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java
  
  Index: StandardWrapperValve.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- StandardWrapperValve.java	2000/05/01 01:53:54	1.8
  +++ StandardWrapperValve.java	2000/05/16 20:25:51	1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java,v 1.8 2000/05/01 01:53:54 craigmcc Exp $
  - * $Revision: 1.8 $
  - * $Date: 2000/05/01 01:53:54 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java,v 1.9 2000/05/16 20:25:51 craigmcc Exp $
  + * $Revision: 1.9 $
  + * $Date: 2000/05/16 20:25:51 $
    *
    * ====================================================================
    *
  @@ -72,10 +72,12 @@
   import javax.servlet.ServletOutputStream;
   import javax.servlet.ServletRequest;
   import javax.servlet.ServletResponse;
  +import javax.servlet.UnavailableException;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   import org.apache.tomcat.Container;
  +import org.apache.tomcat.HttpResponse;
   import org.apache.tomcat.Logger;
   import org.apache.tomcat.Request;
   import org.apache.tomcat.Response;
  @@ -89,7 +91,7 @@
    * <code>StandardWrapper</code> container implementation.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.8 $ $Date: 2000/05/01 01:53:54 $
  + * @version $Revision: 1.9 $ $Date: 2000/05/16 20:25:51 $
    */
   
   final class StandardWrapperValve
  @@ -122,54 +124,134 @@
       public void invoke(Request request, Response response)
   	throws IOException, ServletException {
   
  -	Wrapper wrapper = (Wrapper) getContainer();
  +	// Initialize local variables we may need
  +	boolean unavailable = false;
  +	Throwable throwable = null;
  +	StandardWrapper wrapper = (StandardWrapper) getContainer();
   	ServletRequest sreq = request.getRequest();
   	ServletResponse sres = response.getResponse();
   	Servlet servlet = null;
  +	HttpServletRequest hreq = null;
  +	if (sreq instanceof HttpServletRequest)
  +	    hreq = (HttpServletRequest) sreq;
  +	HttpServletResponse hres = null;
  +	if (sres instanceof HttpServletResponse)
  +	    hres = (HttpServletResponse) sres;
  +
  +	// Check for the servlet being marked unavailable
  +	if (wrapper.isUnavailable()) {
  +	    log(sm.getString("standardWrapper.isUnavailable",
  +			     wrapper.getName()));
  +	    if (hres == null) {
  +		;	// FIXME - Not much we can do generically
  +	    } else {
  +		long available = wrapper.getAvailable();
  +		if ((available > 0L) && (available < Long.MAX_VALUE))
  +		    hres.setDateHeader("Retry-After", available);
  +		hres.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
  +			       sm.getString("standardWrapper.isUnavailable",
  +					    wrapper.getName()));
  +	    }
  +	    unavailable = true;
  +	}
   
  +	// Allocate a servlet instance to process this request
   	try {
  +	    if (!unavailable) {
  +		servlet = wrapper.allocate();
  +	    }
  +	} catch (ServletException e) {
  +	    log(sm.getString("standardWrapper.allocateException",
  +			     wrapper.getName()), e);
  +	    throwable = e;
  +	    exception(request, response, e);
  +	    servlet = null;
  +	} catch (Throwable e) {
  +	    log(sm.getString("standardWrapper.allocateException",
  +			     wrapper.getName()), e);
  +	    throwable = new ServletException
  +		(sm.getString("standardWrapper.allocateException",
  +			      wrapper.getName()), e);
  +	    exception(request, response, (ServletException) throwable);
  +	    servlet = null;
  +	}
   
  -	    // Allocate a servlet instance
  -	    servlet = wrapper.allocate();
  +	// Call the service() method of this instance
  +	try {
  +	    if (servlet != null) {
  +		if ((servlet instanceof HttpServlet) &&
  +		    (hreq != null) && (hres != null)) {
  +		    ((HttpServlet) servlet).service(hreq, hres);
  +		} else {
  +		    servlet.service(sreq, sres);
  +		}
  +	    }
  +	} catch (IOException e) {
  +	    log(sm.getString("standardWrapper.serviceException",
  +			     wrapper.getName()), e);
  +	    ;	// No reporting to the response
  +	    ;	// No change in availability status
  +	} catch (UnavailableException e) {
  +	    log(sm.getString("standardWrapper.serviceException",
  +			     wrapper.getName()), e);
  +	    throwable = e;
  +	    exception(request, response, e);
  +	    wrapper.unavailable(e);
  +	} catch (ServletException e) {
  +	    log(sm.getString("standardWrapper.serviceException",
  +			     wrapper.getName()), e);
  +	    exception(request, response, e);
  +	} catch (Throwable e) {
  +	    log(sm.getString("standardWrapper.serviceException",
  +			     wrapper.getName()), e);
  +	    throwable = new ServletException
  +		(sm.getString("standardWrapper.serviceException",
  +			      wrapper.getName()), e);
  +	    exception(request, response, (ServletException) throwable);
  +	}
   
  -	    // Call the service() method of this instance
  -	    if ((servlet instanceof HttpServlet) &&
  -		(sreq instanceof HttpServletRequest) &&
  -		(sres instanceof HttpServletResponse)) {
  -//		log("Processing request " + ((HttpServletRequest) sreq).getMethod() +
  -//		    " " + ((HttpServletRequest) sreq).getRequestURI());
  -		((HttpServlet) servlet).service((HttpServletRequest) sreq,
  -						(HttpServletResponse) sres);
  -	    } else {
  -		servlet.service(sreq, sres);
  +	// Deallocate the allocated servlet instance
  +	try {
  +	    if (servlet != null) {
  +		wrapper.deallocate(servlet);
   	    }
  +	} catch (ServletException e) {
  +	    log(sm.getString("standardWrapper.deallocateException",
  +			     wrapper.getName()), e);
  +	    throwable = e;
  +	    exception(request, response, e);
  +	} catch (Throwable e) {
  +	    log(sm.getString("standardWrapper.deallocateException",
  +			     wrapper.getName()), e);
  +	    throwable = new ServletException
  +		(sm.getString("standardWrapper.deallocateException",
  +			      wrapper.getName()), e);
  +	    exception(request, response, (ServletException) throwable);
  +	}
   
  -	    // Deallocate the servlet instance
  -	    wrapper.deallocate(servlet);
  +	// Generate a response for the generated HTTP status and message
  +	if (throwable == null) {
  +	    status(request, response);
  +	}
   
  -	    // Flush the output buffer
  -	    PrintWriter writer = null;
  +	// Finish flushing the output buffer as necessary
  +	PrintWriter writer = null;
  +	try {
  +	    writer = sres.getWriter();
   	    try {
  -		writer = sres.getWriter();
  -		try {
  -		    writer.flush();
  -		    writer.close();
  -		} catch (Throwable t) {
  -		    ;
  -		}
  -	    } catch (IllegalStateException e) {
  -		try {
  -		    ServletOutputStream stream = sres.getOutputStream();
  -		    stream.flush();
  -		    stream.close();
  -		} catch (Throwable t) {
  -		    ;
  -		}
  +		writer.flush();
  +		writer.close();
  +	    } catch (Throwable t) {
  +		;
   	    }
  -
  -	} catch (Throwable t) {
  -	    log(sm.getString("standardWrapper.servletException"), t);
  -	    wrapper.deallocate(servlet);
  +	} catch (IllegalStateException e) {
  +	    try {
  +		ServletOutputStream stream = sres.getOutputStream();
  +		stream.flush();
  +		stream.close();
  +	    } catch (Throwable t) {
  +		;
  +	    }
   	}
   
       }
  @@ -179,6 +261,78 @@
   
   
       /**
  +     * Handle the specified ServletException encountered while processing
  +     * the specified Request to produce the specified Response.  Any
  +     * exceptions that occur during generation of the exception report are
  +     * logged and swallowed.
  +     *
  +     * @param request The request being processed
  +     * @param response The response being generated
  +     * @param exception The exception that occurred (which possibly wraps
  +     *  a root cause exception
  +     */
  +    private void exception(Request request, Response response,
  +			   ServletException exception) {
  +
  +	// Reset the response (if possible)
  +	try {
  +	    response.getResponse().reset();
  +	} catch (IllegalStateException e) {
  +	    ;
  +	}
  +
  +	// Render an HTML error page (FIXME - per web.xml descriptor)
  +	Throwable rootCause = exception.getRootCause();
  +	try {
  +	    response.getResponse().setContentType("text/html");
  +	    try {
  +		response.resetBuffer();
  +	    } catch (Throwable e) {
  +		;
  +	    }
  +	    try {
  +		response.getResponse().flushBuffer();
  +	    } catch (IOException e) {
  +		;
  +	    }
  +	    PrintWriter writer = response.getReporter();
  +	    writer.println("<html>");
  +	    writer.println("<head>");
  +	    writer.println("<title>" +
  +			   sm.getString("standardWrapper.exception0") +
  +			   "</title>");
  +	    writer.println("</head>");
  +	    writer.println("<body bgcolor=\"white\">");
  +	    writer.println("<br><br>");
  +	    writer.println("<h1>" +
  +			   sm.getString("standardWrapper.exception1") +
  +			   "</h1>");
  +	    if (rootCause != null)
  +		writer.println("<h3>" +
  +			       sm.getString("standardWrapper.exception2") +
  +			       "</h3>");
  +	    writer.println("<pre>");
  +	    exception.printStackTrace(writer);
  +	    writer.println("</pre>");
  +	    if (rootCause != null) {
  +		writer.println("<h3>" +
  +			       sm.getString("standardWrapper.exception3") +
  +			       "</h3>");
  +		writer.println("<pre>");
  +		rootCause.printStackTrace(writer);
  +		writer.println("</pre>");
  +	    }
  +	    writer.println("</body>");
  +	    writer.println("</html>");
  +	    writer.flush();
  +	} catch (IllegalStateException e) {
  +	    ;
  +	}
  +
  +    }
  +
  +
  +    /**
        * Log a message on the Logger associated with our Container (if any)
        *
        * @param message Message to be logged
  @@ -224,6 +378,81 @@
   			       + "]: " + message);
   	    System.out.println("" + throwable);
   	    throwable.printStackTrace(System.out);
  +	}
  +
  +    }
  +
  +
  +    /**
  +     * Handle the HTTP status code (and corresponding message) generated
  +     * while processing the specified Request to produce the specified
  +     * Response.  Any exceptions that occur during generation of the error
  +     * report are logged and swallowed.
  +     *
  +     * @param request The request being processed
  +     * @param response The response being generated
  +     */
  +    private void status(Request request, Response response) {
  +
  +	// Do nothing on non-HTTP responses
  +	if (!(response instanceof HttpResponse))
  +	    return;
  +	HttpResponse hresponse = (HttpResponse) response;
  +	if (!(response.getResponse() instanceof HttpServletResponse))
  +	    return;
  +	HttpServletResponse hres =
  +	    (HttpServletResponse) response.getResponse();
  +	int status = hresponse.getStatus();
  +	String message = hresponse.getMessage();
  +	if (message == null)
  +	    message = "";
  +	if (status == HttpServletResponse.SC_OK)
  +	    return;
  +
  +	// Do nothing if there is no report for the specified status code
  +	String report = null;
  +	try {
  +	    report = sm.getString("http." + status, message);
  +	} catch (Throwable t) {
  +	    ;
  +	}
  +	if (report == null)
  +	    return;
  +
  +	// Reset the response data buffer (if possible)
  +	try {
  +	    response.resetBuffer();
  +	} catch (Throwable e) {
  +	    ;
  +	}
  +
  +	// Render an HTML status report page (FIXME - per web.xml descriptor)
  +	try {
  +	    hres.setContentType("text/html");
  +	    try {
  +		hres.flushBuffer();
  +	    } catch (IOException e) {
  +		;
  +	    }
  +	    PrintWriter writer = response.getReporter();
  +	    writer.println("<html>");
  +	    writer.println("<head>");
  +	    writer.println("<title>" +
  +			   sm.getString("standardWrapper.statusTitle") +
  +			   "</title>");
  +	    writer.println("</head>");
  +	    writer.println("<body bgcolor=\"white\">");
  +	    writer.println("<br><br>");
  +	    writer.println("<h1>" +
  +			   sm.getString("standardWrapper.statusHeader",
  +					"" + status, message) +
  +			   "</h1>");
  +	    writer.println(report);
  +	    writer.println("</body>");
  +	    writer.println("</html>");
  +	    writer.flush();
  +	} catch (IllegalStateException e) {
  +	    ;
   	}
   
       }
  
  
  
  1.8       +5 -4      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/logger/FileLogger.java
  
  Index: FileLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/logger/FileLogger.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- FileLogger.java	2000/05/05 22:45:37	1.7
  +++ FileLogger.java	2000/05/16 20:25:54	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/logger/FileLogger.java,v 1.7 2000/05/05 22:45:37 craigmcc Exp $
  - * $Revision: 1.7 $
  - * $Date: 2000/05/05 22:45:37 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/logger/FileLogger.java,v 1.8 2000/05/16 20:25:54 craigmcc Exp $
  + * $Revision: 1.8 $
  + * $Date: 2000/05/16 20:25:54 $
    *
    * ====================================================================
    *
  @@ -84,7 +84,7 @@
    * optional preceding timestamp.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.7 $ $Date: 2000/05/05 22:45:37 $
  + * @version $Revision: 1.8 $ $Date: 2000/05/16 20:25:54 $
    */
   
   public final class FileLogger
  @@ -412,3 +412,4 @@
   
   
   }
  +
  
  
  
  1.4       +14 -4     jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/logger/LoggerBase.java
  
  Index: LoggerBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/logger/LoggerBase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LoggerBase.java	2000/04/22 23:15:51	1.3
  +++ LoggerBase.java	2000/05/16 20:25:54	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/logger/LoggerBase.java,v 1.3 2000/04/22 23:15:51 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/04/22 23:15:51 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/logger/LoggerBase.java,v 1.4 2000/05/16 20:25:54 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2000/05/16 20:25:54 $
    *
    * ====================================================================
    *
  @@ -69,6 +69,7 @@
   import java.beans.PropertyChangeListener;
   import java.io.CharArrayWriter;
   import java.io.PrintWriter;
  +import javax.servlet.ServletException;
   import org.apache.tomcat.Container;
   import org.apache.tomcat.Logger;
   
  @@ -79,7 +80,7 @@
    * any property setting and lifecycle methods required for configuration.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2000/04/22 23:15:51 $
  + * @version $Revision: 1.4 $ $Date: 2000/05/16 20:25:54 $
    */
   
   abstract class LoggerBase
  @@ -206,6 +207,15 @@
   	PrintWriter writer = new PrintWriter(buf);
   	writer.println(msg);
   	throwable.printStackTrace(writer);
  +	if (throwable instanceof ServletException) {
  +	    Throwable rootCause =
  +		((ServletException) throwable).getRootCause();
  +	    if (rootCause != null) {
  +		writer.println("----- Root Cause -----");
  +		rootCause.printStackTrace(writer);
  +	    }
  +	}
  +
   	log(buf.toString());
   
       }
  
  
  
  1.8       +4 -5      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/StandardResources.java
  
  Index: StandardResources.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/StandardResources.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StandardResources.java	2000/05/12 00:47:26	1.7
  +++ StandardResources.java	2000/05/16 20:25:55	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/StandardResources.java,v 1.7 2000/05/12 00:47:26 craigmcc Exp $
  - * $Revision: 1.7 $
  - * $Date: 2000/05/12 00:47:26 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/StandardResources.java,v 1.8 2000/05/16 20:25:55 craigmcc Exp $
  + * $Revision: 1.8 $
  + * $Date: 2000/05/16 20:25:55 $
    *
    * ====================================================================
    *
  @@ -85,7 +85,6 @@
   import org.apache.tomcat.Resources;
   import org.apache.tomcat.util.LifecycleSupport;
   import org.apache.tomcat.util.StringManager;
  -import org.apache.tomcat.util.URLUtil;
   
   
   /**
  @@ -101,7 +100,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.7 $ $Date: 2000/05/12 00:47:26 $
  + * @version $Revision: 1.8 $ $Date: 2000/05/16 20:25:55 $
    */
   
   public final class StandardResources
  
  
  
  1.4       +27 -12    jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/InvokerServlet.java
  
  Index: InvokerServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/InvokerServlet.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InvokerServlet.java	2000/05/05 05:59:09	1.3
  +++ InvokerServlet.java	2000/05/16 20:25:57	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/InvokerServlet.java,v 1.3 2000/05/05 05:59:09 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/05/05 05:59:09 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/InvokerServlet.java,v 1.4 2000/05/16 20:25:57 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2000/05/16 20:25:57 $
    *
    * ====================================================================
    *
  @@ -97,7 +97,7 @@
    * in the web application deployment descriptor.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2000/05/05 05:59:09 $
  + * @version $Revision: 1.4 $ $Date: 2000/05/16 20:25:57 $
    */
   
   public final class InvokerServlet
  @@ -210,7 +210,7 @@
   	Wrapper wrapper = (Wrapper) getServletConfig();
   	context = (Context) wrapper.getParent();
   
  -	if (debug > 0)
  +	if (debug >= 1)
   	    log("init: Associated with Context '" + context.getPath() + "'");
   
       }
  @@ -237,20 +237,34 @@
   	throws IOException, ServletException {
   
   	// Identify the class name of the servlet we want
  -	if (debug > 0)
  +	if (debug >= 1)
   	    log("serveRequest: Serving request " + request.getMethod() +
   		" " + request.getRequestURI());
   	String pathInfo = request.getPathInfo();
   	if (pathInfo == null) {
  -	    if (debug > 0)
  +	    if (debug >= 1)
   	        log("serveRequest:  Invalid pathInfo '" + pathInfo + "'");
   	    response.sendError(HttpServletResponse.SC_BAD_REQUEST,
   	                       request.getRequestURI());
   	    return;
           }
  +	String servletClass = pathInfo.substring(1);
   
  +	// See if we can load the class object for this servlet class
  +	/*
  +	try {
  +	    Class clazz = Class.forName(servletClass);
  +	} catch (Throwable t) {
  +	    if (debug >= 1)
  +		log("serveRequest:  Invalid servletClass '" +
  +		    servletClass + "'");
  +	    response.sendError(HttpServletResponse.SC_NOT_FOUND,
  +			       request.getRequestURI());
  +	    return;
  +	}
  +	*/
  +
   	// Create and register a new Wrapper for this servlet class
  -	String servletClass = pathInfo.substring(1);
   	int slash = servletClass.indexOf("/");
   	if (slash >= 0) {
   	    pathInfo = servletClass.substring(slash);
  @@ -261,20 +275,21 @@
   	String name = "org.apache.tomcat.INVOKER." + servletClass;
   	String pattern = request.getServletPath() + "/" + servletClass + "/*";
   	Wrapper wrapper = null;
  -	if (debug > 0)
  +	if (debug >= 1)
   	    log("serveRequest:  Creating wrapper for '" + servletClass +
   		"' with mapping '" + pattern + "'");
   	try {
   	    Class wrapperClassObject = Class.forName(wrapperClass);
   	    wrapper = (Wrapper) wrapperClassObject.newInstance();
   	    wrapper.setName(name);
  -	    wrapper.setLoadOnStartup(0);
  +	    wrapper.setLoadOnStartup(1);
   	    wrapper.setServletClass(servletClass);
   	    context.addChild(wrapper);
   	    context.addServletMapping(pattern, name);
           } catch (Throwable t) {
   	    log("serveRequest", t);
  -	    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
  +	    response.sendError(HttpServletResponse.SC_NOT_FOUND,
  +			       request.getRequestURI());
   	    return;
           }
   
  @@ -284,7 +299,7 @@
   	sb.append(servletClass);
   	sb.append(pathInfo);
   	String dispatcherPath = sb.toString();
  -	if (debug > 0)
  +	if (debug >= 1)
   	    log("serveRequest:  Forwarding to '" + dispatcherPath + "'");
   	RequestDispatcher rd =
   	    getServletContext().getRequestDispatcher(dispatcherPath);
  
  
  
  1.4       +34 -6     jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/session/ManagerBase.java
  
  Index: ManagerBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/session/ManagerBase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ManagerBase.java	2000/04/12 18:46:37	1.3
  +++ ManagerBase.java	2000/05/16 20:26:15	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/session/ManagerBase.java,v 1.3 2000/04/12 18:46:37 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/04/12 18:46:37 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/session/ManagerBase.java,v 1.4 2000/05/16 20:26:15 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2000/05/16 20:26:15 $
    *
    * ====================================================================
    *
  @@ -75,7 +75,6 @@
   import org.apache.tomcat.Manager;
   import org.apache.tomcat.Request;
   import org.apache.tomcat.Session;
  -import org.apache.tomcat.util.SessionUtil;
   
   
   /**
  @@ -84,7 +83,7 @@
    * be subclassed to create more sophisticated Manager implementations.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2000/04/12 18:46:37 $
  + * @version $Revision: 1.4 $ $Date: 2000/05/16 20:26:15 $
    */
   
   public abstract class ManagerBase implements Manager {
  @@ -100,6 +99,12 @@
   
   
       /**
  +     * A counter used to generate session identifiers.
  +     */
  +    protected static int counter = 1010;
  +
  +
  +    /**
        * The distributable flag for Sessions created by this Manager.  If this
        * flag is set to <code>true</code>, any user attributes added to a
        * session controlled by this Manager must be Serializable.
  @@ -279,7 +284,7 @@
   	session.setValid(true);
   	session.setCreationTime(System.currentTimeMillis());
   	session.setMaxInactiveInterval(this.maxInactiveInterval);
  -	session.setId(SessionUtil.generateSessionId());
  +	session.setId(generateSessionId());
   
   	return (session);
   
  @@ -340,6 +345,29 @@
       public void removePropertyChangeListener(PropertyChangeListener listener) {
   
   	support.removePropertyChangeListener(listener);
  +
  +    }
  +
  +
  +    // ------------------------------------------------------ Protected Methods
  +
  +
  +    /**
  +     * Generate and return a new session identifier.
  +     */
  +    protected String generateSessionId() {
  +
  +	Integer i = new Integer(counter++);
  +	StringBuffer buf = new StringBuffer();
  +	String dString = Double.toString(Math.abs(Math.random()));
  +
  +	buf.append("To");
  +	buf.append(i);
  +	buf.append("mC");
  +	buf.append(dString.substring(2));	// Skip "0." at the start
  +	buf.append("At");
  +
  +	return (buf.toString());
   
       }
   
  
  
  
  1.1                  jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/util/SimplePool.java
  
  Index: SimplePool.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/util/SimplePool.java,v 1.1 2000/05/16 20:26:21 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/05/16 20:26:21 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.tomcat.util;
  
  import java.util.zip.*;
  import java.net.*;
  import java.util.*;
  import java.io.*;
  
  /**
   * Simple object pool. Based on ThreadPool and few other classes
   *
   * The pool will ignore overflow and return null if empty.
   *
   * @author Gal Shachor
   * @author Costin
   */
  public final class SimplePool  {
      /*
       * Where the threads are held.
       */
      private Object pool[];
  
      private int max;
      private int minSpare;
      private int maxSpare;
  
      private int current=-1;
  
      Object lock;
      
      public SimplePool(int max) {
  	this.max=max;
  	pool=new Object[max];
  	lock=new Object();
      }
  
      /**
       * Add the object to the pool, silent nothing if the pool is full
       */
      public  void put(Object o) {
  	int idx=-1;
  	synchronized( lock ) {
  	    if( current < max )
  		idx=++current;
  	}
  	if( idx > 0 ) 
  	    pool[idx]=o;
      }
  
      /**
       * Get an object from the pool, null if the pool is empty.
       */
      public  Object get() {
  	int idx=-1;
  	synchronized( lock ) {
  	    if( current >= 0 )
  		idx=current--;
  	}
  	if( idx >= 0  ) 
  	    return pool[idx];
  	return null;
      }
  
      /** Return the size of the pool
       */
      public int getMax() {
  	return max;
      }
  }