tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1784767 - in /tomcat/trunk: java/javax/servlet/ java/org/apache/catalina/core/ java/org/apache/jasper/servlet/ test/org/apache/tomcat/unittest/
Date Tue, 28 Feb 2017 15:55:44 GMT
Author: markt
Date: Tue Feb 28 15:55:44 2017
New Revision: 1784767

URL: http://svn.apache.org/viewvc?rev=1784767&view=rev
Log:
Add the new ServletContext methods to set and get the default session timeout

Modified:
    tomcat/trunk/java/javax/servlet/ServletContext.java
    tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
    tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java
    tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
    tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java
    tomcat/trunk/test/org/apache/tomcat/unittest/TesterServletContext.java

Modified: tomcat/trunk/java/javax/servlet/ServletContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/servlet/ServletContext.java?rev=1784767&r1=1784766&r2=1784767&view=diff
==============================================================================
--- tomcat/trunk/java/javax/servlet/ServletContext.java (original)
+++ tomcat/trunk/java/javax/servlet/ServletContext.java Tue Feb 28 15:55:44 2017
@@ -962,4 +962,39 @@ public interface ServletContext {
      * @since Servlet 3.1
      */
     public String getVirtualServerName();
+
+    /**
+     * Get the default session timeout.
+     *
+     * @throws UnsupportedOperationException    If called from a
+     *    {@link ServletContextListener#contextInitialized(ServletContextEvent)}
+     *    method of a {@link ServletContextListener} that was not defined in a
+     *    web.xml file, a web-fragment.xml file nor annotated with
+     *    {@link javax.servlet.annotation.WebListener}. For example, a
+     *    {@link ServletContextListener} defined in a TLD would not be able to
+     *    use this method.
+     *
+     * @since Servlet 4.0
+     */
+    public int getSessionTimeout();
+
+    /**
+     * Set the default session timeout. This method may only be called before
+     * the ServletContext is initialised.
+     *
+     * @param sessionTimeoutMins The new default session timeout in minutes.
+     *
+     * @throws UnsupportedOperationException    If called from a
+     *    {@link ServletContextListener#contextInitialized(ServletContextEvent)}
+     *    method of a {@link ServletContextListener} that was not defined in a
+     *    web.xml file, a web-fragment.xml file nor annotated with
+     *    {@link javax.servlet.annotation.WebListener}. For example, a
+     *    {@link ServletContextListener} defined in a TLD would not be able to
+     *    use this method.
+     * @throws IllegalStateException If the ServletContext has already been
+     *         initialised
+     *
+     * @since Servlet 4.0
+     */
+    public void setSessionTimeout(int sessionTimeout);
 }

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=1784767&r1=1784766&r2=1784767&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java Tue Feb 28 15:55:44
2017
@@ -1227,6 +1227,24 @@ public class ApplicationContext implemen
     }
 
 
+    @Override
+    public int getSessionTimeout() {
+        return context.getSessionTimeout();
+    }
+
+
+    @Override
+    public void setSessionTimeout(int sessionTimeout) {
+        if (!context.getState().equals(LifecycleState.STARTING_PREP)) {
+            throw new IllegalStateException(
+                    sm.getString("applicationContext.setSessionTimeout.ise",
+                            getContextPath()));
+        }
+
+        context.setSessionTimeout(sessionTimeout);
+    }
+
+
     // -------------------------------------------------------- Package Methods
     protected StandardContext getContext() {
         return this.context;

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java?rev=1784767&r1=1784766&r2=1784767&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java Tue Feb 28 15:55:44
2017
@@ -769,6 +769,26 @@ public class ApplicationContextFacade im
     }
 
 
+    @Override
+    public int getSessionTimeout() {
+        if (SecurityUtil.isPackageProtectionEnabled()) {
+            return ((Integer) doPrivileged("getSessionTimeout", null)).intValue();
+        } else  {
+            return context.getSessionTimeout();
+        }
+    }
+
+
+    @Override
+    public void setSessionTimeout(int sessionTimeout) {
+        if (SecurityUtil.isPackageProtectionEnabled()) {
+            doPrivileged("getSessionTimeout", new Object[] { Integer.valueOf(sessionTimeout)
});
+        } else  {
+            context.setSessionTimeout(sessionTimeout);
+        }
+    }
+
+
     /**
      * Use reflection to invoke the requested method. Cache the method object
      * to speed up the process

Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1784767&r1=1784766&r2=1784767&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties Tue Feb 28 15:55:44
2017
@@ -32,6 +32,7 @@ applicationContext.role.iae=An individua
 applicationContext.roles.iae=Array of roles to declare for context [{0}] cannot be null
 applicationContext.setAttribute.namenull=Name cannot be null
 applicationContext.setInitParam.ise=Initialization parameters cannot be set after the context
has been initialized
+applicationContext.setSessionTimeout.ise=The session timeout cannot be set for context {0}
as the context has been initialised
 applicationContext.setSessionTracking.ise=The session tracking modes for context {0} cannot
be set whilst the context is running
 applicationContext.setSessionTracking.iae.invalid=The session tracking mode {0} requested
for context {1} is not supported by that context
 applicationContext.setSessionTracking.iae.ssl=The session tracking modes requested for context
{0} included SSL and at least one other mode. SSL may not be configured with other modes.

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1784767&r1=1784766&r2=1784767&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Tue Feb 28 15:55:44 2017
@@ -6697,5 +6697,17 @@ public class StandardContext extends Con
         public String getVirtualServerName() {
             return sc.getVirtualServerName();
         }
+
+        @Override
+        public int getSessionTimeout() {
+            throw new UnsupportedOperationException(
+                    sm.getString("noPluggabilityServletContext.notAllowed"));
+        }
+
+        @Override
+        public void setSessionTimeout(int sessionTimeout) {
+            throw new UnsupportedOperationException(
+                    sm.getString("noPluggabilityServletContext.notAllowed"));
+        }
     }
 }

Modified: tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java?rev=1784767&r1=1784766&r2=1784767&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java (original)
+++ tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java Tue Feb 28 15:55:44
2017
@@ -690,4 +690,14 @@ public class JspCServletContext implemen
     public String getVirtualServerName() {
         return null;
     }
+
+    @Override
+    public int getSessionTimeout() {
+        return 0;
+    }
+
+    @Override
+    public void setSessionTimeout(int sessionTimeout) {
+        // NO-OP
+    }
 }

Modified: tomcat/trunk/test/org/apache/tomcat/unittest/TesterServletContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/unittest/TesterServletContext.java?rev=1784767&r1=1784766&r2=1784767&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/unittest/TesterServletContext.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/unittest/TesterServletContext.java Tue Feb 28 15:55:44
2017
@@ -342,4 +342,14 @@ public class TesterServletContext implem
     public String getVirtualServerName() {
         return "localhost";
     }
+
+    @Override
+    public int getSessionTimeout() {
+        throw new RuntimeException("Not implemented");
+    }
+
+    @Override
+    public void setSessionTimeout(int sessionTimeout) {
+        throw new RuntimeException("Not implemented");
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message