Interface Session

All Superinterfaces:
Attributes
All Known Implementing Classes:
ManagedSession

public interface Session extends Attributes

The interface to a generic session associated with a request. This interface may be used directly, or it may be wrapped by an API specific representation of a session. Such wrappers must implement the Session.API sub interface.

Depending on the implementation the attribute values may be stored locally in memory or in a remote database. The instances of the attribute values may be different to those passed to Attributes.setAttribute(String, Object) or to those returned in previous Attributes.getAttribute(String) calls.

  • Method Details

    • getSession

      static Session getSession(Object session)

      Get the session associated with an API session wrapper.

      Parameters:
      session - The API wrapper of the session
      Returns:
      The associated Session.
    • getApi

      <T extends Session.API> T getApi()
      Type Parameters:
      T - The type of the API wrapper.
      Returns:
      An API wrapper of this session or null if there is none.
    • isValid

      boolean isValid()
      Returns:
      true if the session is has not been invalidated nor expired due to inactivity.
    • getId

      String getId()
      Returns:
      A identifier for the session. Depending on the implementation may be unique within the context, the server, the JVM or a cluster.
      See Also:
    • getExtendedId

      String getExtendedId()
      Returns:
      The session identifier as returned by getId() extended with additional routing information. The additional information does not form part of the identity, but may be used by implementations and associated infrastructure to help route request for the same session to the same server.
    • getLastAccessedTime

      long getLastAccessedTime()
      Returns:
      the time, as represented by System.currentTimeMillis(), that the session was last accessed by a request.
    • setMaxInactiveInterval

      void setMaxInactiveInterval(int secs)
      Parameters:
      secs - The period in secs in which the session will remain valid (unless explicitly invalidated) when not accessed by any requests.
    • getMaxInactiveInterval

      int getMaxInactiveInterval()
      Returns:
      The period in secs in which the session will remain valid (unless explicitly invalidated) when not accessed by any requests.
    • renewId

      void renewId(Request request, Response response)
      Renew the identity of the session. Typically, this is done after a change of authentication or confidentiality.
      Parameters:
      request - The request from which the session was obtained.
      response - The response which may be updated with the new session identity.
    • invalidate

      void invalidate()

      Invalidate this session in the current context and all sessions of the same identity with associated contexts.

    • isNew

      boolean isNew() throws IllegalStateException
      Returns:
      true if the session has been newly created within the scope of the current request.
      Throws:
      IllegalStateException
    • encodeURI

      String encodeURI(Request request, String uri, boolean cookiesInUse)