Return-Path: Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 79242 invoked by uid 500); 29 Apr 2000 05:59:58 -0000 Delivered-To: apmail-jakarta-tomcat-cvs@apache.org Received: (qmail 79238 invoked by uid 1059); 29 Apr 2000 05:59:57 -0000 Date: 29 Apr 2000 05:59:57 -0000 Message-ID: <20000429055957.79237.qmail@locus.apache.org> From: craigmcc@locus.apache.org To: jakarta-tomcat-cvs@apache.org Subject: cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/valves AccessLogValve.java craigmcc 00/04/28 22:59:57 Modified: proposals/catalina build.xml proposals/catalina/src/conf server.xml proposals/catalina/src/share/org/apache/tomcat Host.java proposals/catalina/src/share/org/apache/tomcat/connector ResponseBase.java proposals/catalina/src/share/org/apache/tomcat/core ContainerBase.java LocalStrings.properties StandardContext.java StandardEngine.java StandardHost.java StandardWrapper.java StandardWrapperValve.java proposals/catalina/src/share/org/apache/tomcat/loader StandardLoader.java proposals/catalina/src/share/org/apache/tomcat/resources StandardResources.java proposals/catalina/src/share/org/apache/tomcat/startup Catalina.java ContextConfig.java LocalStrings.properties proposals/catalina/src/share/org/apache/tomcat/valves AccessLogValve.java Added: proposals/catalina/src/conf tomcat-users.xml web.xml proposals/catalina/src/share/org/apache/tomcat/servlets DefaultServlet.java Log: Debug to the point where Catalina can serve it's first static files. Lots of debugging on the default servlet is still needed, including: - Correct processing of If-Modified-Since - Welcome files when processing a directory - URL-based resource rendering (including last-modified check?) - Deal with URLs like "http://localhost:8080" and "http://localhost:8080/" - Tuning to discover the optimum default buffer sizes Revision Changes Path 1.9 +0 -4 jakarta-tomcat/proposals/catalina/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/build.xml,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- build.xml 2000/04/27 05:55:12 1.8 +++ build.xml 2000/04/29 05:59:51 1.9 @@ -42,10 +42,6 @@ - - 1.10 +14 -8 jakarta-tomcat/proposals/catalina/src/conf/server.xml Index: server.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/conf/server.xml,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- server.xml 2000/04/27 05:55:13 1.9 +++ server.xml 2000/04/29 05:59:51 1.10 @@ -2,7 +2,7 @@ - + @@ -12,7 +12,7 @@ - + - + - + + + neptune + neptune.mcclan.net + - - + + - - + + 1.1 jakarta-tomcat/proposals/catalina/src/conf/tomcat-users.xml Index: tomcat-users.xml =================================================================== 1.1 jakarta-tomcat/proposals/catalina/src/conf/web.xml Index: web.xml =================================================================== default org.apache.tomcat.servlets.DefaultServlet -2147483646 debug 99 invoker org.apache.tomcat.servlets.InvokerServlet debug 99 jsp org.apache.jasper.runtime.JspServlet default / invoker /servlet/* jsp *.jsp 30 txt text/plain html text/html htm text/html gif image/gif jpg image/jpeg jpe image/jpeg jpeg image/jpeg java text/plain body text/html rtx text/richtext tsv text/tab-separated-values etx text/x-setext ps application/x-postscript class application/java csh application/x-csh sh application/x-sh tcl application/x-tcl tex application/x-tex texinfo application/x-texinfo texi application/x-texinfo t application/x-troff tr application/x-troff roff application/x-troff man application/x-troff-man me application/x-troff-me ms application/x-wais-source src application/x-wais-source zip application/zip bcpio application/x-bcpio cpio application/x-cpio gtar application/x-gtar shar application/x-shar sv4cpio application/x-sv4cpio sv4crc application/x-sv4crc tar application/x-tar ustar application/x-ustar dvi application/x-dvi hdf application/x-hdf latex application/x-latex bin application/octet-stream oda application/oda pdf application/pdf ps application/postscript eps application/postscript ai application/postscript rtf application/rtf nc application/x-netcdf cdf application/x-netcdf cer application/x-x509-ca-cert exe application/octet-stream gz application/x-gzip Z application/x-compress z application/x-compress hqx application/mac-binhex40 mif application/x-mif ief image/ief tiff image/tiff tif image/tiff ras image/x-cmu-raster pnm image/x-portable-anymap pbm image/x-portable-bitmap pgm image/x-portable-graymap ppm image/x-portable-pixmap rgb image/x-rgb xbm image/x-xbitmap xpm image/x-xpixmap xwd image/x-xwindowdump au audio/basic snd audio/basic aif audio/x-aiff aiff audio/x-aiff aifc audio/x-aiff wav audio/x-wav mpeg video/mpeg mpg video/mpeg mpe video/mpeg qt video/quicktime mov video/quicktime avi video/x-msvideo movie video/x-sgi-movie avx video/x-rad-screenplay wrl x-world/x-vrml mpv2 video/mpeg2 index.jsp index.html index.htm 1.3 +44 -4 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Host.java Index: Host.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Host.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Host.java 2000/04/23 01:42:28 1.2 +++ Host.java 2000/04/29 05:59:53 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Host.java,v 1.2 2000/04/23 01:42:28 craigmcc Exp $ - * $Revision: 1.2 $ - * $Date: 2000/04/23 01:42:28 $ + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Host.java,v 1.3 2000/04/29 05:59:53 craigmcc Exp $ + * $Revision: 1.3 $ + * $Date: 2000/04/29 05:59:53 $ * * ==================================================================== * @@ -91,12 +91,29 @@ * an individual servlet context), depending upon the Engine implementation. * * @author Craig R. McClanahan - * @version $Revision: 1.2 $ $Date: 2000/04/23 01:42:28 $ + * @version $Revision: 1.3 $ $Date: 2000/04/29 05:59:53 $ */ public interface Host extends Container { + // ----------------------------------------------------- Manifest Constants + + + /** + * The ContainerEvent event type sent when a new alias is added + * by addAlias(). + */ + public static final String ADD_ALIAS_EVENT = "addAlias"; + + + /** + * The ContainerEvent event type sent when an old alias is removed + * by removeAlias(). + */ + public static final String REMOVE_ALIAS_EVENT = "removeAlias"; + + // ------------------------------------------------------------- Properties @@ -132,6 +149,21 @@ /** + * Add an alias name that should be mapped to this same Host. + * + * @param alias The alias to be added + */ + public void addAlias(String alias); + + + /** + * Return the set of alias names for this Host. If none are defined, + * a zero length array is returned. + */ + public String[] findAliases(); + + + /** * Return the Context that should be used to process this request, * based on matching the longest possible context path (or selecting * the default context). If no such Context can be identified, @@ -150,6 +182,14 @@ * @param uri Request URI to be mapped */ public Context map(String uri); + + + /** + * Remove the specified alias name from the aliases for this Host. + * + * @param alias Alias name to be removed + */ + public void removeAlias(String alias); } 1.6 +5 -5 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ResponseBase.java 2000/04/18 03:45:15 1.5 +++ ResponseBase.java 2000/04/29 05:59:53 1.6 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/ResponseBase.java,v 1.5 2000/04/18 03:45:15 craigmcc Exp $ - * $Revision: 1.5 $ - * $Date: 2000/04/18 03:45:15 $ + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/ResponseBase.java,v 1.6 2000/04/29 05:59:53 craigmcc Exp $ + * $Revision: 1.6 $ + * $Date: 2000/04/29 05:59:53 $ * * ==================================================================== * @@ -87,7 +87,7 @@ * the connector-specific methods need to be implemented. * * @author Craig R. McClanahan - * @version $Revision: 1.5 $ $Date: 2000/04/18 03:45:15 $ + * @version $Revision: 1.6 $ $Date: 2000/04/29 05:59:53 $ */ public abstract class ResponseBase @@ -437,7 +437,7 @@ throw new IllegalStateException (sm.getString("responseBase.getOutputStream.ise")); - if (stream != null) + if (stream == null) stream = createOutputStream(); return (stream); 1.14 +84 -44 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java Index: ContainerBase.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ContainerBase.java 2000/04/27 05:55:15 1.13 +++ ContainerBase.java 2000/04/29 05:59:53 1.14 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java,v 1.13 2000/04/27 05:55:15 craigmcc Exp $ - * $Revision: 1.13 $ - * $Date: 2000/04/27 05:55:15 $ + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java,v 1.14 2000/04/29 05:59:53 craigmcc Exp $ + * $Revision: 1.14 $ + * $Date: 2000/04/29 05:59:53 $ * * ==================================================================== * @@ -149,7 +149,7 @@ * class comments of the implementation class. * * @author Craig R. McClanahan - * @version $Revision: 1.13 $ $Date: 2000/04/27 05:55:15 $ + * @version $Revision: 1.14 $ $Date: 2000/04/29 05:59:53 $ */ public abstract class ContainerBase @@ -172,6 +172,12 @@ /** + * The debugging detail level for this component. + */ + protected int debug = 0; + + + /** * The first Valve in the pipeline associated with this Container. */ protected Valve first = null; @@ -272,12 +278,19 @@ */ public synchronized void setBasic(Valve valve) { - // Are we actually changing components? + // Change components if necessary Valve oldBasic = this.basic; if (oldBasic == valve) return; + this.basic = valve; - // Stop the old component if necessary + // Stop the old component if necessary and remove it from the pipeline + if (oldBasic != null) { + Valve previous = getLast(); + if (previous != null) + previous.setNext(null); + oldBasic.setContainer(null); + } if (started && (oldBasic != null) && (oldBasic instanceof Lifecycle)) { try { ((Lifecycle) oldBasic).stop(); @@ -286,10 +299,10 @@ } } - // Start the new component if necessary - if (valve != null) { - valve.setContainer((Container) this); - valve.setNext(null); + // Start the new component if necessary and link it into the pipeline + if (this.basic != null) { + this.basic.setContainer((Container) this); + this.basic.setNext(null); } if (started && (valve != null) && (valve instanceof Lifecycle)) { try { @@ -298,22 +311,10 @@ log("ContainerBase.setBasic: start: ", e); } } - - // Link the new component into the pipeline - if (basic == null) { + if (this.basic != null) { Valve previous = getLast(); if (previous != null) - previous.setNext(valve); - valve.setPrevious(previous); - } else { - Valve previous = basic.getPrevious(); - if (previous != null) - previous.setNext(valve); - valve.setPrevious(previous); - basic.setContainer(null); - basic.setNext(null); - basic.setPrevious(null); - basic = valve; + previous.setNext(this.basic); } // Report this property change to interested listeners @@ -323,6 +324,31 @@ /** + * Return the debugging detail level for this component. + */ + public int getDebug() { + + return (this.debug); + + } + + + /** + * Set the debugging detail level for this component. + * + * @param debug The new debugging detail level + */ + public void setDebug(int debug) { + + int oldDebug = this.debug; + this.debug = debug; + support.firePropertyChange("debug", new Integer(oldDebug), + new Integer(this.debug)); + + } + + + /** * Return descriptive information about this Container implementation and * the corresponding version number, in the format * <description>/<version>. @@ -370,10 +396,11 @@ */ public synchronized void setLoader(Loader loader) { - // Are we actually changing components? + // Change components if necessary Loader oldLoader = this.loader; if (oldLoader == loader) return; + this.loader = loader; // Stop the old component if necessary if (started && (oldLoader != null) && @@ -397,8 +424,7 @@ } } - // Perform the property change and report it - this.loader = loader; + // Report this property change to interested listeners support.firePropertyChange("loader", oldLoader, this.loader); } @@ -427,10 +453,11 @@ */ public synchronized void setLogger(Logger logger) { - // Are we actually changing components? + // Change components if necessary Logger oldLogger = this.logger; if (oldLogger == logger) return; + this.logger = logger; // Stop the old component if necessary if (started && (oldLogger != null) && @@ -454,8 +481,7 @@ } } - // Perform the property change and report it - this.logger = logger; + // Report this property change to interested listeners support.firePropertyChange("logger", oldLogger, this.logger); } @@ -484,10 +510,11 @@ */ public synchronized void setManager(Manager manager) { - // Are we actually changing components? + // Change components if necessary Manager oldManager = this.manager; if (oldManager == manager) return; + this.manager = manager; // Stop the old component if necessary if (started && (oldManager != null) && @@ -511,8 +538,7 @@ } } - // Perform the property change and report it - this.manager = manager; + // Report this property change to interested listeners support.firePropertyChange("manager", oldManager, this.manager); } @@ -575,7 +601,7 @@ public void setParent(Container container) { Container oldParent = this.parent; - this.parent = parent; + this.parent = container; support.firePropertyChange("parent", oldParent, this.parent); } @@ -604,10 +630,11 @@ */ public synchronized void setRealm(Realm realm) { - // Are we actually changing components? + // Change components if necessary Realm oldRealm = this.realm; if (oldRealm == realm) return; + this.realm = realm; // Stop the old component if necessary if (started && (oldRealm != null) && @@ -631,8 +658,7 @@ } } - // Perform the property change and report it - this.realm = realm; + // Report this property change to interested listeners support.firePropertyChange("realm", oldRealm, this.realm); } @@ -661,10 +687,11 @@ */ public synchronized void setResources(Resources resources) { - // Are we actually changing components? + // Change components if necessary Resources oldResources = this.resources; if (oldResources == resources) return; + this.resources = resources; // Stop the old component if necessary if (started && (oldResources != null) && @@ -690,8 +717,7 @@ } } - // Perform the property change and report it - this.resources = resources; + // Report this property change to interested listeners support.firePropertyChange("resources", oldResources, this.resources); } @@ -1142,9 +1168,9 @@ Logger logger = getLogger(); if (logger != null) - logger.log(message); + logger.log(logName() + ": " + message); else - System.out.println(message); + System.out.println(logName() + ": " + message); } @@ -1160,11 +1186,25 @@ Logger logger = getLogger(); if (logger != null) - logger.log(message, throwable); + logger.log(logName() + ": " + message, throwable); else { - System.out.println(message + ": " + throwable); + System.out.println(logName() + ": " + message + ": " + throwable); throwable.printStackTrace(System.out); } + + } + + + /** + * Return the abbreviated name of this container for logging messsages + */ + protected String logName() { + + String className = this.getClass().getName(); + int period = className.lastIndexOf("."); + if (period >= 0) + className = className.substring(period + 1); + return (className + "[" + getName() + "]"); } 1.10 +6 -0 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.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- LocalStrings.properties 2000/04/26 02:14:50 1.9 +++ LocalStrings.properties 2000/04/29 05:59:53 1.10 @@ -1,17 +1,21 @@ containerBase.alreadyStarted=Container has already been started +containerBase.notConfigured=No basic Valve has been configured containerBase.notStarted=Container has not been started interceptorValve.alreadyStarted=InterceptorValve has already been started interceptorValve.notStarted=InterceptorValve has not yet been started standardContext.alreadyStarted=Context has already been started +standardContext.mappingError=MAPPING configuration error for relative URI {0} standardContext.notStarted=Context has not yet been started standardContext.notWrapper=Child of a Context must be a Wrapper standardEngine.alreadyStarted=Engine has already been started +standardEngine.mappingError=MAPPING configuration error for server name {0} standardEngine.notHost=Child of an Engine must be a Host standardEngine.notParent=Engine cannot have a parent Container standardEngine.notStarted=Engine has not yet been started standardEngine.unfoundHost=Virtual host {0} not found standardEngine.unknownHost=No server host specified in this request standardHost.alreadyStarted=Host has already been started +standardHost.mappingError=MAPPING configuration error for requset URI {0} standardHost.noContext=No Context configured to process this request standardHost.noHost=No Host configured to process this request standardHost.notContext=Child of a Host must be a Context @@ -22,6 +26,8 @@ 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.loadError=Exception loading servlet of class {0} standardWrapper.noChild=Wrapper cannot have a child Container standardWrapper.noLoader=Wrapper cannot find the Loader to use standardWrapper.noServlet=No servlet class has been configured +standardWrapper.servletException=Servlet execution threw exception 1.12 +51 -11 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContext.java Index: StandardContext.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContext.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- StandardContext.java 2000/04/26 02:14:50 1.11 +++ StandardContext.java 2000/04/29 05:59:53 1.12 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContext.java,v 1.11 2000/04/26 02:14:50 craigmcc Exp $ - * $Revision: 1.11 $ - * $Date: 2000/04/26 02:14:50 $ + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContext.java,v 1.12 2000/04/29 05:59:53 craigmcc Exp $ + * $Revision: 1.12 $ + * $Date: 2000/04/29 05:59:53 $ * * ==================================================================== * @@ -92,7 +92,7 @@ * requests directed to a particular servlet. * * @author Craig R. McClanahan - * @version $Revision: 1.11 $ $Date: 2000/04/26 02:14:50 $ + * @version $Revision: 1.12 $ $Date: 2000/04/29 05:59:53 $ */ public final class StandardContext @@ -232,9 +232,9 @@ /** - * The welcome files for this application, keyed by welcome file name. + * The welcome files for this application */ - private Hashtable welcomeFiles = new Hashtable(); + private Vector welcomeFiles = new Vector(); /** @@ -654,7 +654,8 @@ */ public void addWelcomeFile(String name) { - welcomeFiles.put(name, name); + welcomeFiles.addElement(name); + postWelcomeFiles(); fireContainerEvent("addWelcomeFile", name); } @@ -1023,7 +1024,13 @@ */ public boolean findWelcomeFile(String name) { - return (welcomeFiles.get(name) != null); + synchronized (welcomeFiles) { + for (int i = 0; i < welcomeFiles.size(); i++) { + if (name.equals((String) welcomeFiles.elementAt(i))) + return (true); + } + return (false); + } } @@ -1036,9 +1043,8 @@ synchronized (welcomeFiles) { String results[] = new String[welcomeFiles.size()]; - Enumeration elements = welcomeFiles.keys(); for (int i = 0; i < results.length; i++) - results[i] = (String) elements.nextElement(); + results[i] = (String) welcomeFiles.elementAt(i); return (results); } @@ -1077,6 +1083,8 @@ String requestURI = ((HttpServletRequest) request.getRequest()).getRequestURI(); String relativeURI = requestURI.substring(contextPath.length()); + if (debug > 0) + log("Mapping relative URI '" + relativeURI + "'"); // Apply the standard request URI mapping rules from the specification Wrapper wrapper = null; @@ -1086,6 +1094,8 @@ // Rule 1 -- Exact Match if (wrapper == null) { + if (debug > 1) + log(" Trying exact match"); name = (String) servletMappings.get(relativeURI); if (name != null) wrapper = (Wrapper) findChild(name); @@ -1097,6 +1107,8 @@ // Rule 2 -- Prefix Match if (wrapper == null) { + if (debug > 1) + log(" Trying prefix match"); servletPath = relativeURI; while (true) { int slash = servletPath.lastIndexOf("/"); @@ -1118,6 +1130,8 @@ // Rule 3 -- Extension Match if (wrapper == null) { + if (debug > 1) + log(" Trying extension match"); int slash = relativeURI.lastIndexOf("/"); if (slash >= 0) { String last = relativeURI.substring(slash); @@ -1137,6 +1151,8 @@ // Rule 4 -- Default Match if (wrapper == null) { + if (debug > 1) + log(" Trying default match"); name = (String) servletMappings.get("/"); if (name != null) wrapper = (Wrapper) findChild(name); @@ -1147,7 +1163,18 @@ } + // Complain if there is no match at all + if (wrapper == null) { + log(sm.getString("standardContext.mappingError", relativeURI)); + return (null); + } + + // Update the Request (if requested) and return this Wrapper + if (debug > 0) + log(" Mapped to servlet '" + wrapper.getName() + + "' with servlet path '" + servletPath + + "' and path info '" + pathInfo + "' and update=" + update); if (update) { request.setWrapper(wrapper); ((HttpRequest) request).setServletPath(servletPath); @@ -1159,6 +1186,18 @@ /** + * Post a copy of our current list of welcome files as a servlet context + * attribute, so that the default servlet can find them. + */ + private void postWelcomeFiles() { + + getServletContext().setAttribute("org.apache.tomcat.WELCOME_FILES", + welcomeFiles); + + } + + + /** * Remove the specified security constraint from this web application. * * @param constraint Constraint to be removed @@ -1328,7 +1367,8 @@ */ public void removeWelcomeFile(String name) { - welcomeFiles.remove(name); + welcomeFiles.removeElement(name); + postWelcomeFiles(); fireContainerEvent("removeWelcomeFile", name); } 1.6 +41 -40 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardEngine.java Index: StandardEngine.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardEngine.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- StandardEngine.java 2000/04/26 02:14:50 1.5 +++ StandardEngine.java 2000/04/29 05:59:54 1.6 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardEngine.java,v 1.5 2000/04/26 02:14:50 craigmcc Exp $ - * $Revision: 1.5 $ - * $Date: 2000/04/26 02:14:50 $ + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardEngine.java,v 1.6 2000/04/29 05:59:54 craigmcc Exp $ + * $Revision: 1.6 $ + * $Date: 2000/04/29 05:59:54 $ * * ==================================================================== * @@ -81,7 +81,7 @@ * fully qualified host name of that virtual host. * * @author Craig R. McClanahan - * @version $Revision: 1.5 $ $Date: 2000/04/26 02:14:50 $ + * @version $Revision: 1.6 $ $Date: 2000/04/29 05:59:54 $ */ public final class StandardEngine @@ -107,7 +107,8 @@ /** - * Host name to use when no server host is specified in the request. + * Host name to use when no server host, or an unknown host, + * is specified in the request. */ private String defaultHost = null; @@ -119,12 +120,6 @@ "org.apache.tomcat.core.StandardEngine/1.0"; - /** - * Host name to use when an unknown host name is specified. - */ - private String unknownHost = null; - - // ------------------------------------------------------------- Properties @@ -153,31 +148,6 @@ } - /** - * Return the unknown host. - */ - public String getUnknownHost() { - - return (unknownHost); - - } - - - /** - * Set the unknown host. - * - * @param host The new unknown host - */ - public void setUnknownHost(String host) { - - String oldUnknownHost = this.unknownHost; - this.unknownHost = host; - support.firePropertyChange("unknownHost", oldUnknownHost, - this.unknownHost); - - } - - // --------------------------------------------------------- Public Methods @@ -220,16 +190,47 @@ public Host map(Request request, boolean update) { // Extract the requested server name - String server = request.getRequest().getServerName(); + String server = request.getRequest().getServerName().toLowerCase(); if (server == null) server = defaultHost; if (server == null) return (null); + if (debug > 0) + log("Mapping server name '" + server + "'"); - // Find the matching child Host + // Find the matching child Host directly + if (debug > 1) + log(" Trying a direct match"); Host host = (Host) findChild(server); - if ((host == null) && (unknownHost != null)) - host = (Host) findChild(unknownHost); + + // Find a matching Host by alias. FIXME - Optimize this! + if (host == null) { + if (debug > 1) + log(" Trying an alias match"); + Container children[] = findChildren(); + for (int i = 0; i < children.length; i++) { + String aliases[] = ((Host) children[i]).findAliases(); + for (int j = 0; j < aliases.length; j++) { + if (server.equals(aliases[j])) { + host = (Host) children[i]; + break; + } + } + if (host != null) + break; + } + } + + // Trying the "default" host if any + if (host == null) { + if (debug > 1) + log(" Trying the default host"); + host = (Host) findChild(defaultHost); + } + + // Complain if no host was found + if (host == null) + log(sm.getString("standardEngine.mappingError", server)); // Update the request if requested, and return the selected host ; // No update to the request is required 1.8 +101 -5 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardHost.java Index: StandardHost.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardHost.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- StandardHost.java 2000/04/26 02:14:50 1.7 +++ StandardHost.java 2000/04/29 05:59:54 1.8 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardHost.java,v 1.7 2000/04/26 02:14:50 craigmcc Exp $ - * $Revision: 1.7 $ - * $Date: 2000/04/26 02:14:50 $ + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardHost.java,v 1.8 2000/04/29 05:59:54 craigmcc Exp $ + * $Revision: 1.8 $ + * $Date: 2000/04/29 05:59:54 $ * * ==================================================================== * @@ -84,7 +84,7 @@ * requests directed to a particular web application. * * @author Craig R. McClanahan - * @version $Revision: 1.7 $ $Date: 2000/04/26 02:14:50 $ + * @version $Revision: 1.8 $ $Date: 2000/04/29 05:59:54 $ */ public final class StandardHost @@ -110,6 +110,12 @@ /** + * The set of aliases for this Host. + */ + private String[] aliases = new String[0]; + + + /** * The descriptive information string for this implementation. */ private static final String info = @@ -156,6 +162,8 @@ throw new IllegalArgumentException (sm.getString("standardHost.nullName")); + name = name.toLowerCase(); // Internally all names are lower case + String oldName = this.name; this.name = name; support.firePropertyChange("name", oldName, this.name); @@ -212,6 +220,33 @@ /** + * Add an alias name that should be mapped to this same Host. + * + * @param alias The alias to be added + */ + public void addAlias(String alias) { + + alias = alias.toLowerCase(); + + // Skip duplicate aliases + for (int i = 0; i < aliases.length; i++) { + if (aliases[i].equals(alias)) + return; + } + + // Add this alias to the list + String newAliases[] = new String[aliases.length + 1]; + for (int i = 0; i < aliases.length; i++) + newAliases[i] = aliases[i]; + newAliases[aliases.length] = alias; + + // Inform interested listeners + fireContainerEvent(ADD_ALIAS_EVENT, alias); + + } + + + /** * Add a child Container, only if the proposed child is an implementation * of Context. * @@ -228,6 +263,17 @@ /** + * Return the set of alias names for this Host. If none are defined, + * a zero length array is returned. + */ + public String[] findAliases() { + + return (this.aliases); + + } + + + /** * Return descriptive information about this Container implementation and * the corresponding version number, in the format * <description>/<version>. @@ -280,7 +326,12 @@ */ public Context map(String uri) { + if (debug > 0) + log("Mapping request URI '" + uri + "'"); + // Match on the longest possible context path prefix + if (debug > 1) + log(" Trying the longest context path prefix"); Context context = null; while (true) { context = (Context) findChild(uri); @@ -293,11 +344,56 @@ } // If no Context matches, select the default Context - if (context == null) + if (context == null) { + if (debug > 1) + log(" Trying the default context"); context = (Context) findChild(""); + } + // Complain if no Context has been selected + if (context == null) { + log(sm.getString("standardHost.mappingError", uri)); + return (null); + } + // Return the mapped Context (if any) + if (debug > 0) + log(" Mapped to context '" + context.getPath() + "'"); return (context); + + } + + + /** + * Remove the specified alias name from the aliases for this Host. + * + * @param alias Alias name to be removed + */ + public void removeAlias(String alias) { + + alias = alias.toLowerCase(); + + // Make sure this alias is currently present + int n = -1; + for (int i = 0; i < aliases.length; i++) { + if (aliases[i].equals(alias)) { + n = i; + break; + } + } + if (n < 0) + return; + + // Remove the specified alias + int j = 0; + String newAliases[] = new String[aliases.length - 1]; + for (int i = 0; i < aliases.length; i++) { + if (i != n) + newAliases[j++] = aliases[i]; + } + + // Inform interested listeners + fireContainerEvent(REMOVE_ALIAS_EVENT, alias); } 1.6 +44 -5 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- StandardWrapper.java 2000/04/26 02:14:51 1.5 +++ StandardWrapper.java 2000/04/29 05:59:54 1.6 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapper.java,v 1.5 2000/04/26 02:14:51 craigmcc Exp $ - * $Revision: 1.5 $ - * $Date: 2000/04/26 02:14:51 $ + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapper.java,v 1.6 2000/04/29 05:59:54 craigmcc Exp $ + * $Revision: 1.6 $ + * $Date: 2000/04/29 05:59:54 $ * * ==================================================================== * @@ -96,7 +96,7 @@ * make them efficient are counter-productive. * * @author Craig R. McClanahan - * @version $Revision: 1.5 $ $Date: 2000/04/26 02:14:51 $ + * @version $Revision: 1.6 $ $Date: 2000/04/29 05:59:54 $ */ public final class StandardWrapper @@ -128,6 +128,12 @@ /** + * The debugging detail level for this component. + */ + private int debug = 2; + + + /** * The descriptive information string for this implementation. */ private static final String info = @@ -184,6 +190,28 @@ /** + * Return the debugging detail level for this component. + */ + public int getDebug() { + + return (this.debug); + + } + + + /** + * Set the debugging detail level for this component. + * + * @param debug The new debugging detail level + */ + public void setDebug(int debug) { + + this.debug = debug; + + } + + + /** * Return descriptive information about this Container implementation and * the corresponding version number, in the format * <description>/<version>. @@ -380,28 +408,39 @@ */ public Servlet allocate() { + if (debug > 0) + log("Allocating an instance"); + // Load and initialize our instance if necessary if (instance == null) { try { load(); } catch (Exception e) { + log(sm.getString("standardWrapper.loadError", servletClass), + e); return (null); } } // If not SingleThreadedModel, return the same instance every time - if (!singleThreadModel) + if (!singleThreadModel) { + log(" Returning non-STM instance"); return (instance); + } // Lock and return this instance synchronized (instance) { if (allocated) { + if (debug > 1) + log(" Waiting for allocated STM instance"); try { instance.wait(); } catch (InterruptedException e) { ; } } + if (debug > 1) + log(" Returning allocated STM instance"); allocated = true; return (instance); } 1.4 +62 -12 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- StandardWrapperValve.java 2000/04/23 01:42:35 1.3 +++ StandardWrapperValve.java 2000/04/29 05:59:54 1.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java,v 1.3 2000/04/23 01:42:35 craigmcc Exp $ - * $Revision: 1.3 $ - * $Date: 2000/04/23 01:42:35 $ + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java,v 1.4 2000/04/29 05:59:54 craigmcc Exp $ + * $Revision: 1.4 $ + * $Date: 2000/04/29 05:59:54 $ * * ==================================================================== * @@ -74,6 +74,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.tomcat.Container; +import org.apache.tomcat.Logger; import org.apache.tomcat.Request; import org.apache.tomcat.Response; import org.apache.tomcat.Wrapper; @@ -86,7 +87,7 @@ * StandardWrapper container implementation. * * @author Craig R. McClanahan - * @version $Revision: 1.3 $ $Date: 2000/04/23 01:42:35 $ + * @version $Revision: 1.4 $ $Date: 2000/04/29 05:59:54 $ */ final class StandardWrapperValve @@ -125,24 +126,73 @@ Servlet servlet = null; try { - servlet = wrapper.allocate(); - if ((servlet instanceof HttpServlet) && (sreq instanceof HttpServletRequest) && - (sres instanceof HttpServletResponse)) + (sres instanceof HttpServletResponse)) { ((HttpServlet) servlet).service((HttpServletRequest) sreq, (HttpServletResponse) sres); - else + } else { servlet.service(sreq, sres); - + } wrapper.deallocate(servlet); - } catch (Throwable t) { - - ; // FIXME - deal with exceptions thrown by the servlet + log(sm.getString("servletWrapper.servletException"), t); wrapper.deallocate(servlet); + } + + } + + + // -------------------------------------------------------- Private Methods + + + /** + * Log a message on the Logger associated with our Container (if any) + * + * @param message Message to be logged + */ + private void log(String message) { + + Logger logger = null; + if (container != null) + logger = container.getLogger(); + if (logger != null) + logger.log("StandardWrapperValve[" + container.getName() + "]: " + + message); + else { + String containerName = null; + if (container != null) + containerName = container.getName(); + System.out.println("StandardWrapperValve[" + containerName + + "]: " + message); + } + + } + + + /** + * Log a message on the Logger associated with our Container (if any) + * + * @param message Message to be logged + * @param throwable Associated exception + */ + private void log(String message, Throwable throwable) { + Logger logger = null; + if (container != null) + logger = container.getLogger(); + if (logger != null) + logger.log("StandardWrapperValve[" + container.getName() + "] " + + message, throwable); + else { + String containerName = null; + if (container != null) + containerName = container.getName(); + System.out.println("StandardWrapperValve[" + containerName + + "]: " + message); + System.out.println("" + throwable); + throwable.printStackTrace(System.out); } } 1.2 +32 -4 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/loader/StandardLoader.java Index: StandardLoader.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/loader/StandardLoader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- StandardLoader.java 2000/04/26 02:14:53 1.1 +++ StandardLoader.java 2000/04/29 05:59:55 1.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/loader/StandardLoader.java,v 1.1 2000/04/26 02:14:53 craigmcc Exp $ - * $Revision: 1.1 $ - * $Date: 2000/04/26 02:14:53 $ + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/loader/StandardLoader.java,v 1.2 2000/04/29 05:59:55 craigmcc Exp $ + * $Revision: 1.2 $ + * $Date: 2000/04/29 05:59:55 $ * * ==================================================================== * @@ -97,7 +97,7 @@ * is not present, the system class loader will be used instead. * * @author Craig R. McClanahan - * @version $Revision: 1.1 $ $Date: 2000/04/26 02:14:53 $ + * @version $Revision: 1.2 $ $Date: 2000/04/29 05:59:55 $ */ public final class StandardLoader @@ -120,6 +120,12 @@ /** + * The debugging detail level for this component. + */ + private int debug = 0; + + + /** * The descriptive information about this Loader implementation. */ private static final String info = @@ -192,6 +198,28 @@ Container oldContainer = this.container; this.container = container; support.firePropertyChange("container", oldContainer, this.container); + + } + + + /** + * Return the debugging detail level for this component. + */ + public int getDebug() { + + return (this.debug); + + } + + + /** + * Set the debugging detail level for this component. + * + * @param debug The new debugging detail level + */ + public void setDebug(int debug) { + + this.debug = debug; } 1.3 +11 -7 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- StandardResources.java 2000/04/27 05:55:17 1.2 +++ StandardResources.java 2000/04/29 05:59:55 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/StandardResources.java,v 1.2 2000/04/27 05:55:17 craigmcc Exp $ - * $Revision: 1.2 $ - * $Date: 2000/04/27 05:55:17 $ + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/StandardResources.java,v 1.3 2000/04/29 05:59:55 craigmcc Exp $ + * $Revision: 1.3 $ + * $Date: 2000/04/29 05:59:55 $ * * ==================================================================== * @@ -101,7 +101,7 @@ * * * @author Craig R. McClanahan - * @version $Revision: 1.2 $ $Date: 2000/04/27 05:55:17 $ + * @version $Revision: 1.3 $ $Date: 2000/04/29 05:59:55 $ */ public final class StandardResources @@ -346,9 +346,11 @@ */ public String getMimeType(String file) { + if (debug > 0) + log("Calculating MIME type of '" + file + "'"); if (file == null) return (null); - if ((container != null) || (!(container instanceof Context))) + if ((container == null) || (!(container instanceof Context))) return (null); int period = file.lastIndexOf("."); if (period < 0) @@ -356,8 +358,10 @@ String extension = file.substring(period + 1); if (extension.length() < 1) return (null); - else - return (((Context) container).findMimeMapping(extension)); + if (debug > 0) + log(" Mime type of '" + extension + "' is '" + + ((Context) container).findMimeMapping(extension)); + return (((Context) container).findMimeMapping(extension)); } 1.1 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/DefaultServlet.java Index: DefaultServlet.java =================================================================== /* * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/DefaultServlet.java,v 1.1 2000/04/29 05:59:56 craigmcc Exp $ * $Revision: 1.1 $ * $Date: 2000/04/29 05:59:56 $ * * ==================================================================== * * 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 * . * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.tomcat.servlets; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.IOException; import java.io.PrintWriter; import java.net.MalformedURLException; import java.net.URL; import java.sql.Timestamp; import java.util.Enumeration; import java.util.Vector; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.tomcat.util.xml.SaxContext; import org.apache.tomcat.util.xml.XmlAction; import org.apache.tomcat.util.xml.XmlMapper; /** * The default resource-serving servlet for most web applications, * used to serve static resources such as HTML pages and images. * * @author Craig R. McClanahan * @version $Revision: 1.1 $ $Date: 2000/04/29 05:59:56 $ */ public final class DefaultServlet extends HttpServlet { // ----------------------------------------------------- Instance Variables /** * The debugging detail level for this servlet. */ private int debug = 0; /** * The input buffer size to use when serving resources. */ private int input = 2048; /** * The output buffer size to use when serving resources. */ private int output = 2048; /** * The set of welcome files for this web application */ private Vector welcomes = new Vector(); // --------------------------------------------------------- Public Methods /** * Finalize this servlet. */ public void destroy() { ; // No actions necessary } /** * Process a GET request for the specified resource. * * @param request The servlet request we are processing * @param response The servlet response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet-specified error occurs */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // Serve the requested resource, including the data content serveResource(request, response, true); } /** * Process a HEAD request for the specified resource. * * @param request The servlet request we are processing * @param response The servlet response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet-specified error occurs */ /* public void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // Identify the requested resource path String pathInfo = request.getPathInfo(); if (debug > 0) log("DefaultServlet.doHead: Serving resource '" + pathInfo + "'"); if (pathInfo == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } // Serve the requested resource, without the data content serveResource(request, response, false); } */ /** * Process a POST request for the specified resource. * * @param request The servlet request we are processing * @param response The servlet response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet-specified error occurs */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, response); } /** * Return the date and time that the specified resource was last modified, * in milliseconds since midnight January 1, 1970 GMT. If the time is * unknown, a negative number is returned. * * @param request The servlet request we are processing */ public long getLastModified(HttpServletRequest request) { // Identify the requested resource path String pathInfo = request.getPathInfo(); if (debug > 0) log("DefaultServlet.getLastModified: Serving resource '" + pathInfo + "'"); if (pathInfo == null) return (-1); // Convert the resource path to a URL URL resourceURL = null; try { resourceURL = getServletContext().getResource(pathInfo); } catch (MalformedURLException e) { ; } if (resourceURL == null) return (-1); if (debug > 0) log("DefaultServlet.getLastModified: Corresponding URL is '" + resourceURL.toString() + "'"); // Optimized processing for a "file:" URL if ("file".equals(resourceURL.getProtocol())) { File file = new File(resourceURL.getFile()); if (file == null) return (-1); if (!file.exists() || !file.canRead()) return (-1); if (debug > 0) log("DefaultServlet.getLastModified: Last modified on '" + new Timestamp(file.lastModified()) + "'"); return (file.lastModified()); } // Currently do not know how to answer this question for other URLs return (-1); // FIXME: getLastModified() for non-file URL } /** * Initialize this servlet. */ public void init() throws ServletException { // Set our properties from the initialization parameters String value = null; try { value = getServletConfig().getInitParameter("debug"); debug = Integer.parseInt(value); } catch (Throwable t) { ; } try { value = getServletConfig().getInitParameter("input"); input = Integer.parseInt(value); } catch (Throwable t) { ; } try { value = getServletConfig().getInitParameter("output"); output = Integer.parseInt(value); } catch (Throwable t) { ; } // Sanity check on the specified buffer sizes if (input < 256) input = 256; if (output < 256) output = 256; // Initialize the set of welcome files for this application welcomes = (Vector) getServletContext().getAttribute ("org.apache.tomcat.WELCOME_FILES"); if (welcomes == null) welcomes = new Vector(); if (debug > 0) { log("DefaultServlet.init: input buffer size=" + input + ", output buffer size=" + output); for (int i = 0; i < welcomes.size(); i++) log("DefaultServlet.init: welcome file=" + welcomes.elementAt(i)); } } // -------------------------------------------------------- Private Methods /** * Copy the contents of the specified input stream to the specified * output stream, and ensure that both streams are closed before returning * (even in the face of an exception). * * @param istream The input stream to read from * @param ostream The output stream to write to * * @exception IOException if an input/output error occurs */ private void copy(InputStream istream, ServletOutputStream ostream) throws IOException { // Copy the input stream to the output stream IOException exception = null; byte buffer[] = new byte[input]; int len = buffer.length; while (len >= buffer.length) { try { len = istream.read(buffer); ostream.write(buffer, 0, len); } catch (IOException e) { exception = e; len = -1; } if (len < buffer.length) break; } // Clean up the input and output streams try { istream.close(); } catch (Throwable t) { ; } try { ostream.flush(); } catch (Throwable t) { ; } try { ostream.close(); } catch (Throwable t) { ; } // Rethrow any exception that has occurred if (exception != null) throw exception; } /** * Serve the specified directory as a set of hyperlinks to the * included files. * * @param requestURI Request URI of the directory being served * @param directory File object representing this directory * @param response The servlet response we are creating * @param content Should the content be included? * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet-specified error occurs */ public void serveDirectory(String requestURI, File directory, HttpServletResponse response, boolean content) throws IOException, ServletException { if (!content) return; // FIXME - look for a welcome file // FIXME - do the directory thing response.setContentType("text/html"); response.setBufferSize(output); PrintWriter writer = response.getWriter(); writer.println(""); writer.println(""); writer.println("Directory of " + requestURI + ""); writer.println(""); writer.println(""); writer.println("Files in this directory:"); writer.println("
    "); String filenames[] = directory.list(); for (int i = 0; i < filenames.length; i++) { writer.println("
  • " + filenames[i]); } writer.println("
"); writer.println(""); writer.println(""); writer.flush(); writer.close(); } /** * Serve the specified file, optionally including the data content. * * @param requestURI The request URI we are processing * @param pathname Pathname of the file to be served * @param response The servlet response we are creating * @param content Should the content be included? * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet-specified error occurs */ public void serveFile(String requestURI, String pathname, HttpServletResponse response, boolean content) throws IOException, ServletException { // Open the file (if it actually exists) File file = new File(pathname); if (!file.exists() || !file.canRead()) { response.sendError(HttpServletResponse.SC_NOT_FOUND, pathname); return; } if (file.isDirectory()) { serveDirectory(requestURI, file, response, content); return; } InputStream istream = // FIXME: internationalization??????? new BufferedInputStream(new FileInputStream(pathname), input); // Set the appropriate output headers String contentType = getServletContext().getMimeType(pathname); if (contentType != null) { if (debug > 0) log("DefaultServlet.serveFile: contentType='" + contentType + "'"); response.setContentType(contentType); } long contentLength = file.length(); if (contentLength >= 0) { if (debug > 0) log("DefaultServlet.serveFile: contentLength=" + contentLength); response.setContentLength((int) contentLength); } // Copy the input stream to our output stream (if requested) if (content) { response.setBufferSize(output); copy(istream, response.getOutputStream()); } } /** * Serve the specified resource, optionally including the data content. * * @param request The servlet request we are processing * @param response The servlet response we are creating * @param content Should the content be included? * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet-specified error occurs */ public void serveResource(HttpServletRequest request, HttpServletResponse response, boolean content) throws IOException, ServletException { // Identify the requested resource path String pathInfo = request.getPathInfo(); if (debug > 0) { if (content) log("DefaultServlet.serveResource: Serving resource '" + pathInfo + "' headers and data"); else log("DefaultServlet.serveResource: Serving resource '" + pathInfo + "' headers only"); } if (pathInfo == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } // Exclude any resource in the /WEB-INF subdirectory if (pathInfo.startsWith("/WEB-INF")) { response.sendError(HttpServletResponse.SC_NOT_FOUND, pathInfo); return; } // Convert the resource path to a URL URL resourceURL = null; try { resourceURL = getServletContext().getResource(pathInfo); } catch (MalformedURLException e) { ; } if (resourceURL == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, pathInfo); return; } if (debug > 0) log("DefaultServlet.serveResource: Corresponding URL is '" + resourceURL.toString() + "'"); // Optimized processing for a "file:" URL if ("file".equals(resourceURL.getProtocol())) { serveFile(request.getRequestURI(), resourceURL.getFile(), response, content); return; } } } 1.7 +11 -4 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/Catalina.java Index: Catalina.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/Catalina.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Catalina.java 2000/04/27 05:55:20 1.6 +++ Catalina.java 2000/04/29 05:59:56 1.7 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/Catalina.java,v 1.6 2000/04/27 05:55:20 craigmcc Exp $ - * $Revision: 1.6 $ - * $Date: 2000/04/27 05:55:20 $ + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/Catalina.java,v 1.7 2000/04/29 05:59:56 craigmcc Exp $ + * $Revision: 1.7 $ + * $Date: 2000/04/29 05:59:56 $ * * ==================================================================== * @@ -88,7 +88,7 @@ * * * @author Craig R. McClanahan - * @version $Revision: 1.6 $ $Date: 2000/04/27 05:55:20 $ + * @version $Revision: 1.7 $ $Date: 2000/04/29 05:59:56 $ */ public final class Catalina { @@ -236,6 +236,13 @@ mapper.addRule("Server/Engine/Host", mapper.setProperties()); mapper.addRule("Server/Engine/Host", mapper.addChild ("addChild", "org.apache.tomcat.Container")); + + /* FIXME - Server/Engine/Alias + mapper.addRule("Server/Engine/Alias", + mapper.methodSetter("addAlias", 1)); + mapper.addRule("Server/Engine/Alias", + mapper.methodParam(0)); + */ mapper.addRule("Server/Engine/Host/Context", mapper.objectCreate ("org.apache.tomcat.core.StandardContext", 1.4 +12 -4 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/ContextConfig.java Index: ContextConfig.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/ContextConfig.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ContextConfig.java 2000/04/27 05:55:20 1.3 +++ ContextConfig.java 2000/04/29 05:59:56 1.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/ContextConfig.java,v 1.3 2000/04/27 05:55:20 craigmcc Exp $ - * $Revision: 1.3 $ - * $Date: 2000/04/27 05:55:20 $ + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/ContextConfig.java,v 1.4 2000/04/29 05:59:56 craigmcc Exp $ + * $Revision: 1.4 $ + * $Date: 2000/04/29 05:59:56 $ * * ==================================================================== * @@ -77,6 +77,7 @@ import org.apache.tomcat.Logger; import org.apache.tomcat.Resources; import org.apache.tomcat.Wrapper; +import org.apache.tomcat.loader.StandardLoader; import org.apache.tomcat.resources.StandardResources; import org.apache.tomcat.session.StandardManager; import org.apache.tomcat.util.StringManager; @@ -91,7 +92,7 @@ * resource for this web application. * * @author Craig R. McClanahan - * @version $Revision: 1.3 $ $Date: 2000/04/27 05:55:20 $ + * @version $Revision: 1.4 $ $Date: 2000/04/29 05:59:56 $ */ public final class ContextConfig @@ -430,6 +431,13 @@ // Configure a mapper to read a web application deployment descriptor XmlMapper mapper = createMapper(); + + // Add missing Loader component if necessary + if (context.getLoader() == null) { + if (debug > 0) + log(sm.getString("contextConfig.defaultLoader")); + context.setLoader(new StandardLoader()); + } // Add missing Manager component if necessary if (context.getManager() == null) { 1.4 +1 -0 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/LocalStrings.properties Index: LocalStrings.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/LocalStrings.properties,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- LocalStrings.properties 2000/04/27 05:55:20 1.3 +++ LocalStrings.properties 2000/04/29 05:59:56 1.4 @@ -5,6 +5,7 @@ contextConfig.cce=Lifecycle event data object {0} is not a Context contextConfig.defaultClose=Error closing default web.xml contextConfig.defaultConfig=Configuration error in default web.xml +contextConfig.defaultLoader=Configuring default Loader contextConfig.defaultManager=Configuring default Manager contextConfig.defaultMissing=Missing default web.xml, using application web.xml only contextConfig.defaultParse=Parse error in default web.xml 1.7 +4 -4 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/valves/AccessLogValve.java Index: AccessLogValve.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/valves/AccessLogValve.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- AccessLogValve.java 2000/04/26 02:14:55 1.6 +++ AccessLogValve.java 2000/04/29 05:59:57 1.7 @@ -122,7 +122,7 @@ * can be implemented. * * @author Craig R. McClanahan - * @version $Revision: 1.6 $ $Date: 2000/04/26 02:14:55 $ + * @version $Revision: 1.7 $ $Date: 2000/04/29 05:59:57 $ */ public final class AccessLogValve @@ -521,13 +521,13 @@ String timestamp = new Timestamp(System.currentTimeMillis()).toString(); StringBuffer temp = new StringBuffer("["); - temp.append(timestamp.substring(8, 2)); // Day + temp.append(timestamp.substring(8, 10)); // Day temp.append('/'); - temp.append(lookup(timestamp.substring(5, 2))); // Month + temp.append(lookup(timestamp.substring(5, 7))); // Month temp.append('/'); temp.append(timestamp.substring(0, 4)); // Year temp.append(':'); - temp.append(timestamp.substring(11, 8)); // Time + temp.append(timestamp.substring(11, 19)); // Time temp.append(' '); temp.append("-0800"); // FIXME!!! temp.append(']');