This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push: new 761e67e Remove three system properties used for configuration 761e67e is described below commit 761e67e9faba1a4c85b3b1b80313cfe5b5889084 Author: remm <r...@apache.org> AuthorDate: Thu Mar 26 16:45:14 2020 +0100 Remove three system properties used for configuration Three rarely used properties that are associated with the Context: - org.apache.catalina.core.StandardHostValve.ACCESS_SESSION is replaced by the Context.alwaysAccessSession attribute - org.apache.catalina.core.ApplicationContext.GET_RESOURCE_REQUIRE_SLASH is replaced by the Context.contextGetResourceRequiresSlash attribute - org.apache.catalina.core.ApplicationDispatcher.WRAP_SAME_OBJECT is replaced by the Context.dispatcherWrapsSameObject attribute --- java/org/apache/catalina/Context.java | 65 ++++++++++++++++++++++ .../apache/catalina/core/ApplicationContext.java | 18 +----- .../catalina/core/ApplicationDispatcher.java | 22 +------- .../catalina/core/ApplicationFilterChain.java | 28 +++++----- .../catalina/core/ApplicationFilterFactory.java | 1 + java/org/apache/catalina/core/StandardContext.java | 43 ++++++++++++++ .../apache/catalina/core/StandardHostValve.java | 18 +----- .../org/apache/catalina/startup/FailedContext.java | 16 ++++++ test/org/apache/tomcat/unittest/TesterContext.java | 16 ++++++ webapps/docs/changelog.xml | 18 ++++++ webapps/docs/config/context.xml | 30 ++++++++++ webapps/docs/config/systemprops.xml | 36 +----------- 12 files changed, 211 insertions(+), 100 deletions(-) diff --git a/java/org/apache/catalina/Context.java b/java/org/apache/catalina/Context.java index 6edaf1e..b8f55a0 100644 --- a/java/org/apache/catalina/Context.java +++ b/java/org/apache/catalina/Context.java @@ -86,6 +86,7 @@ public interface Context extends Container, ContextBind { // ------------------------------------------------------------- Properties + /** * Returns <code>true</code> if requests mapped to servlets without * "multipart config" to parse multipart/form-data requests anyway. @@ -1867,4 +1868,68 @@ public interface Context extends Container, ContextBind { * otherwise {@code false} */ public boolean getCreateUploadTargets(); + + + /** + * If this is <code>true</code>, every request that is associated with a + * session will cause the session's last accessed time to be updated + * regardless of whether or not the request explicitly accesses the session. + * If <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code> is set to + * <code>true</code>, the default of this setting will be <code>true</code>, + * else the default value will be <code>false</code>. + * @return the flag value + */ + public boolean getAlwaysAccessSession(); + + + /** + * Set the session access behavior. + * @param alwaysAccessSession the new flag value + */ + public void setAlwaysAccessSession(boolean alwaysAccessSession); + + + /** + * If this is <code>true</code> then the path passed to + * <code>ServletContext.getResource()</code> or + * <code>ServletContext.getResourceAsStream()</code> must start with + * "/". If <code>false</code>, code like + * <code>getResource("myfolder/myresource.txt")</code> will work as Tomcat + * will prepend "/" to the provided path. + * If <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code> is set to + * <code>true</code>, the default of this setting will be <code>true</code>, + * else the default value will be <code>false</code>. + * @return the flag value + */ + public boolean getContextGetResourceRequiresSlash(); + + + /** + * Allow using <code>ServletContext.getResource()</code> or + * <code>ServletContext.getResourceAsStream()</code> without + * a leading "/". + * @param contextGetResourceRequiresSlash the new flag value + */ + public void setContextGetResourceRequiresSlash(boolean contextGetResourceRequiresSlash); + + + /** + * If this is <code>true</code> then any wrapped request or response + * object passed to an application dispatcher will be checked to ensure that + * it has wrapped the original request or response. + * If <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code> is set to + * <code>true</code>, the default of this setting will be <code>true</code>, + * else the default value will be <code>false</code>. + * @return the flag value + */ + public boolean getDispatcherWrapsSameObject(); + + + /** + * Allow disabling the object wrap check in the request dispatcher. + * @param dispatcherWrapsSameObject the new flag value + */ + public void setDispatcherWrapsSameObject(boolean dispatcherWrapsSameObject); + + } diff --git a/java/org/apache/catalina/core/ApplicationContext.java b/java/org/apache/catalina/core/ApplicationContext.java index 3de49c2..358cce3 100644 --- a/java/org/apache/catalina/core/ApplicationContext.java +++ b/java/org/apache/catalina/core/ApplicationContext.java @@ -90,22 +90,6 @@ import org.apache.tomcat.util.res.StringManager; */ public class ApplicationContext implements ServletContext { - protected static final boolean STRICT_SERVLET_COMPLIANCE; - - protected static final boolean GET_RESOURCE_REQUIRE_SLASH; - - - static { - STRICT_SERVLET_COMPLIANCE = Globals.STRICT_SERVLET_COMPLIANCE; - - String requireSlash = System.getProperty( - "org.apache.catalina.core.ApplicationContext.GET_RESOURCE_REQUIRE_SLASH"); - if (requireSlash == null) { - GET_RESOURCE_REQUIRE_SLASH = STRICT_SERVLET_COMPLIANCE; - } else { - GET_RESOURCE_REQUIRE_SLASH = Boolean.parseBoolean(requireSlash); - } - } // ----------------------------------------------------------- Constructors @@ -575,7 +559,7 @@ public class ApplicationContext implements ServletContext { } if (!path.startsWith("/")) { - if (GET_RESOURCE_REQUIRE_SLASH) { + if (context.getContextGetResourceRequiresSlash()) { return null; } else { return "/" + path; diff --git a/java/org/apache/catalina/core/ApplicationDispatcher.java b/java/org/apache/catalina/core/ApplicationDispatcher.java index 6f48831..7f267e6 100644 --- a/java/org/apache/catalina/core/ApplicationDispatcher.java +++ b/java/org/apache/catalina/core/ApplicationDispatcher.java @@ -63,24 +63,6 @@ import org.apache.tomcat.util.res.StringManager; */ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher { - static final boolean STRICT_SERVLET_COMPLIANCE; - - static final boolean WRAP_SAME_OBJECT; - - - static { - STRICT_SERVLET_COMPLIANCE = Globals.STRICT_SERVLET_COMPLIANCE; - - String wrapSameObject = System.getProperty( - "org.apache.catalina.core.ApplicationDispatcher.WRAP_SAME_OBJECT"); - if (wrapSameObject == null) { - WRAP_SAME_OBJECT = STRICT_SERVLET_COMPLIANCE; - } else { - WRAP_SAME_OBJECT = Boolean.parseBoolean(wrapSameObject); - } - } - - protected class PrivilegedForward implements PrivilegedExceptionAction<Void> { private final ServletRequest request; @@ -331,7 +313,7 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher // Set up to handle the specified request and response State state = new State(request, response, false); - if (WRAP_SAME_OBJECT) { + if (context.getDispatcherWrapsSameObject()) { // Check SRV.8.2 / SRV.14.2.5.1 compliance checkSameObjects(request, response); } @@ -523,7 +505,7 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher // Set up to handle the specified request and response State state = new State(request, response, true); - if (WRAP_SAME_OBJECT) { + if (context.getDispatcherWrapsSameObject()) { // Check SRV.8.2 / SRV.14.2.5.1 compliance checkSameObjects(request, response); } diff --git a/java/org/apache/catalina/core/ApplicationFilterChain.java b/java/org/apache/catalina/core/ApplicationFilterChain.java index e9bec91..f4c00e2 100644 --- a/java/org/apache/catalina/core/ApplicationFilterChain.java +++ b/java/org/apache/catalina/core/ApplicationFilterChain.java @@ -47,18 +47,9 @@ import org.apache.tomcat.util.res.StringManager; public final class ApplicationFilterChain implements FilterChain { // Used to enforce requirements of SRV.8.2 / SRV.14.2.5.1 - private static final ThreadLocal<ServletRequest> lastServicedRequest; - private static final ThreadLocal<ServletResponse> lastServicedResponse; + private static final ThreadLocal<ServletRequest> lastServicedRequest = new ThreadLocal<>(); + private static final ThreadLocal<ServletResponse> lastServicedResponse = new ThreadLocal<>(); - static { - if (ApplicationDispatcher.WRAP_SAME_OBJECT) { - lastServicedRequest = new ThreadLocal<>(); - lastServicedResponse = new ThreadLocal<>(); - } else { - lastServicedRequest = null; - lastServicedResponse = null; - } - } // -------------------------------------------------------------- Constants @@ -99,6 +90,11 @@ public final class ApplicationFilterChain implements FilterChain { private boolean servletSupportsAsync = false; /** + * Check the proper Servlet objects have been used. + */ + private boolean dispatcherWrapsSameObject = false; + + /** * The string manager for our package. */ private static final StringManager sm = @@ -204,7 +200,7 @@ public final class ApplicationFilterChain implements FilterChain { // We fell off the end of the chain -- call the servlet instance try { - if (ApplicationDispatcher.WRAP_SAME_OBJECT) { + if (dispatcherWrapsSameObject) { lastServicedRequest.set(request); lastServicedResponse.set(response); } @@ -237,7 +233,7 @@ public final class ApplicationFilterChain implements FilterChain { ExceptionUtils.handleThrowable(e); throw new ServletException(sm.getString("filterChain.servlet"), e); } finally { - if (ApplicationDispatcher.WRAP_SAME_OBJECT) { + if (dispatcherWrapsSameObject) { lastServicedRequest.set(null); lastServicedResponse.set(null); } @@ -303,6 +299,7 @@ public final class ApplicationFilterChain implements FilterChain { pos = 0; servlet = null; servletSupportsAsync = false; + dispatcherWrapsSameObject = false; } @@ -329,6 +326,11 @@ public final class ApplicationFilterChain implements FilterChain { } + void setDispatcherWrapsSameObject(boolean dispatcherWrapsSameObject) { + this.dispatcherWrapsSameObject = dispatcherWrapsSameObject; + } + + /** * Identifies the Filters, if any, in this FilterChain that do not support * async. diff --git a/java/org/apache/catalina/core/ApplicationFilterFactory.java b/java/org/apache/catalina/core/ApplicationFilterFactory.java index c74fdeb..0cdae4a 100644 --- a/java/org/apache/catalina/core/ApplicationFilterFactory.java +++ b/java/org/apache/catalina/core/ApplicationFilterFactory.java @@ -81,6 +81,7 @@ public final class ApplicationFilterFactory { // Acquire the filter mappings for this Context StandardContext context = (StandardContext) wrapper.getParent(); + filterChain.setDispatcherWrapsSameObject(context.getDispatcherWrapsSameObject()); FilterMap filterMaps[] = context.findFilterMaps(); // If there are no filter mappings, we are done diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index 0617ba5..9b6c3b2 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -827,6 +827,11 @@ public class StandardContext extends ContainerBase private boolean createUploadTargets = false; + private boolean alwaysAccessSession = Globals.STRICT_SERVLET_COMPLIANCE; + + private boolean contextGetResourceRequiresSlash = Globals.STRICT_SERVLET_COMPLIANCE; + + private boolean dispatcherWrapsSameObject = Globals.STRICT_SERVLET_COMPLIANCE; // ----------------------------------------------------- Context Properties @@ -873,6 +878,44 @@ public class StandardContext extends ContainerBase @Override + public boolean getAlwaysAccessSession() { + return alwaysAccessSession; + } + + + @Override + public void setAlwaysAccessSession(boolean alwaysAccessSession) { + this.alwaysAccessSession = alwaysAccessSession; + } + + + @Override + public boolean getContextGetResourceRequiresSlash() { + return contextGetResourceRequiresSlash; + } + + + @Override + public void setContextGetResourceRequiresSlash( + boolean contextGetResourceRequiresSlash) { + this.contextGetResourceRequiresSlash = contextGetResourceRequiresSlash; + } + + + @Override + public boolean getDispatcherWrapsSameObject() { + return dispatcherWrapsSameObject; + } + + + @Override + public void setDispatcherWrapsSameObject( + boolean dispatcherWrapsSameObject) { + this.dispatcherWrapsSameObject = dispatcherWrapsSameObject; + } + + + @Override public String getRequestCharacterEncoding() { return requestEncoding; } diff --git a/java/org/apache/catalina/core/StandardHostValve.java b/java/org/apache/catalina/core/StandardHostValve.java index 43f5780..3be0026 100644 --- a/java/org/apache/catalina/core/StandardHostValve.java +++ b/java/org/apache/catalina/core/StandardHostValve.java @@ -59,22 +59,6 @@ final class StandardHostValve extends ValveBase { private static final ClassLoader MY_CLASSLOADER = StandardHostValve.class.getClassLoader(); - static final boolean STRICT_SERVLET_COMPLIANCE; - - static final boolean ACCESS_SESSION; - - static { - STRICT_SERVLET_COMPLIANCE = Globals.STRICT_SERVLET_COMPLIANCE; - - String accessSession = System.getProperty( - "org.apache.catalina.core.StandardHostValve.ACCESS_SESSION"); - if (accessSession == null) { - ACCESS_SESSION = STRICT_SERVLET_COMPLIANCE; - } else { - ACCESS_SESSION = Boolean.parseBoolean(accessSession); - } - } - //------------------------------------------------------ Constructor public StandardHostValve() { super(true); @@ -183,7 +167,7 @@ final class StandardHostValve extends ValveBase { } finally { // Access a session (if present) to update last accessed time, based // on a strict interpretation of the specification - if (ACCESS_SESSION) { + if (context.getAlwaysAccessSession()) { request.getSession(false); } diff --git a/java/org/apache/catalina/startup/FailedContext.java b/java/org/apache/catalina/startup/FailedContext.java index aebbd0d..9a93207 100644 --- a/java/org/apache/catalina/startup/FailedContext.java +++ b/java/org/apache/catalina/startup/FailedContext.java @@ -815,4 +815,20 @@ public class FailedContext extends LifecycleMBeanBase implements Context { public void setCreateUploadTargets(boolean createUploadTargets) { /* NO-OP */} @Override public boolean getCreateUploadTargets() { return false; } + + @Override + public boolean getAlwaysAccessSession() { return false; } + @Override + public void setAlwaysAccessSession(boolean alwaysAccessSession) {} + + @Override + public boolean getContextGetResourceRequiresSlash() { return false; } + @Override + public void setContextGetResourceRequiresSlash(boolean contextGetResourceRequiresSlash) {} + + @Override + public boolean getDispatcherWrapsSameObject() { return false; } + @Override + public void setDispatcherWrapsSameObject(boolean dispatcherWrapsSameObject) {} + } \ No newline at end of file diff --git a/test/org/apache/tomcat/unittest/TesterContext.java b/test/org/apache/tomcat/unittest/TesterContext.java index 14c9ffc..94d7b34 100644 --- a/test/org/apache/tomcat/unittest/TesterContext.java +++ b/test/org/apache/tomcat/unittest/TesterContext.java @@ -1275,4 +1275,20 @@ public class TesterContext implements Context { public void setCreateUploadTargets(boolean createUploadTargets) { /* NO-OP */} @Override public boolean getCreateUploadTargets() { return false; } + + @Override + public boolean getAlwaysAccessSession() { return false; } + @Override + public void setAlwaysAccessSession(boolean alwaysAccessSession) {} + + @Override + public boolean getContextGetResourceRequiresSlash() { return false; } + @Override + public void setContextGetResourceRequiresSlash(boolean contextGetResourceRequiresSlash) {} + + @Override + public boolean getDispatcherWrapsSameObject() { return false; } + @Override + public void setDispatcherWrapsSameObject(boolean dispatcherWrapsSameObject) {} + } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 716678c..657f4dd 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -99,6 +99,24 @@ system property, replaced by the <code>sessionLastAccessAtStart</code> attribute on the Manager. (remm) </update> + <update> + Remove + <code>org.apache.catalina.core.StandardHostValve.ACCESS_SESSION</code> + system property, replaced by the + <code>alwaysAccessSession</code> attribute on the Context. (remm) + </update> + <update> + Remove + <code>org.apache.catalina.core.ApplicationContext.GET_RESOURCE_REQUIRE_SLASH</code> + system property, replaced by the + <code>contextGetResourceRequiresSlash</code> attribute on the Context. (remm) + </update> + <update> + Remove + <code>org.apache.catalina.core.ApplicationDispatcher.WRAP_SAME_OBJECT</code> + system property, replaced by the + <code>dispatcherWrapsSameObject</code> attribute on the Context. (remm) + </update> </changelog> </subsection> <subsection name="Coyote"> diff --git a/webapps/docs/config/context.xml b/webapps/docs/config/context.xml index d4ea9e9..0846d38 100644 --- a/webapps/docs/config/context.xml +++ b/webapps/docs/config/context.xml @@ -297,6 +297,15 @@ <code>/WEB-INF/web.xml</code>.</p> </attribute> + <attribute name="alwaysAccessSession" required="false"> + <p>If this is <code>true</code>, every request that is associated with a + session will cause the session's last accessed time to be updated + regardless of whether or not the request explicitly accesses the session.</p> + <p>If <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code> is set to + <code>true</code>, the default of this setting will be <code>true</code>, + else the default value will be <code>false</code>.</p> + </attribute> + <attribute name="backgroundProcessorDelay" required="false"> <p>This value represents the delay in seconds between the invocation of the backgroundProcess method on this context and @@ -328,6 +337,18 @@ no filtering will be applied.</p> </attribute> + <attribute name="contextGetResourceRequiresSlash" required="false"> + <p>If this is <code>true</code> then the path passed to + <code>ServletContext.getResource()</code> or + <code>ServletContext.getResourceAsStream()</code> must start with + "/". If <code>false</code>, code like + <code>getResource("myfolder/myresource.txt")</code> will work as Tomcat + will prepend "/" to the provided path.</p> + <p>If <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code> is set to + <code>true</code>, the default of this setting will be <code>true</code>, + else the default value will be <code>false</code>.</p> + </attribute> + <attribute name="cookies" required="false"> <p>Set to <code>true</code> if you want cookies to be used for session identifier communication if supported by the client (this @@ -352,6 +373,15 @@ return <code>null</code>.</p> </attribute> + <attribute name="dispatcherWrapsSameObject" required="false"> + <p>If this is <code>true</code> then any wrapped request or response + object passed to an application dispatcher will be checked to ensure that + it has wrapped the original request or response.</p> + <p>If <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code> is set to + <code>true</code>, the default of this setting will be <code>true</code>, + else the default value will be <code>false</code>.</p> + </attribute> + <attribute name="docBase" required="true"> <p>The <em>Document Base</em> (also known as the <em>Context Root</em>) directory for this web application, or the pathname diff --git a/webapps/docs/config/systemprops.xml b/webapps/docs/config/systemprops.xml index 1289604..dfecf4f 100644 --- a/webapps/docs/config/systemprops.xml +++ b/webapps/docs/config/systemprops.xml @@ -283,11 +283,11 @@ <p>The default value of this system property is <code>false</code>.</p> <p>If this is <code>true</code> the default values will be changed for:</p> <ul> + <li><code>org.apache.catalina.<br/>Context.alwaysAccessSession</code></li> + <li><code>org.apache.catalina.<br/>Context.contextGetResourceRequiresSlash</code></li> + <li><code>org.apache.catalina.<br/>Context.dispatcherWrapsSameObject</code></li> <li><code>org.apache.catalina.<br/>Manager.sessionActivityCheck</code></li> <li><code>org.apache.catalina.<br/>Manager.sessionLastAccessAtStart</code></li> - <li><code>org.apache.catalina.core.<br/>ApplicationContext.GET_RESOURCE_REQUIRE_SLASH</code></li> - <li><code>org.apache.catalina.core.<br/>ApplicationDispatcher.WRAP_SAME_OBJECT</code></li> - <li><code>org.apache.catalina.core.<br/>StandardHostValve.ACCESS_SESSION</code></li> <li><code>org.apache.tomcat.util.http.<br/>ServerCookie.STRICT_NAMING</code></li> <li>The <code>URIEncoding</code> attribute of any <a href="http.html">HTTP connector</a> or @@ -305,27 +305,6 @@ </ul> </property> - <property name="org.apache.catalina.core.ApplicationContext .GET_RESOURCE_REQUIRE_SLASH"> - <p>If this is <code>true</code> then the path passed to - <code>ServletContext.getResource()</code> or - <code>ServletContext.getResourceAsStream()</code> must start with - "/". If <code>false</code>, code like - <code>getResource("myfolder/myresource.txt")</code> will work as Tomcat - will prepend "/" to the provided path.</p> - <p>If <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code> is set to - <code>true</code>, the default of this setting will be <code>true</code>, - else the default value will be <code>false</code>.</p> - </property> - - <property name="org.apache.catalina.core. ApplicationDispatcher.WRAP_SAME_OBJECT"> - <p>If this is <code>true</code> then any wrapped request or response - object passed to an application dispatcher will be checked to ensure that - it has wrapped the original request or response.</p> - <p>If <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code> is set to - <code>true</code>, the default of this setting will be <code>true</code>, - else the default value will be <code>false</code>.</p> - </property> - <property name="org.apache.tomcat.websocket. STRICT_SPEC_COMPLIANCE"> <p>The default value of this system property is <code>false</code>.</p> <p>If this is <code>true</code> the default values will be changed for:</p> @@ -360,15 +339,6 @@ <code>JSESSIONIDSSO</code>.</p> </property> - <property name="org.apache.catalina.core. StandardHostValve.ACCESS_SESSION"> - <p>If this is <code>true</code>, every request that is associated with a - session will cause the session's last accessed time to be updated - regardless of whether or not the request explicitly accesses the session.</p> - <p>If <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code> is set to - <code>true</code>, the default of this setting will be <code>true</code>, - else the default value will be <code>false</code>.</p> - </property> - </properties> </section> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org