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 b79e56c  Remove two system properties used for configuration
b79e56c is described below

commit b79e56c7739d8151ad6b0d1d34da3404bc46da34
Author: remm <r...@apache.org>
AuthorDate: Thu Mar 26 11:29:47 2020 +0100

    Remove two system properties used for configuration
    
    Again two rarely used properties (well, not for the TCK), both in the
    session package:
    - org.apache.catalina.session.StandardSession.ACTIVITY_CHECK is replaced
    by the Manager.sessionActivityCheck attribute
    - org.apache.catalina.session.StandardSession.LAST_ACCESS_AT_START is
    replaced by the Manager.sessionLastAccessAtStart attribute
---
 java/org/apache/catalina/Manager.java              | 51 ++++++++++++++++++
 .../apache/catalina/ha/session/DeltaSession.java   | 10 ++--
 java/org/apache/catalina/session/ManagerBase.java  | 27 ++++++++++
 .../apache/catalina/session/StandardSession.java   | 61 +++++++++-------------
 .../session/TestPersistentManagerIntegration.java  | 27 ++--------
 webapps/docs/changelog.xml                         | 12 +++++
 webapps/docs/config/manager.xml                    | 20 +++++++
 webapps/docs/config/systemprops.xml                | 26 +--------
 8 files changed, 148 insertions(+), 86 deletions(-)

diff --git a/java/org/apache/catalina/Manager.java 
b/java/org/apache/catalina/Manager.java
index fb1d306..3cab011 100644
--- a/java/org/apache/catalina/Manager.java
+++ b/java/org/apache/catalina/Manager.java
@@ -440,4 +440,55 @@ public interface Manager {
      */
     public void setNotifyAttributeListenerOnUnchangedValue(
             boolean notifyAttributeListenerOnUnchangedValue);
+
+
+    /**
+     * If this is <code>true</code>, Tomcat will track the number of active
+     * requests for each session. When determining if a session is valid, any
+     * session with at least one active request will always be considered 
valid.
+     * 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 default boolean getSessionActivityCheck() {
+        return Globals.STRICT_SERVLET_COMPLIANCE;
+    }
+
+
+    /**
+     * Configure if Tomcat will track the number of active requests for each
+     * session. When determining if a session is valid, any session with at
+     * least one active request will always be considered valid.
+     * @param sessionActivityCheck the new flag value
+     */
+    public void setSessionActivityCheck(boolean sessionActivityCheck);
+
+
+    /**
+     * If this is <code>true</code>, the last accessed time for sessions will
+     * be calculated from the beginning of the previous request. If
+     * <code>false</code>, the last accessed time for sessions will be 
calculated
+     * from the end of the previous request. This also affects how the idle 
time
+     * is calculated.
+     * 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 default boolean getSessionLastAccessAtStart() {
+        return Globals.STRICT_SERVLET_COMPLIANCE;
+    }
+
+
+    /**
+     * Configure if the last accessed time for sessions will
+     * be calculated from the beginning of the previous request. If
+     * <code>false</code>, the last accessed time for sessions will be 
calculated
+     * from the end of the previous request. This also affects how the idle 
time
+     * is calculated.
+     * @param sessionLastAccessAtStart the new flag value
+     */
+    public void setSessionLastAccessAtStart(boolean sessionLastAccessAtStart);
+
 }
diff --git a/java/org/apache/catalina/ha/session/DeltaSession.java 
b/java/org/apache/catalina/ha/session/DeltaSession.java
index 7ea3e1c..9875fb2 100644
--- a/java/org/apache/catalina/ha/session/DeltaSession.java
+++ b/java/org/apache/catalina/ha/session/DeltaSession.java
@@ -437,7 +437,7 @@ public class DeltaSession extends StandardSession 
implements Externalizable,Clus
         if (this.expiring) {
             return true;
         }
-        if (ACTIVITY_CHECK && accessCount.get() > 0) {
+        if (activityCheck && accessCount.get() > 0) {
             return true;
         }
         if (maxInactiveInterval > 0) {
@@ -1011,7 +1011,11 @@ public class DeltaSession extends StandardSession 
implements Externalizable,Clus
     }
 
     protected void setAccessCount(int count) {
-        if ( accessCount == null && ACTIVITY_CHECK ) accessCount = new 
AtomicInteger();
-        if ( accessCount != null ) super.accessCount.set(count);
+        if (accessCount == null && activityCheck) {
+            accessCount = new AtomicInteger();
+        }
+        if (accessCount != null) {
+            accessCount.set(count);
+        }
     }
 }
diff --git a/java/org/apache/catalina/session/ManagerBase.java 
b/java/org/apache/catalina/session/ManagerBase.java
index 56dd793..d6304ce 100644
--- a/java/org/apache/catalina/session/ManagerBase.java
+++ b/java/org/apache/catalina/session/ManagerBase.java
@@ -203,6 +203,9 @@ public abstract class ManagerBase extends 
LifecycleMBeanBase implements Manager
      */
     private boolean persistAuthentication = false;
 
+    private boolean sessionActivityCheck = Globals.STRICT_SERVLET_COMPLIANCE;
+
+    private boolean sessionLastAccessAtStart = 
Globals.STRICT_SERVLET_COMPLIANCE;
 
     // ------------------------------------------------------------ 
Constructors
 
@@ -247,6 +250,30 @@ public abstract class ManagerBase extends 
LifecycleMBeanBase implements Manager
     }
 
 
+    @Override
+    public boolean getSessionActivityCheck() {
+        return sessionActivityCheck;
+    }
+
+
+    @Override
+    public void setSessionActivityCheck(boolean sessionActivityCheck) {
+        this.sessionActivityCheck = sessionActivityCheck;
+    }
+
+
+    @Override
+    public boolean getSessionLastAccessAtStart() {
+        return sessionLastAccessAtStart;
+    }
+
+
+    @Override
+    public void setSessionLastAccessAtStart(boolean sessionLastAccessAtStart) {
+        this.sessionLastAccessAtStart = sessionLastAccessAtStart;
+    }
+
+
     /**
      * Obtain the regular expression used to filter session attribute based on
      * attribute name. The regular expression is anchored so it must match the
diff --git a/java/org/apache/catalina/session/StandardSession.java 
b/java/org/apache/catalina/session/StandardSession.java
index 951f9ee..0e8402a 100644
--- a/java/org/apache/catalina/session/StandardSession.java
+++ b/java/org/apache/catalina/session/StandardSession.java
@@ -84,33 +84,6 @@ public class StandardSession implements HttpSession, 
Session, Serializable {
 
     private static final long serialVersionUID = 1L;
 
-    protected static final boolean STRICT_SERVLET_COMPLIANCE;
-
-    protected static final boolean ACTIVITY_CHECK;
-
-    protected static final boolean LAST_ACCESS_AT_START;
-
-    static {
-        STRICT_SERVLET_COMPLIANCE = Globals.STRICT_SERVLET_COMPLIANCE;
-
-        String activityCheck = System.getProperty(
-                "org.apache.catalina.session.StandardSession.ACTIVITY_CHECK");
-        if (activityCheck == null) {
-            ACTIVITY_CHECK = STRICT_SERVLET_COMPLIANCE;
-        } else {
-            ACTIVITY_CHECK = Boolean.parseBoolean(activityCheck);
-        }
-
-        String lastAccessAtStart = System.getProperty(
-                
"org.apache.catalina.session.StandardSession.LAST_ACCESS_AT_START");
-        if (lastAccessAtStart == null) {
-            LAST_ACCESS_AT_START = STRICT_SERVLET_COMPLIANCE;
-        } else {
-            LAST_ACCESS_AT_START = Boolean.parseBoolean(lastAccessAtStart);
-        }
-    }
-
-
     // ----------------------------------------------------------- Constructors
 
 
@@ -124,8 +97,14 @@ public class StandardSession implements HttpSession, 
Session, Serializable {
         super();
         this.manager = manager;
 
+        if (manager != null) {
+            // Manager could be null in test environments
+            activityCheck = manager.getSessionActivityCheck();
+            lastAccessAtStart = manager.getSessionLastAccessAtStart();
+        }
+
         // Initialize access count
-        if (ACTIVITY_CHECK) {
+        if (activityCheck) {
             accessCount = new AtomicInteger();
         }
 
@@ -271,6 +250,18 @@ public class StandardSession implements HttpSession, 
Session, Serializable {
     protected transient AtomicInteger accessCount = null;
 
 
+    /**
+     * The activity check for this session.
+     */
+    protected transient boolean activityCheck;
+
+
+    /**
+     * The behavior of the last access check.
+     */
+    protected transient boolean lastAccessAtStart;
+
+
     // ----------------------------------------------------- Session Properties
 
 
@@ -525,7 +516,7 @@ public class StandardSession implements HttpSession, 
Session, Serializable {
     public long getIdleTimeInternal() {
         long timeNow = System.currentTimeMillis();
         long timeIdle;
-        if (LAST_ACCESS_AT_START) {
+        if (lastAccessAtStart) {
             timeIdle = timeNow - lastAccessedTime;
         } else {
             timeIdle = timeNow - thisAccessedTime;
@@ -650,7 +641,7 @@ public class StandardSession implements HttpSession, 
Session, Serializable {
             return true;
         }
 
-        if (ACTIVITY_CHECK && accessCount.get() > 0) {
+        if (activityCheck && accessCount.get() > 0) {
             return true;
         }
 
@@ -689,7 +680,7 @@ public class StandardSession implements HttpSession, 
Session, Serializable {
 
         this.thisAccessedTime = System.currentTimeMillis();
 
-        if (ACTIVITY_CHECK) {
+        if (activityCheck) {
             accessCount.incrementAndGet();
         }
 
@@ -708,7 +699,7 @@ public class StandardSession implements HttpSession, 
Session, Serializable {
          * The servlet spec mandates to ignore request handling time
          * in lastAccessedTime.
          */
-        if (LAST_ACCESS_AT_START) {
+        if (lastAccessAtStart) {
             this.lastAccessedTime = this.thisAccessedTime;
             this.thisAccessedTime = System.currentTimeMillis();
         } else {
@@ -716,7 +707,7 @@ public class StandardSession implements HttpSession, 
Session, Serializable {
             this.lastAccessedTime = this.thisAccessedTime;
         }
 
-        if (ACTIVITY_CHECK) {
+        if (activityCheck) {
             accessCount.decrementAndGet();
         }
 
@@ -820,7 +811,7 @@ public class StandardSession implements HttpSession, 
Session, Serializable {
                 }
             }
 
-            if (ACTIVITY_CHECK) {
+            if (activityCheck) {
                 accessCount.set(0);
             }
 
@@ -902,7 +893,7 @@ public class StandardSession implements HttpSession, 
Session, Serializable {
     public void activate() {
 
         // Initialize access count
-        if (ACTIVITY_CHECK) {
+        if (activityCheck) {
             accessCount = new AtomicInteger();
         }
 
diff --git 
a/test/org/apache/catalina/session/TestPersistentManagerIntegration.java 
b/test/org/apache/catalina/session/TestPersistentManagerIntegration.java
index b625a64..f4bb66f 100644
--- a/test/org/apache/catalina/session/TestPersistentManagerIntegration.java
+++ b/test/org/apache/catalina/session/TestPersistentManagerIntegration.java
@@ -26,9 +26,7 @@ import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
 import jakarta.servlet.http.HttpSession;
 
-import org.junit.After;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
 import org.apache.catalina.Context;
@@ -41,28 +39,6 @@ import org.apache.catalina.valves.PersistentValve;
 
 public class TestPersistentManagerIntegration extends TomcatBaseTest {
 
-    private static final String ACTIVITY_CHECK = 
"org.apache.catalina.session.StandardSession.ACTIVITY_CHECK";
-
-    private String oldActivityCheck;
-
-    /**
-     * As documented in config/manager.html, the "ACTIVITY_CHECK" property must
-     * be set to "true" for PersistentManager to function correctly.
-     */
-    @Before
-    public void setActivityCheck() {
-        oldActivityCheck = System.setProperty(ACTIVITY_CHECK, "true");
-    }
-
-    @After
-    public void resetActivityCheck() {
-        if (oldActivityCheck != null) {
-            System.setProperty(ACTIVITY_CHECK, oldActivityCheck);
-        } else {
-            System.clearProperty(ACTIVITY_CHECK);
-        }
-    }
-
     /**
      * Wait enough for the system clock to update its value. On some systems
      * (e.g. old Windows) the clock granularity is tens of milliseconds.
@@ -109,6 +85,7 @@ public class TestPersistentManagerIntegration extends 
TomcatBaseTest {
 
         manager.setStore(store);
         manager.setMaxIdleBackup(0);
+        manager.setSessionActivityCheck(true);
         ctx.setManager(manager);
         ctx.addValve(new PersistentValve());
         tomcat.start();
@@ -141,6 +118,7 @@ public class TestPersistentManagerIntegration extends 
TomcatBaseTest {
 
         manager.setStore(store);
         manager.setMaxIdleBackup(0);
+        manager.setSessionActivityCheck(true);
         ctx.setManager(manager);
         ctx.addValve(new PersistentValve());
         tomcat.start();
@@ -173,6 +151,7 @@ public class TestPersistentManagerIntegration extends 
TomcatBaseTest {
 
         manager.setStore(store);
         manager.setMaxIdleBackup(0);
+        manager.setSessionActivityCheck(true);
         ctx.setManager(manager);
         tomcat.start();
         String sessionId = getUrl("http://localhost:"; + getPort() + "/dummy")
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 9e7f153..716678c 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -87,6 +87,18 @@
         <code>enforceEncodingInGetWriter</code> attribute on the Connector.
         (remm)
       </update>
+      <update>
+        Remove
+        <code>org.apache.catalina.session.StandardSession.ACTIVITY_CHECK</code>
+        system property, replaced by the <code>sessionActivityCheck</code> 
attribute
+        on the Manager. (remm)
+      </update>
+      <update>
+        Remove
+        
<code>org.apache.catalina.session.StandardSession.LAST_ACCESS_AT_START</code>
+        system property, replaced by the
+        <code>sessionLastAccessAtStart</code> attribute on the Manager. (remm)
+      </update>
     </changelog>
   </subsection>
   <subsection name="Coyote">
diff --git a/webapps/docs/config/manager.xml b/webapps/docs/config/manager.xml
index 8af3e20..d70e7b5 100644
--- a/webapps/docs/config/manager.xml
+++ b/webapps/docs/config/manager.xml
@@ -90,6 +90,26 @@
         the default value of <code>false</code> will be used.</p>
       </attribute>
 
+      <attribute name="sessionActivityCheck" required="false">
+        <p>If this is <code>true</code>, Tomcat will track the number of active
+        requests for each session. When determining if a session is valid, any
+        session with at least one active request will always be considered 
valid.</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="sessionLastAccessAtStart" required="false">
+        <p>If this is <code>true</code>, the last accessed time for sessions 
will
+        be calculated from the beginning of the previous request. If
+        <code>false</code>, the last accessed time for sessions will be 
calculated
+        from the end of the previous request. This also affects how the idle 
time
+        is calculated.</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>
+
     </attributes>
 
   </subsection>
diff --git a/webapps/docs/config/systemprops.xml 
b/webapps/docs/config/systemprops.xml
index 0188a53..1289604 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/>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.catalina.session.<br/>StandardSession.ACTIVITY_CHECK</code></li>
-      
<li><code>org.apache.catalina.session.<br/>StandardSession.LAST_ACCESS_AT_START</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
@@ -369,28 +369,6 @@
       else the default value will be <code>false</code>.</p>
     </property>
 
-    <property
-    name="org.apache.catalina.session. StandardSession.ACTIVITY_CHECK">
-      <p>If this is <code>true</code>, Tomcat will track the number of active
-      requests for each session. When determining if a session is valid, any
-      session with at least one active request will always be considered 
valid.</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.session. StandardSession.LAST_ACCESS_AT_START">
-      <p>If this is <code>true</code>, the last accessed time for sessions will
-      be calculated from the beginning of the previous request. If
-      <code>false</code>, the last accessed time for sessions will be 
calculated
-      from the end of the previous request. This also affects how the idle time
-      is calculated.</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

Reply via email to