craigmcc 00/11/24 16:57:25 Modified: catalina/src/share/org/apache/catalina/core LocalStrings.properties StandardContext.java StandardWrapper.java catalina/src/share/org/apache/catalina/deploy ErrorPage.java LoginConfig.java Log: Improve backwards compatibility of servlet 2.2 applications running under Catalina, by conditionally accepting context-relative pathnames that do not start with "/". To enable this acceptance, you must explicitly reference the public identifier of the 2.2 DTD in your web.xml file: <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> (in other words, the standard DOCTYPE declaration for a 2.2 webapp). The paths without leading slashes are accepted on the following web.xml elements: * <jsp-file> subelement of the <servlet> element. * <location> subelement of the <error-page> element. * <form-login-page> and <form-error-page> subelements of the <form-login-config> element. To encourage attention to this issue, a warning message will be logged to the Logger associated with this Context, if such a value is accepted. If you specify the 2.3 version of the DTD, attempts to specify such a path without a leading "/" will be rejected. This is based on the tightened requirements that are specifically defined in the 2.3 specification. Revision Changes Path 1.19 +10 -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.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- LocalStrings.properties 2000/11/02 06:14:09 1.18 +++ LocalStrings.properties 2000/11/25 00:57:24 1.19 @@ -25,6 +25,9 @@ standardContext.alreadyStarted=Context has already been started standardContext.applicationListener=Error configuring application listener of class {0} standardContext.applicationSkipped=Skipped installing application listeners due to previous error(s) +standardContext.errorPage.error=Error page location {0} must start with a '/' +standardContext.errorPage.required=ErrorPage cannot be null +standardContext.errorPage.warning=WARNING: Error page location {0} must start with a '/' in Servlet 2.3 standardContext.filterMap.either=Filter mapping must specify either a <url-pattern> or a <servlet-name> standardContext.filterMap.name=Filter mapping specifies an unknown filter name {0} standardContext.filterMap.pattern=Invalid <url-pattern> {0} in filter mapping @@ -32,6 +35,11 @@ standardContext.isUnavailable=This application is not currently available standardContext.listenerStart=Exception sending context initialized event to listener instance of class {0} standardContext.listenerStop=Exception sending context destroyed event to listener instance of class {0} +standardContext.loginConfig.errorPage=Form error page {0} must start with a '/' +standardContext.loginConfig.errorWarning=WARNING: Form error page {0} must start with a '/' in Servlet 2.3 +standardContext.loginConfig.loginPage=Form login page {0} must start with a '/' +standardContext.loginConfig.loginWarning=WARNING: Form login page {0} must start with a '/' in Servlet 2.3 +standardContext.loginConfig.required=LoginConfig cannot be null standardContext.managerLoad=Exception loading sessions from persistent storage standardContext.managerUnload=Exception unloading sessions to persistent storage standardContext.mappingError=MAPPING configuration error for relative URI {0} @@ -51,6 +59,8 @@ standardContext.stoppingLoader=Exception stopping Loader standardContext.stoppingManager=Exception stopping Manager standardContext.stoppingWrapper=Exception stopping Wrapper for servlet {0} +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 standardContext.invalidEnvEntryType={0} environment entry has an invalid type standardContext.bindFailed=Bind naming operation failed : {0} 1.30 +91 -12 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.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- StandardContext.java 2000/11/24 22:36:23 1.29 +++ StandardContext.java 2000/11/25 00:57:24 1.30 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.29 2000/11/24 22:36:23 craigmcc Exp $ - * $Revision: 1.29 $ - * $Date: 2000/11/24 22:36:23 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.30 2000/11/25 00:57:24 craigmcc Exp $ + * $Revision: 1.30 $ + * $Date: 2000/11/25 00:57:24 $ * * ==================================================================== * @@ -131,7 +131,7 @@ * * @author Craig R. McClanahan * @author Remy Maucherat - * @version $Revision: 1.29 $ $Date: 2000/11/24 22:36:23 $ + * @version $Revision: 1.30 $ $Date: 2000/11/25 00:57:24 $ */ public final class StandardContext @@ -681,23 +681,23 @@ /** - * Return the login configuration descriptor for this web application. + * Set the Loader with which this Context is associated. + * + * @param loader The newly associated loader */ - public LoginConfig getLoginConfig() { + public synchronized void setLoader(Loader loader) { - return (this.loginConfig); + super.setLoader(loader); } /** - * Set the Loader with which this Context is associated. - * - * @param loader The newly associated loader + * Return the login configuration descriptor for this web application. */ - public synchronized void setLoader(Loader loader) { + public LoginConfig getLoginConfig() { - super.setLoader(loader); + return (this.loginConfig); } @@ -709,6 +709,36 @@ */ public void setLoginConfig(LoginConfig config) { + // Validate the incoming property value + if (config == null) + throw new IllegalArgumentException + (sm.getString("standardContext.loginConfig.required")); + String loginPage = config.getLoginPage(); + if ((loginPage != null) && !loginPage.startsWith("/")) { + if (isServlet22()) { + log(sm.getString("standardContext.loginConfig.loginWarning", + loginPage)); + config.setLoginPage("/" + loginPage); + } else { + throw new IllegalArgumentException + (sm.getString("standardContext.loginConfig.loginPage", + loginPage)); + } + } + String errorPage = config.getErrorPage(); + if ((errorPage != null) && !errorPage.startsWith("/")) { + if (isServlet22()) { + log(sm.getString("standardContext.loginConfig.errorWarning", + errorPage)); + config.setErrorPage("/" + errorPage); + } else { + throw new IllegalArgumentException + (sm.getString("standardContext.loginConfig.errorPage", + errorPage)); + } + } + + // Process the property setting change LoginConfig oldLoginConfig = this.loginConfig; this.loginConfig = config; support.firePropertyChange("loginConfig", @@ -761,6 +791,10 @@ */ public void setPublicId(String publicId) { + if (debug >= 1) + log("Setting deployment descriptor public ID to '" + + publicId + "'"); + String oldPublicId = this.publicId; this.publicId = publicId; support.firePropertyChange("publicId", oldPublicId, publicId); @@ -971,6 +1005,17 @@ if (!(child instanceof Wrapper)) throw new IllegalArgumentException (sm.getString("standardContext.notWrapper")); + Wrapper wrapper = (Wrapper) child; + String jspFile = wrapper.getJspFile(); + if ((jspFile != null) && !jspFile.startsWith("/")) { + if (isServlet22()) { + log(sm.getString("standardContext.wrapper.warning", jspFile)); + wrapper.setJspFile("/" + jspFile); + } else { + throw new IllegalArgumentException + (sm.getString("standardContext.wrapper.error", jspFile)); + } + } super.addChild(child); } @@ -1045,6 +1090,24 @@ */ public void addErrorPage(ErrorPage errorPage) { + // Validate the input parameters + if (errorPage == null) + throw new IllegalArgumentException + (sm.getString("standardContext.errorPage.required")); + String location = errorPage.getLocation(); + if ((location != null) && !location.startsWith("/")) { + if (isServlet22()) { + log(sm.getString("standardContext.errorPage.warning", + location)); + errorPage.setLocation("/" + location); + } else { + throw new IllegalArgumentException + (sm.getString("standardContext.errorPage.error", + location)); + } + } + + // Add the specified error page to our internal collections String exceptionType = errorPage.getExceptionType(); if (exceptionType != null) { synchronized (exceptionPages) { @@ -2967,6 +3030,22 @@ protected void addDefaultMapper(String mapperClass) { super.addDefaultMapper(this.mapperClass); + + } + + + /** + * Are we processing a version 2.2 deployment descriptor? + */ + protected boolean isServlet22() { + + if (this.publicId == null) + return (false); + if (this.publicId.equals + (org.apache.catalina.startup.Constants.WebDtdPublicId_22)) + return (true); + else + return (false); } 1.11 +7 -7 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java Index: StandardWrapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- StandardWrapper.java 2000/10/13 05:58:52 1.10 +++ StandardWrapper.java 2000/11/25 00:57:24 1.11 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v 1.10 2000/10/13 05:58:52 craigmcc Exp $ - * $Revision: 1.10 $ - * $Date: 2000/10/13 05:58:52 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v 1.11 2000/11/25 00:57:24 craigmcc Exp $ + * $Revision: 1.11 $ + * $Date: 2000/11/25 00:57:24 $ * * ==================================================================== * @@ -101,7 +101,7 @@ * make them efficient are counter-productive. * * @author Craig R. McClanahan - * @version $Revision: 1.10 $ $Date: 2000/10/13 05:58:52 $ + * @version $Revision: 1.11 $ $Date: 2000/11/25 00:57:24 $ */ public final class StandardWrapper @@ -307,9 +307,9 @@ */ public void setJspFile(String jspFile) { - if ((jspFile != null) && !jspFile.startsWith("/")) - throw new IllegalArgumentException - (sm.getString("standardWrapper.jspFile.format", jspFile)); + // if ((jspFile != null) && !jspFile.startsWith("/")) + // throw new IllegalArgumentException + // (sm.getString("standardWrapper.jspFile.format", jspFile)); String oldJspFile = this.jspFile; this.jspFile = jspFile; 1.3 +7 -7 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/deploy/ErrorPage.java Index: ErrorPage.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/deploy/ErrorPage.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ErrorPage.java 2000/10/07 20:08:43 1.2 +++ ErrorPage.java 2000/11/25 00:57:25 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/deploy/ErrorPage.java,v 1.2 2000/10/07 20:08:43 craigmcc Exp $ - * $Revision: 1.2 $ - * $Date: 2000/10/07 20:08:43 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/deploy/ErrorPage.java,v 1.3 2000/11/25 00:57:25 craigmcc Exp $ + * $Revision: 1.3 $ + * $Date: 2000/11/25 00:57:25 $ * * ==================================================================== * @@ -74,7 +74,7 @@ * deployment descriptor. * * @author Craig R. McClanahan - * @version $Revision: 1.2 $ $Date: 2000/10/07 20:08:43 $ + * @version $Revision: 1.3 $ $Date: 2000/11/25 00:57:25 $ */ public final class ErrorPage { @@ -181,9 +181,9 @@ */ public void setLocation(String location) { - if ((location == null) || !location.startsWith("/")) - throw new IllegalArgumentException - ("Error Page Location must start with a '/'"); + // if ((location == null) || !location.startsWith("/")) + // throw new IllegalArgumentException + // ("Error Page Location must start with a '/'"); this.location = RequestUtil.URLDecode(location); } 1.4 +10 -10 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/deploy/LoginConfig.java Index: LoginConfig.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/deploy/LoginConfig.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- LoginConfig.java 2000/10/07 20:08:43 1.3 +++ LoginConfig.java 2000/11/25 00:57:25 1.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/deploy/LoginConfig.java,v 1.3 2000/10/07 20:08:43 craigmcc Exp $ - * $Revision: 1.3 $ - * $Date: 2000/10/07 20:08:43 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/deploy/LoginConfig.java,v 1.4 2000/11/25 00:57:25 craigmcc Exp $ + * $Revision: 1.4 $ + * $Date: 2000/11/25 00:57:25 $ * * ==================================================================== * @@ -74,7 +74,7 @@ * deployment descriptor. * * @author Craig R. McClanahan - * @version $Revision: 1.3 $ $Date: 2000/10/07 20:08:43 $ + * @version $Revision: 1.4 $ $Date: 2000/11/25 00:57:25 $ */ public final class LoginConfig { @@ -108,9 +108,9 @@ } public void setErrorPage(String errorPage) { - if ((errorPage == null) || !errorPage.startsWith("/")) - throw new IllegalArgumentException - ("Error Page resource path must start with a '/'"); + // if ((errorPage == null) || !errorPage.startsWith("/")) + // throw new IllegalArgumentException + // ("Error Page resource path must start with a '/'"); this.errorPage = RequestUtil.URLDecode(errorPage); } @@ -125,9 +125,9 @@ } public void setLoginPage(String loginPage) { - if ((loginPage == null) || !loginPage.startsWith("/")) - throw new IllegalArgumentException - ("Login Page resource path must start with a '/'"); + // if ((loginPage == null) || !loginPage.startsWith("/")) + // throw new IllegalArgumentException + // ("Login Page resource path must start with a '/'"); this.loginPage = RequestUtil.URLDecode(loginPage); }