Class HttpSessionImpl

  • All Implemented Interfaces:
    javax.servlet.http.HttpSession

    public class HttpSessionImpl
    extends Base
    implements javax.servlet.http.HttpSession
    This is the HttpSession implementation that supports clustering.
    Version:
    Coherence 2.3
    Author:
    cp 2003.07.24
    • Constructor Detail

      • HttpSessionImpl

        public HttpSessionImpl​(SessionHelper helper,
                               HttpSessionCollection collection)
        Construct a Coherence HTTP session object for a new session.
        Parameters:
        helper - the application's session helper
        collection - the HttpSessionCollection that this session will use to create and manage its session model
      • HttpSessionImpl

        public HttpSessionImpl​(SessionHelper helper,
                               HttpSessionCollection collection,
                               String sId)
        Construct a Coherence HTTP session object for an existing session.
        Parameters:
        helper - the application's session helper
        collection - the HttpSessionCollection that this session will use to access and manage its session model
        sId - the session ID that this session will represent
    • Method Detail

      • getAttribute

        public Object getAttribute​(String sName)
        Returns the object bound with the specified name in this session, or null if no object is bound under the name.
        Specified by:
        getAttribute in interface javax.servlet.http.HttpSession
        Parameters:
        sName - a string specifying the name of the object
        Returns:
        the object with the specified name
        Throws:
        IllegalStateException - if this method is called on an invalidated session
      • getAttributeNames

        public Enumeration getAttributeNames()
        Returns an Enumeration of String objects containing the names of all the objects bound to this session.
        Specified by:
        getAttributeNames in interface javax.servlet.http.HttpSession
        Returns:
        an Enumeration of String objects specifying the names of all the objects bound to this session
        Throws:
        IllegalStateException - if this method is called on an invalidated session
      • getCreationTime

        public long getCreationTime()
        Returns the creation time for this session.
        Specified by:
        getCreationTime in interface javax.servlet.http.HttpSession
        Returns:
        the creation time for this session
      • getId

        public String getId()
        Returns the session identifier for this session.
        Specified by:
        getId in interface javax.servlet.http.HttpSession
        Returns:
        the session identifier for this session.
      • getLastAccessedTime

        public long getLastAccessedTime()
        Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight, January 1, 1970 GMT. Actions that your application takes, such as getting or setting a value associated with the session, do not affect the access time.
        Specified by:
        getLastAccessedTime in interface javax.servlet.http.HttpSession
        Returns:
        the last time the client sent a request associated with this session, as the number of milliseconds since midnight, January 1, 1970 GMT. Actions that your application takes, such as getting or setting a value associated with the session, do not affect the access time
      • getMaxInactiveInterval

        public int getMaxInactiveInterval()
        Returns the maximum time interval, in seconds, between client requests before the servlet container will invalidate the session. A negative time indicates that the session should never time out.
        Specified by:
        getMaxInactiveInterval in interface javax.servlet.http.HttpSession
        Returns:
        the maximum time interval, in seconds, between client requests before the servlet container will invalidate the session. A negative time indicates that the session should never time out
      • getServletContext

        public javax.servlet.ServletContext getServletContext()
        Returns the ServletContext to which this session belongs.
        Specified by:
        getServletContext in interface javax.servlet.http.HttpSession
        Returns:
        The ServletContext object for the web application
        Since:
        Servlet 2.3
      • getSessionContext

        public javax.servlet.http.HttpSessionContext getSessionContext()
        Deprecated.
        As of Version 2.1, this method is deprecated and has no replacement. It will be removed in a future version of the Java Servlet API.
        Get the HttpSessionContext.
        Specified by:
        getSessionContext in interface javax.servlet.http.HttpSession
        Returns:
        an HttpSessionContext object
      • getValue

        public Object getValue​(String sName)
        Deprecated.
        As of Version 2.2, this method is replaced by getAttribute(String).
        Returns the object bound with the specified name in this session, or null if no object is bound under the name.
        Specified by:
        getValue in interface javax.servlet.http.HttpSession
        Parameters:
        sName - a string specifying the name of the object
        Returns:
        the object with the specified name
        Throws:
        IllegalStateException - if this method is called on an invalidated session
      • getValueNames

        public String[] getValueNames()
        Deprecated.
        As of Version 2.2, this method is replaced by getAttributeNames()
        Returns an array of String objects specifying the names of all the objects bound to this session.
        Specified by:
        getValueNames in interface javax.servlet.http.HttpSession
        Returns:
        an array of String objects specifying the names of all the objects bound to this session
        Throws:
        IllegalStateException - if this method is called on an invalidated session
      • invalidate

        public void invalidate()
        Invalidates this session then unbinds any objects bound to it.
        Specified by:
        invalidate in interface javax.servlet.http.HttpSession
        Throws:
        IllegalStateException - if this method is called on an already invalidated session
      • isNew

        public boolean isNew()
        Returns true if the client does not yet know about the session or if the client chooses not to join the session. For example, if the server used only cookie-based sessions, and the client had disabled the use of cookies, then a session would be new on each request.
        Specified by:
        isNew in interface javax.servlet.http.HttpSession
        Returns:
        true if the server has created a session, but the client has not yet joined
        Throws:
        IllegalStateException - if this method is called on an already invalidated session
      • putValue

        public void putValue​(String sName,
                             Object oValue)
        Deprecated.
        As of Version 2.2, this method is replaced by setAttribute(String, Object)
        Binds an object to this session, using the name specified. If an object of the same name is already bound to the session, the object is replaced.

        If the value passed in is null, this has the same effect as calling removeAttribute().

        Specified by:
        putValue in interface javax.servlet.http.HttpSession
        Parameters:
        sName - the name to which the object is bound; cannot be null
        oValue - the object to be bound; cannot be null
        Throws:
        IllegalStateException - if this method is called on an invalidated session
      • removeAttribute

        public void removeAttribute​(String sName)
        Removes the object bound with the specified name from this session. If the session does not have an object bound with the specified name, this method does nothing.
        Specified by:
        removeAttribute in interface javax.servlet.http.HttpSession
        Parameters:
        sName - the name of the object to remove from this session
        Throws:
        IllegalStateException - if this method is called on an invalidated session
      • removeValue

        public void removeValue​(String sName)
        Deprecated.
        As of Version 2.2, this method is replaced by removeAttribute(String)
        Removes the object bound with the specified name from this session. If the session does not have an object bound with the specified name, this method does nothing.
        Specified by:
        removeValue in interface javax.servlet.http.HttpSession
        Parameters:
        sName - the name of the object to remove from this session
        Throws:
        IllegalStateException - if this method is called on an invalidated session
      • setAttribute

        public void setAttribute​(String sName,
                                 Object oValue)
        Binds an object to this session, using the name specified. If an object of the same name is already bound to the session, the object is replaced.

        If the value passed in is null, this has the same effect as calling removeAttribute().

        Specified by:
        setAttribute in interface javax.servlet.http.HttpSession
        Parameters:
        sName - the name to which the object is bound; cannot be null
        oValue - the object to be bound
        Throws:
        IllegalStateException - if this method is called on an invalidated session
      • setMaxInactiveInterval

        public void setMaxInactiveInterval​(int cSeconds)
        Set the maximum time interval, in seconds, between client requests before the servlet container will invalidate the session. A negative time indicates that the session should never time out.
        Specified by:
        setMaxInactiveInterval in interface javax.servlet.http.HttpSession
        Parameters:
        cSeconds - the new maximum interval
      • toString

        public String toString()
        Returns a string representation of the object.
        Overrides:
        toString in class Object
        Returns:
        a string representation of the object
      • getDescription

        protected String getDescription()
        Returns a string representation of this object's attributes.
        Returns:
        a string representation of this object's attributes
      • ensureUsableModel

        protected HttpSessionModel ensureUsableModel()
        Obtain a "usable" HttpSessionModel for this session, which may or may not be active.
        Returns:
        a usable HttpSessionModel for this session object
        Throws:
        IllegalStateException - if a usable model cannot be obtained, for example if the session ID does not exist in the cluster
      • ensureActiveModel

        protected HttpSessionModel ensureActiveModel()
        Obtain an "active" HttpSessionModel for this session.
        Returns:
        an active HttpSessionModel for this session object
        Throws:
        IllegalStateException - if a usable model cannot be obtained, for example if the session ID does not exist in the cluster
      • enter

        protected void enter()
        Ensure ownership of the session.
      • exit

        protected void exit()
        Release ownership of the session.
      • getSessionHelper

        protected SessionHelper getSessionHelper()
        Get the SessionHelper for this ServletContext wrapper.
        Returns:
        the SessionHelper for this ServletContext wrapper
      • getCollection

        protected HttpSessionCollection getCollection()
        Obtain the HttpSessionCollection.
        Returns:
        the HttpSessionCollection that manages the session models