craigmcc 00/12/23 11:00:34 Modified: catalina/src/share/org/apache/catalina/core LocalStrings.properties StandardContext.java Log: Add a backwards compatibility hack to the way that web application deployment descriptors are parsed. Tomcat 3.x accepted <url-pattern> arguments (inside a <servlet-mapping> or a <security-constraint>) that did not conform to the syntax requirements of the Servlet 2.2 specification, because it would explicitly add a leading slash if it was omitted. Now, Tomcat 4.0 will accept such a pattern, with a warning message to the log, *only* on applications that declare themselves to use the Servlet 2.2 DTD. For a 2.3 web app, Tomcat 4.0 enforces the syntax rules on <url-pattern> arguments, which are spelled out explicitly in the spec. Revision Changes Path 1.22 +1 -0 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/LocalStrings.properties Index: LocalStrings.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/LocalStrings.properties,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- LocalStrings.properties 2000/12/14 02:56:14 1.21 +++ LocalStrings.properties 2000/12/23 19:00:31 1.22 @@ -60,6 +60,7 @@ standardContext.stoppingLoader=Exception stopping Loader standardContext.stoppingManager=Exception stopping Manager standardContext.stoppingWrapper=Exception stopping Wrapper for servlet {0} +standardContext.urlPattern.patternWarning=WARNING: URL pattern {0} must start with a '/' in Servlet 2.3 standardContext.wrapper.error=JSP file {0} must start with a '/' standardContext.wrapper.warning=WARNING: JSP file {0} must start with a '/' in Servlet 2.3 standardContext.invalidEnvEntryValue={0} environment entry has an invalid value for specified type 1.33 +31 -5 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java Index: StandardContext.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- StandardContext.java 2000/12/08 07:17:52 1.32 +++ StandardContext.java 2000/12/23 19:00:32 1.33 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.32 2000/12/08 07:17:52 pier Exp $ - * $Revision: 1.32 $ - * $Date: 2000/12/08 07:17:52 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.33 2000/12/23 19:00:32 craigmcc Exp $ + * $Revision: 1.33 $ + * $Date: 2000/12/23 19:00:32 $ * * ==================================================================== * @@ -133,7 +133,7 @@ * * @author Craig R. McClanahan * @author Remy Maucherat - * @version $Revision: 1.32 $ $Date: 2000/12/08 07:17:52 $ + * @version $Revision: 1.33 $ $Date: 2000/12/23 19:00:32 $ */ public class StandardContext @@ -1039,6 +1039,7 @@ for (int i = 0; i < collections.length; i++) { String patterns[] = collections[i].findPatterns(); for (int j = 0; j < patterns.length; j++) { + patterns[j] = adjustURLPattern(patterns[j]); if (!validateURLPattern(patterns[j])) throw new IllegalArgumentException (sm.getString @@ -1187,6 +1188,8 @@ if ((servletName != null) && (urlPattern != null)) throw new IllegalArgumentException (sm.getString("standardContext.filterMap.either")); + // Because filter-pattern is new in 2.3, no need to adjust + // for 2.2 backwards compatibility if ((urlPattern != null) && !validateURLPattern(urlPattern)) throw new IllegalArgumentException (sm.getString("standardContext.filterMap.pattern", @@ -1353,7 +1356,7 @@ if (findChild(name) == null) throw new IllegalArgumentException (sm.getString("standardContext.servletMap.name", name)); - pattern = RequestUtil.URLDecode(pattern); + pattern = adjustURLPattern(RequestUtil.URLDecode(pattern)); if (!validateURLPattern(pattern)) throw new IllegalArgumentException (sm.getString("standardContext.servletMap.pattern", pattern)); @@ -3054,6 +3057,29 @@ protected void addDefaultMapper(String mapperClass) { super.addDefaultMapper(this.mapperClass); + + } + + + /** + * Adjust the URL pattern to begin with a leading slash, if appropriate + * (i.e. we are running a servlet 2.2 application). Otherwise, return + * the specified URL pattern unchanged. + * + * @param urlPattern The URL pattern to be adjusted (if needed) + * and returned + */ + protected String adjustURLPattern(String urlPattern) { + + if (urlPattern == null) + return (urlPattern); + if (urlPattern.startsWith("/") || urlPattern.startsWith("*.")) + return (urlPattern); + if (!isServlet22()) + return (urlPattern); + log(sm.getString("standardContext.urlPattern.patternWarning", + urlPattern)); + return ("/" + urlPattern); }