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 6958 invoked by uid 2016); 3 Nov 1999 20:39:01 -0000 Delivered-To: apcore-jakarta-tomcat-cvs@apache.org Received: (qmail 6949 invoked by uid 259); 3 Nov 1999 20:39:00 -0000 Date: 3 Nov 1999 20:39:00 -0000 Message-ID: <19991103203900.6948.qmail@hyperreal.org> From: costin@hyperreal.org To: jakarta-tomcat-cvs@apache.org Subject: cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/core Constants.java Container.java Context.java DefaultServlet.java Request.java RequestDispatcherImpl.java RequestMapper.java ServletContextFacade.java ServletLoader.java costin 99/11/03 12:38:59 Modified: src/share/org/apache/tomcat/core Constants.java Container.java Context.java DefaultServlet.java Request.java RequestDispatcherImpl.java RequestMapper.java ServletContextFacade.java ServletLoader.java Log: Merged fixes from J2EE branch to main branch. This is only for tomcat.core package. Revision Changes Path 1.3 +8 -3 jakarta-tomcat/src/share/org/apache/tomcat/core/Constants.java Index: Constants.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Constants.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Constants.java 1999/10/15 00:34:29 1.2 +++ Constants.java 1999/11/03 20:38:49 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Constants.java,v 1.2 1999/10/15 00:34:29 akv Exp $ - * $Revision: 1.2 $ - * $Date: 1999/10/15 00:34:29 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Constants.java,v 1.3 1999/11/03 20:38:49 costin Exp $ + * $Revision: 1.3 $ + * $Date: 1999/11/03 20:38:49 $ * * ==================================================================== * @@ -171,6 +171,8 @@ } public static class JSP { + public static final String NAME = "jsp"; + public static class Directive { public static class Compile { public static final String Name = "jsp_precompile"; @@ -196,6 +198,8 @@ "javax.servlet.error.exception_type"; public static final String ERROR_MESSAGE = "javax.servlet.error.message"; + public static final String RESOLVED_SERVLET = + "javax.servlet.resolved"; } public static class Locale { @@ -221,5 +225,6 @@ public static final String HTTPS = "https"; public static final String FILE = "file"; public static final String WAR = "war"; + public static final String JAR = "jar"; } } 1.2 +25 -16 jakarta-tomcat/src/share/org/apache/tomcat/core/Container.java Index: Container.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Container.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Container.java 1999/10/09 00:30:01 1.1 +++ Container.java 1999/11/03 20:38:51 1.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Container.java,v 1.1 1999/10/09 00:30:01 duncan Exp $ - * $Revision: 1.1 $ - * $Date: 1999/10/09 00:30:01 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Container.java,v 1.2 1999/11/03 20:38:51 costin Exp $ + * $Revision: 1.2 $ + * $Date: 1999/11/03 20:38:51 $ * * ==================================================================== * @@ -78,7 +78,6 @@ public class Container { private Context context; - private ClassLoader classLoader; private ServletLoader servletLoader; private Hashtable servlets = new Hashtable(); private Hashtable prefixMappedServlets = new Hashtable(); @@ -97,14 +96,6 @@ return context; } - ClassLoader getClassLoader() { - return this.classLoader; - } - - void setClassLoader(ClassLoader classLoader) { - this.classLoader = classLoader; - } - ServletLoader getLoader() { if(servletLoader == null) { servletLoader = new ServletLoader(this); @@ -190,19 +181,35 @@ servlets.put(name, wrapper); } - boolean containsServlet(String name) { - ServletWrapper[] sw = getServlets(name); + /** True if we have a servlet with className. + */ + boolean containsServlet(String className) { + ServletWrapper[] sw = getServlets(className); return (sw != null && sw.length > 0); } + /** Check if we have a servlet with the specified name + */ boolean containsServletByName(String name) { return (servlets.containsKey(name)); } - void removeServlet(String name) { - removeServlets(getServlets(name)); + /** Remove all servlets with a specific class name + */ + void removeServlet(String className) { + removeServlets(getServlets(className)); + } + + /** Remove the servlet with a specific name + */ + void removeServletByName(String servletName) { + ServletWrapper wrapper=(ServletWrapper)servlets.get(servletName); + if( wrapper != null ) { + ServletWrapper wa[]={wrapper}; + removeServlets( wa ); + } } boolean containsJSP(String path) { @@ -422,6 +429,8 @@ } } + /** Return servlets with a specified class name + */ private ServletWrapper[] getServlets(String name) { Vector servletWrappers = new Vector(); Enumeration enum = servlets.keys(); 1.7 +80 -61 jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java Index: Context.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Context.java 1999/11/01 20:50:46 1.6 +++ Context.java 1999/11/03 20:38:51 1.7 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java,v 1.6 1999/11/01 20:50:46 costin Exp $ - * $Revision: 1.6 $ - * $Date: 1999/11/01 20:50:46 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java,v 1.7 1999/11/03 20:38:51 costin Exp $ + * $Revision: 1.7 $ + * $Date: 1999/11/03 20:38:51 $ * * ==================================================================== * @@ -64,6 +64,7 @@ package org.apache.tomcat.core; +import org.apache.tomcat.server.*; import org.apache.tomcat.util.*; import org.apache.tomcat.deployment.*; import java.io.*; @@ -240,19 +241,11 @@ } public ClassLoader getClassLoader() { - ClassLoader cl = this.container.getClassLoader(); - - if (cl == null) { - cl = (ClassLoader)this.container.getLoader(); - } - - return (ClassLoader)cl; + return this.classLoader; } public void setClassLoader(ClassLoader classLoader) { - if (! this.initialized) { - this.container.setClassLoader(classLoader); - } + this.classLoader = classLoader; } public String getClassPath() { @@ -269,8 +262,12 @@ return cp; } - public void setClassPath(String classpath) { - this.classPath = classpath; + public void setClassPath(String classPath) { + if (this.classPath.trim().length() > 0) { + this.classPath += File.pathSeparator; + } + + this.classPath += classPath; } /** @@ -521,8 +518,10 @@ public Object getAttribute(String name) { if (name.equals("org.apache.tomcat.jsp_classpath")) - return getClassPath(); - else { + return getClassPath(); + else if(name.equals("org.apache.tomcat.classloader")) { + return this.container.getLoader(); + }else { Object o = attributes.get(name); return attributes.get(name); } @@ -636,6 +635,13 @@ request.setServletPath(result.getServletPath()); request.setPathInfo(result.getPathInfo()); + if (result.getMappedPath() != null) { + request.setAttribute(Constants.Attribute.RESOLVED_SERVLET, + result.getMappedPath()); + } else { + request.removeAttribute(Constants.Attribute.RESOLVED_SERVLET); + } + result.getWrapper().handleRequest(request.getFacade(), response.getFacade()); @@ -663,27 +669,25 @@ private void clearDir(File dir) { String[] files = dir.list(); - if (files == null) { - return; - } - - for (int i = 0; i < files.length; i++) { - File f = new File(dir, files[i]); - - if (f.isDirectory()) { - clearDir(f); + if (files != null) { + for (int i = 0; i < files.length; i++) { + File f = new File(dir, files[i]); + + if (f.isDirectory()) { + clearDir(f); + } + + try { + f.delete(); + } catch (Exception e) { + } } try { - f.delete(); + dir.delete(); } catch (Exception e) { } - } - - try { - dir.delete(); - } catch (Exception e) { - } + } } private void processWebApp(InputStream is) { @@ -755,14 +759,14 @@ resourceName = ((ServletDescriptor)webComponentDescriptor).getClassName(); - if (container.containsServlet(resourceName)) { + if (container.containsServletByName(name)) { String msg = sm.getString("context.dd.dropServlet", - resourceName); + name + "(" + resourceName + ")" ); System.out.println(msg); removeResource = true; - container.removeServlet(resourceName); + container.removeServletByName(name); } container.addServlet(name, resourceName, description); @@ -912,41 +916,56 @@ } private void loadServlets() { - Vector loadServlets = new Vector(); + Vector orderedKeys = new Vector(); Enumeration e = loadableServlets.keys(); + + // order keys while (e.hasMoreElements()) { Integer key = (Integer)e.nextElement(); - Vector v = (Vector)loadableServlets.get(key); - Enumeration lse = v.elements(); + int slot = -1; + + for (int i = 0; i < orderedKeys.size(); i++) { + if (key.intValue() < + ((Integer)(orderedKeys.elementAt(i))).intValue()) { + slot = i; + + break; + } + } - while (lse.hasMoreElements()) { - loadServlets.addElement(lse.nextElement()); + if (slot > -1) { + orderedKeys.insertElementAt(key, slot); + } else { + orderedKeys.addElement(key); } } - // Changed because this is exactly opposite of what we want.... - // Servlets were being loaded in the exact opposite order. - // Priorities IMO, should start with 0. - // Only System Servlets should be at 0 and rest of the servlets - // should be +ve integers. - // WARNING: Please do not change this without talking to: - // harishp@eng.sun.com (J2EE impact) - // for (int i = loadServlets.size() - 1; i >= 0; i--) { - - for(int i = 0; i < loadServlets.size(); ++i) { - String servletName = (String)loadServlets.elementAt(i); - LookupResult result = - container.lookupServletByName(servletName); + // loaded ordered servlets - try { - result.getWrapper().loadServlet(); - } catch (Exception ee) { - ee.printStackTrace(); - String msg = sm.getString("context.loadServlet.e", - servletName); + // Priorities IMO, should start with 0. + // Only System Servlets should be at 0 and rest of the + // servlets should be +ve integers. + // WARNING: Please do not change this without talking to: + // harishp@eng.sun.com (J2EE impact) + + for (int i = 0; i < orderedKeys.size(); i ++) { + Integer key = (Integer)orderedKeys.elementAt(i); + e = ((Vector)(loadableServlets.get(key))).elements(); - System.out.println(msg); + while (e.hasMoreElements()) { + String servletName = (String)e.nextElement(); + LookupResult result = + container.lookupServletByName(servletName); + + try { + result.getWrapper().loadServlet(); + } catch (Exception ee) { + String msg = sm.getString("context.loadServlet.e", + servletName); + + System.out.println(msg); + } } } } 1.5 +63 -16 jakarta-tomcat/src/share/org/apache/tomcat/core/DefaultServlet.java Index: DefaultServlet.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/DefaultServlet.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DefaultServlet.java 1999/11/01 20:50:46 1.4 +++ DefaultServlet.java 1999/11/03 20:38:52 1.5 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/DefaultServlet.java,v 1.4 1999/11/01 20:50:46 costin Exp $ - * $Revision: 1.4 $ - * $Date: 1999/11/01 20:50:46 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/DefaultServlet.java,v 1.5 1999/11/03 20:38:52 costin Exp $ + * $Revision: 1.5 $ + * $Date: 1999/11/03 20:38:52 $ * * ==================================================================== * @@ -64,6 +64,7 @@ package org.apache.tomcat.core; +import org.apache.tomcat.server.*; import org.apache.tomcat.util.*; import java.io.*; import java.net.*; @@ -282,12 +283,16 @@ while (enum.hasMoreElements()) { String fileName = (String)enum.nextElement(); - File f = new File(file, fileName); - if (f.exists()) { - welcomeFile = fileName; + if (fileName != null && + fileName.trim().length() > 0) { + File f = new File(file, fileName); - break; + if (f.exists()) { + welcomeFile = fileName; + + break; + } } } @@ -351,10 +356,32 @@ // return 404 instead of the JSP source // On all platforms, makes sure we don't let ../'s through // Unfortunately, on Unix, it prevents symlinks from working - if (! absPath.equals(canPath)) { - response.sendError(response.SC_NOT_FOUND); - - return; + // So, a check for File.separatorChar='\\' ..... It hopefully + // happens on flavors of Windows. + if (File.separatorChar == '\\') { + // On Windows check ignore case.... + if(!absPath.equalsIgnoreCase(canPath)) { + response.sendError(response.SC_NOT_FOUND); + return; + } + } else { + // The following code on Non Windows disallows ../ + // in the path but also disallows symlinks.... + // + // if(!absPath.equals(canPath)) { + // response.sendError(response.SC_NOT_FOUND); + // return; + // } + // instead lets look for ".." in the absolute path + // and disallow only that. + // Why should we loose out on symbolic links? + // + + if(absPath.indexOf("..") != -1) { + // We have .. in the path... + response.sendError(response.SC_NOT_FOUND); + return; + } } String mimeType = mimeTypes.getContentTypeFor(file.getName()); @@ -484,12 +511,32 @@ absPath = FilePathUtil.patch(absPath); - if (! absPath.equals(canPath)) { - response.sendError(response.SC_NOT_FOUND); - - return; + if (File.separatorChar == '\\') { + // On Windows check ignore case.... + if(!absPath.equalsIgnoreCase(canPath)) { + response.sendError(response.SC_NOT_FOUND); + return; + } + } else { + // The following code on Non Windows disallows ../ + // in the path but also disallows symlinks.... + // + // if(!absPath.equals(canPath)) { + // response.sendError(response.SC_NOT_FOUND); + // return; + // } + // instead lets look for ".." in the absolute path + // and disallow only that. + // Why should we loose out on symbolic links? + // + + if(absPath.indexOf("..") != -1) { + // We have .. in the path... + response.sendError(response.SC_NOT_FOUND); + return; + } } - + Vector dirs = new Vector(); Vector files = new Vector(); String[] fileNames = file.list(); 1.8 +12 -4 jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java Index: Request.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- Request.java 1999/11/02 17:37:19 1.7 +++ Request.java 1999/11/03 20:38:52 1.8 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v 1.7 1999/11/02 17:37:19 costin Exp $ - * $Revision: 1.7 $ - * $Date: 1999/11/02 17:37:19 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v 1.8 1999/11/03 20:38:52 costin Exp $ + * $Revision: 1.8 $ + * $Date: 1999/11/03 20:38:52 $ * * ==================================================================== * @@ -421,7 +421,8 @@ } public void setParameters( Hashtable h ) { - this.parameters=h; + if(h!=null) + this.parameters=h; // XXX Should we override query parameters ?? } @@ -453,6 +454,13 @@ */ public void setQueryString(String queryString) { this.queryString = queryString; + // catch any parse exceptions + + try { + this.parameters = HttpUtils.parseQueryString(queryString); + } catch (Exception e) { + this.parameters.clear(); + } } // public void setScheme(String scheme) { 1.2 +80 -42 jakarta-tomcat/src/share/org/apache/tomcat/core/RequestDispatcherImpl.java Index: RequestDispatcherImpl.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestDispatcherImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- RequestDispatcherImpl.java 1999/10/09 00:30:15 1.1 +++ RequestDispatcherImpl.java 1999/11/03 20:38:52 1.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestDispatcherImpl.java,v 1.1 1999/10/09 00:30:15 duncan Exp $ - * $Revision: 1.1 $ - * $Date: 1999/10/09 00:30:15 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestDispatcherImpl.java,v 1.2 1999/11/03 20:38:52 costin Exp $ + * $Revision: 1.2 $ + * $Date: 1999/11/03 20:38:52 $ * * ==================================================================== * @@ -90,34 +90,6 @@ RequestDispatcherImpl(Context context) { this.context = context; } - - void setName(String name) { - this.name = name; - this.lookupResult = - context.getContainer().lookupServletByName(this.name); - } - - void setPath(String urlPath) { - int i = urlPath.indexOf("?"); - - if (i > -1) { - try { - this.queryString = - urlPath.substring(i + 1, urlPath.length()); - } catch (Exception e) { - } - - urlPath = urlPath.substring(0, i); - } - - this.urlPath = urlPath; - this.lookupResult = - context.getContainer().lookupServlet(this.urlPath); - } - - public boolean isValid() { - return (this.lookupResult != null); - } public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException { @@ -125,13 +97,9 @@ (HttpServletRequestFacade)request; HttpServletResponseFacade resFacade = (HttpServletResponseFacade)response; + Request realRequest = reqFacade.getRealRequest(); + Response realResponse = resFacade.getRealResponse(); - Request realRequest = null; - Response realResponse = null; - - realRequest = reqFacade.getRealRequest(); - realResponse = resFacade.getRealResponse(); - if (realResponse.isStarted()) { String msg = sm.getString("rdi.forward.ise"); @@ -145,9 +113,23 @@ ForwardedRequest fRequest = new ForwardedRequest(realRequest, urlPath); + // join the query strings of the destination request + // with the originaing request in that order. + + String aggregatedQueryString = this.queryString; + + if (realRequest.getQueryString() != null && + realRequest.getQueryString().trim().length() > 0) { + if (aggregatedQueryString == null) { + aggregatedQueryString = realRequest.getQueryString(); + } else { + aggregatedQueryString += "&" + realRequest.getQueryString(); + } + } + fRequest.setServletPath(this.lookupResult.getServletPath()); fRequest.setPathInfo(this.lookupResult.getPathInfo()); - fRequest.setQueryString(queryString); + fRequest.setQueryString(aggregatedQueryString); this.lookupResult.getWrapper().handleRequest(fRequest, resFacade); } @@ -155,6 +137,10 @@ public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException { HttpServletRequest req = (HttpServletRequest)request; + + // XXX + // while this appears to work i believe the code + // could be streamlined/normalized a bit. // if we are in a chained include, then we'll store the attributes // from the last round so that we've got them for the next round @@ -166,14 +152,15 @@ String path_info = (String)req.getAttribute(Constants.Attribute.PathInfo); String query_string = - (String)req.getAttribute(Constants.Attribute.QueryString); + (String)req.getAttribute(Constants.Attribute.QueryString); HttpServletRequestFacade reqFacade = (HttpServletRequestFacade)request; HttpServletResponseFacade resFacade = (HttpServletResponseFacade)response; - Request realRequest = reqFacade.getRealRequest(); + Request realRequest = reqFacade.getRealRequest(); Response realResponse = resFacade.getRealResponse(); + String originalQueryString = realRequest.getQueryString(); // XXX // not sure why we're pre-pending context.getPath() here @@ -199,15 +186,38 @@ lookupResult.getPathInfo()); } - if (queryString != null) { + // join the query strings of the destination request + // with the originaing request in that order. + + String aggregatedQueryString = this.queryString; + + if (realRequest.getQueryString() != null && + realRequest.getQueryString().trim().length() > 0) { + if (aggregatedQueryString == null) { + aggregatedQueryString = realRequest.getQueryString(); + } else { + aggregatedQueryString += "&" + realRequest.getQueryString(); + } + } + + if (aggregatedQueryString != null) { req.setAttribute(Constants.Attribute.QueryString, - queryString); + aggregatedQueryString); } + + // inline the aggregated query string for the scope + // of the include + + reqFacade.getRealRequest().setQueryString(aggregatedQueryString); IncludedResponse iResponse = new IncludedResponse(realResponse); lookupResult.getWrapper().handleRequest(reqFacade, iResponse); + // revert the query string to its original value + + reqFacade.getRealRequest().setQueryString(originalQueryString); + if (request_uri != null) { req.setAttribute(Constants.Attribute.RequestURI, request_uri); } else { @@ -233,5 +243,33 @@ } else { reqFacade.removeAttribute(Constants.Attribute.QueryString); } + } + + void setName(String name) { + this.name = name; + this.lookupResult = + context.getContainer().lookupServletByName(this.name); + } + + void setPath(String urlPath) { + int i = urlPath.indexOf("?"); + + if (i > -1) { + try { + this.queryString = + urlPath.substring(i + 1, urlPath.length()); + } catch (Exception e) { + } + + urlPath = urlPath.substring(0, i); + } + + this.urlPath = urlPath; + this.lookupResult = + context.getContainer().lookupServlet(this.urlPath); + } + + boolean isValid() { + return (this.lookupResult != null); } } 1.3 +79 -30 jakarta-tomcat/src/share/org/apache/tomcat/core/RequestMapper.java Index: RequestMapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestMapper.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- RequestMapper.java 1999/10/12 07:17:47 1.2 +++ RequestMapper.java 1999/11/03 20:38:53 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestMapper.java,v 1.2 1999/10/12 07:17:47 gonzo Exp $ - * $Revision: 1.2 $ - * $Date: 1999/10/12 07:17:47 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestMapper.java,v 1.3 1999/11/03 20:38:53 costin Exp $ + * $Revision: 1.3 $ + * $Date: 1999/11/03 20:38:53 $ * * ==================================================================== * @@ -80,6 +80,7 @@ private String servletPath = null; private String mapPath = null; private String pathInfo = null; + private String resourceName = null; RequestMapper() { } @@ -101,9 +102,11 @@ ServletWrapper wrapper = getMatch(path); if (wrapper != null) { - lookupResult = new LookupResult(wrapper, - this.servletPath, this.mapPath, this.pathInfo); - } + this.mapPath = getMapPath(wrapper); + + lookupResult = new LookupResult(wrapper, + this.servletPath, this.mapPath, this.pathInfo); + } return lookupResult; } @@ -130,31 +133,8 @@ // lookup real servlet if what we're actually // dealing with a jsp file - if (wrapper != null) { - String servletPath = this.servletPath; - String pathInfo = this.pathInfo; - boolean stillSearching = true; - int counter = 0; - - while (stillSearching) { - if (wrapper.getPath() != null && - wrapper.getServletClass() == null) { - wrapper = getMatch(wrapper.getPath() + pathInfo); - this.mapPath = this.servletPath; - - if (stillSearching && - ++counter > Constants.RequestURIMatchRecursion) { - stillSearching = false; - } - } else { - stillSearching = false; - } - } + wrapper = getResolvedServlet(wrapper); - this.servletPath = servletPath; - this.pathInfo = pathInfo; - } - return wrapper; } @@ -245,5 +225,74 @@ } return wrapper; + } + + private ServletWrapper getResolvedServlet(ServletWrapper wrapper) { + if (wrapper != null) { + String servletPath = this.servletPath; + String pathInfo = this.pathInfo; + boolean stillSearching = true; + int counter = 0; + + this.resourceName = this.servletPath; + + while (stillSearching) { + if (wrapper.getPath() != null && + wrapper.getServletClass() == null) { + this.resourceName = wrapper.getPath(); + wrapper = getMatch(wrapper.getPath() + + (pathInfo == null ? "" : pathInfo)); + this.mapPath = this.servletPath; + + if (stillSearching && + ++counter > Constants.RequestURIMatchRecursion) { + stillSearching = false; + } + } else { + stillSearching = false; + } + } + + this.servletPath = servletPath; + this.pathInfo = pathInfo; + } + + return wrapper; + } + + private String getMapPath(ServletWrapper wrapper) { + String mapPath = this.mapPath; + + // XXX + // this is added to make available the destination + // resource be it a servlet or jsp file - could be + // cleaned up a bit (wobbly) + if (this.servletPath.equals(Constants.Servlet.Invoker.Map) && + this.pathInfo != null) { + String s = this.pathInfo; + + if (this.pathInfo.startsWith("/")) { + s = this.pathInfo.substring(1); + } + + int i = s.indexOf("/"); + + if (i > -1) { + s = s.substring(0, i); + } + + mapPath = "/" + s; + } else if (mapPath == null && + this.resourceName != null) { + // XXX + // hack to differentiate amongst a mapped servlet and a jsp + if (! wrapper.getServletName().equals(Constants.JSP.NAME)) { + mapPath = "/" + wrapper.getServletClass(); + } else { + mapPath = this.resourceName; + } + } + + return mapPath; } } 1.3 +4 -4 jakarta-tomcat/src/share/org/apache/tomcat/core/ServletContextFacade.java Index: ServletContextFacade.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletContextFacade.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ServletContextFacade.java 1999/10/15 00:34:30 1.2 +++ ServletContextFacade.java 1999/11/03 20:38:53 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletContextFacade.java,v 1.2 1999/10/15 00:34:30 akv Exp $ - * $Revision: 1.2 $ - * $Date: 1999/10/15 00:34:30 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletContextFacade.java,v 1.3 1999/11/03 20:38:53 costin Exp $ + * $Revision: 1.3 $ + * $Date: 1999/11/03 20:38:53 $ * * ==================================================================== * @@ -338,7 +338,7 @@ // Can't get this anymore - Harish. A stop-gap arrangement. // context.getLogModule().log(msg); - System.err.println(msg); + // System.err.println(msg); } public String getInitParameter(String name) { 1.3 +57 -24 jakarta-tomcat/src/share/org/apache/tomcat/core/ServletLoader.java Index: ServletLoader.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletLoader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ServletLoader.java 1999/10/15 03:20:26 1.2 +++ ServletLoader.java 1999/11/03 20:38:54 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletLoader.java,v 1.2 1999/10/15 03:20:26 harishp Exp $ - * $Revision: 1.2 $ - * $Date: 1999/10/15 03:20:26 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletLoader.java,v 1.3 1999/11/03 20:38:54 costin Exp $ + * $Revision: 1.3 $ + * $Date: 1999/11/03 20:38:54 $ * * ==================================================================== * @@ -222,7 +222,7 @@ Class clazz = null; try { - ClassLoader parent = container.getClassLoader(); + ClassLoader parent = container.getContext().getClassLoader(); if (parent != null) { clazz = parent.loadClass(name); @@ -361,7 +361,8 @@ if (f.exists() && f.isDirectory()) { - String[] jars = getJarFiles(f); + JarFinder jarFinder = new JarFinder(); + String[] jars = jarFinder.getJars(f); for (int i = 0; i < jars.length; i++) { String s = f.toString() + File.separator + jars[i]; @@ -369,11 +370,12 @@ try { URL tURL = new URL(Constants.Request.FILE, null, s); - URL jURL = new URL(Constants.Request.WAR + - ":" + tURL); + URL jURL = new URL(Constants.Request.JAR + + ":" + tURL + "!/" + entryName); - u = resolveURL(jURL, null, entryName); + u = jURL; } catch (MalformedURLException mue) { + mue.printStackTrace(); u = null; } @@ -406,7 +408,8 @@ if (f.exists() && f.isDirectory()) { - String[] jars = getJarFiles(f); + JarFinder jarFinder = new JarFinder(); + String[] jars = jarFinder.getJars(f); for (int i = 0; i < jars.length; i++) { String s = f.toString() + File.separator + @@ -457,8 +460,8 @@ s += ((! s.endsWith("/")) ? "/" : "") + name.trim(); } - if (base.getProtocol().equalsIgnoreCase(Constants.Request.WAR)) { - u = new URL(base.toString() + + if (base.getProtocol().equalsIgnoreCase(Constants.Request.JAR)) { + u = new URL(base.toString() + ((s.length() > 0) ? "!" : "") + s); } else { u = new URL(base.toString() + @@ -484,12 +487,6 @@ return baos.toByteArray(); } - private String[] getJarFiles(File f) { - FilenameFilter filter = new JarFilter("jar"); - - return f.list(filter); - } - private String classPathFormat(Enumeration e) { String cp = ""; @@ -508,16 +505,52 @@ return cp; } } + +class JarFinder { + private Vector jars = null; -class JarFilter implements FilenameFilter { - String extension = ""; + String[] getJars(String dir) { + File f = new File(dir); + + return getJars(f, null); + } + + String[] getJars(String dir, String path) { + File f = new File(dir); + + return getJars(f, path); + } - JarFilter(String extension) { - this.extension = extension; + String[] getJars(File dir) { + return getJars(dir, null); } + + private String[] getJars(File dir, String path) { + File[] files = dir.listFiles(); + + for (int i = 0; i < files.length; i++) { + File file = files[i]; + String p = (path != null) ? path + File.separator : ""; + + if (file.canRead()) { + if (file.isFile() && + file.getName().toLowerCase().endsWith( + "." + "jar")) { + if (this.jars == null) { + this.jars = new Vector(); + } + + this.jars.addElement(p + file.getName()); + } else if (file.isDirectory()) { + getJars(file, p + file.getName()); + } + } + } + + String[] jars = new String[this.jars.size()]; + + this.jars.copyInto((Object[])jars); - public boolean accept(File dir, String name) { - return (name != null && - name.endsWith("." + this.extension)); + return jars; } }