billbarker 2003/02/16 19:38:55 Modified: util/java/org/apache/tomcat/util/http/mapper Mapper.java Log: First shot at allowing internal-redirects to welcome-files. Also adding in c-l. To Do: Rule 4 and Rule 6 should probably be merged, since I think that it broken wrt the spec otherwise. Implement a welcome-file cache to avoid the JNDI lookup on every request. Revision Changes Path 1.5 +80 -36 jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/mapper/Mapper.java Index: Mapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/mapper/Mapper.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Mapper.java 29 Jan 2003 20:54:55 -0000 1.4 +++ Mapper.java 17 Feb 2003 03:38:54 -0000 1.5 @@ -58,6 +58,9 @@ */ package org.apache.tomcat.util.http.mapper; +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + import org.apache.tomcat.util.buf.CharChunk; import org.apache.tomcat.util.buf.MessageBytes; @@ -70,6 +73,8 @@ public final class Mapper { + private static org.apache.commons.logging.Log logger = + org.apache.commons.logging.LogFactory.getLog(Mapper.class); // ----------------------------------------------------- Instance Variables @@ -468,42 +473,11 @@ } // Rule 3 -- Extension Match + Wrapper[] extensionWrappers = context.extensionWrappers; if (mappingData.wrapper == null) { - Wrapper[] extensionWrappers = context.extensionWrappers; - char[] buf = path.getBuffer(); - int slash = -1; - for (int i = pathEnd - 1; i >= servletPath; i--) { - if (buf[i] == '/') { - slash = i; - break; - } - } - if (slash >= 0) { - int period = -1; - for (int i = pathEnd - 1; i > slash; i--) { - if (buf[i] == '.') { - period = i; - break; - } - } - if (period >= 0) { - path.setOffset(period + 1); - path.setEnd(pathEnd); - int pos = find(extensionWrappers, path); - if ((pos != -1) - && (path.equals(extensionWrappers[pos].name))) { - mappingData.wrapperPath.setChars - (buf, servletPath, pathEnd - servletPath); - mappingData.requestPath.setChars - (buf, servletPath, pathEnd - servletPath); - mappingData.wrapper = extensionWrappers[pos].object; - } - path.setOffset(servletPath); - path.setEnd(pathEnd); - } - } + internalMapExtensionWrapper(extensionWrappers, path, mappingData); } - + // Rule 4 -- Welcome resources processing for servlets if (mappingData.wrapper == null) { char[] buf = path.getBuffer(); @@ -532,8 +506,37 @@ } // Rule 6 -- Welcome resources processing for physical folder - if (processWelcomeResources) { - + if (processWelcomeResources && mappingData.wrapper == null) { + char[] buf = path.getBuffer(); + if( context.resources != null && buf[pathEnd - 1] == '/') { + for (int i = 0; (i < context.welcomeResources.length) + && (mappingData.wrapper == null); i++) { + path.setOffset(pathOffset); + path.setEnd(pathEnd); + path.append(context.welcomeResources[i], 0, + context.welcomeResources[i].length()); + path.setOffset(servletPath); + Object file = null; + try { + file = context.resources.lookup(path.toString()); + } catch(NamingException nex) { + // Swallow not found, since this is normal + } + if(file != null && !(file instanceof DirContext) ) { + if(logger.isTraceEnabled()) + logger.trace("Found welcome-file: " + path); + internalMapExtensionWrapper(extensionWrappers, + path, mappingData); + if(mappingData.wrapper == null) { + mappingData.wrapper = context.defaultWrapper.object; + mappingData.requestPath.setChars + (path.getBuffer(), path.getStart(), path.getLength()); + mappingData.wrapperPath.setChars + (path.getBuffer(), path.getStart(), path.getLength()); + } + } + } + } } // Rule 7 -- Default servlet @@ -598,6 +601,47 @@ mappingData.requestPath.setChars (path.getBuffer(), path.getOffset(), path.getLength()); mappingData.wrapper = wrappers[pos].object; + } + } + } + + /** + * Extension mappings. + */ + private final void internalMapExtensionWrapper + (Wrapper[] wrappers, CharChunk path, MappingData mappingData) { + char[] buf = path.getBuffer(); + int pathEnd = path.getEnd(); + int servletPath = path.getOffset(); + int slash = -1; + for (int i = pathEnd - 1; i >= servletPath; i--) { + if (buf[i] == '/') { + slash = i; + break; + } + } + if (slash >= 0) { + int period = -1; + for (int i = pathEnd - 1; i > slash; i--) { + if (buf[i] == '.') { + period = i; + break; + } + } + if (period >= 0) { + path.setOffset(period + 1); + path.setEnd(pathEnd); + int pos = find(wrappers, path); + if ((pos != -1) + && (path.equals(wrappers[pos].name))) { + mappingData.wrapperPath.setChars + (buf, servletPath, pathEnd - servletPath); + mappingData.requestPath.setChars + (buf, servletPath, pathEnd - servletPath); + mappingData.wrapper = wrappers[pos].object; + } + path.setOffset(servletPath); + path.setEnd(pathEnd); } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]