Class StandardSession
- All Implemented Interfaces:
- Serializable,- HttpSession,- Session
- Direct Known Subclasses:
- DeltaSession
 IMPLEMENTATION NOTE: An instance of this class represents both the internal (Session) and application level
 (HttpSession) view of the session. However, because the class itself is not declared public, Java logic outside of
 the org.apache.catalina.session package cannot cast an HttpSession view of this instance back to a
 Session view.
 
IMPLEMENTATION NOTE: If you add fields to this class, you must make sure that you carry them over in the read/writeObject methods so that this class is properly serialized.
- Author:
- Craig R. McClanahan, Sean Legassick, Jon S. Stevens
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected AtomicIntegerThe access count for this session.protected static final booleanprotected ConcurrentMap<String,Object> The collection of user data attributes associated with this Session.protected StringThe authentication type used to authenticate our cached Principal, if any.protected longThe time this session was created, in milliseconds since midnight, January 1, 1970 GMT.protected static final String[]Type array.protected booleanWe are currently processing a session expiration, so bypass certain IllegalStateException tests.protected StandardSessionFacadeThe facade associated with this session.protected StringThe session identifier of this Session.protected booleanFlag indicating whether this session is new or not.protected booleanFlag indicating whether this session is valid or not.protected static final booleanprotected longThe last accessed time for this Session.protected ArrayList<SessionListener>The session event listeners for this Session.protected ManagerThe Manager with which this Session is associated.protected intThe maximum time interval, in seconds, between client requests before the servlet container may invalidate this session.Internal notes associated with this session by Catalina components and event listeners.protected PrincipalThe authenticated Principal associated with this session, if any.protected static HttpSessionContextDeprecated.protected static final StringManagerThe string manager for this package.protected static final booleanprotected final PropertyChangeSupportThe property change support for this component.protected longThe current accessed time for this session.Fields inherited from interface org.apache.catalina.SessionSESSION_ACTIVATED_EVENT, SESSION_CREATED_EVENT, SESSION_DESTROYED_EVENT, SESSION_PASSIVATED_EVENT
- 
Constructor SummaryConstructorsConstructorDescriptionStandardSession(Manager manager) Construct a new Session associated with the specified Manager.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaccess()Update the accessed time information for this session.voidactivate()Perform internal processing required to activate this session.voidaddSessionListener(SessionListener listener) Add a session event listener to this component.protected voiddoReadObject(ObjectInputStream stream) Read a serialized version of this session object from the specified object input stream.protected voiddoWriteObject(ObjectOutputStream stream) Write a serialized version of this session object to the specified object output stream.voidEnd access to the session.protected booleanShould the given session attribute be excluded?voidexpire()Perform the internal processing required to invalidate this session, without triggering an exception if the session has already expired.voidexpire(boolean notify) Perform the internal processing required to invalidate this session, without triggering an exception if the session has already expired.voidfireSessionEvent(String type, Object data) Notify all session event listeners that a particular event has occurred for this Session.getAttribute(String name) Returns the object bound with the specified name in this session, ornullif no object is bound under the name.Returns anEnumerationofStringobjects containing the names of all the objects bound to this session.longReturns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.longgetId()Returns a string containing the unique identifier assigned to this session.longlonglongReturns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT, and marked by the time the container received the request.longintReturns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.Returns the ServletContext to which this session belongs.Deprecated.As of Version 2.1, this method is deprecated and has no replacement.longlongDeprecated.String[]Deprecated.voidInvalidates this session then unbinds any objects bound to it.booleanisAttributeDistributable(String name, Object value) Does the session implementation support the distributing of the given attribute?booleanisNew()Returnstrueif the client does not yet know about the session or if the client chooses not to join the session.booleanisValid()protected booleanprotected String[]keys()voidPerform the internal processing required to passivate this session.voidDeprecated.voidreadObjectData(ObjectInputStream stream) Read a serialized version of the contents of this session object from the specified object input stream, without requiring that the StandardSession itself have been serialized.voidrecycle()Release all object references, and initialize instance variables, in preparation for reuse of this object.voidremoveAttribute(String name) Removes the object bound with the specified name from this session.voidremoveAttribute(String name, boolean notify) Remove the object bound with the specified name from this session.protected voidremoveAttributeInternal(String name, boolean notify) Remove the object bound with the specified name from this session.voidremoveNote(String name) Remove any object bound to the specified name in the internal notes for this session.voidremoveSessionListener(SessionListener listener) Remove a session event listener from this component.voidremoveValue(String name) Deprecated.voidsetAttribute(String name, Object value) Binds an object to this session, using the name specified.voidsetAttribute(String name, Object value, boolean notify) Bind an object to this session, using the specified name.voidsetAuthType(String authType) Set the authentication type used to authenticate our cached Principal, if any.voidsetCreationTime(long time) Set the creation time for this session.voidSet the session identifier for this session and notifies any associated listeners that a new session has been created.voidSet the session identifier for this session and optionally notifies any associated listeners that a new session has been created.voidsetManager(Manager manager) Set the Manager within which this Session is valid.voidsetMaxInactiveInterval(int interval) Specifies the time, in seconds, between client requests before the servlet container will invalidate this session.voidsetNew(boolean isNew) Set theisNewflag for this session.voidBind an object to a specified name in the internal notes associated with this session, replacing any existing binding for this name.voidsetPrincipal(Principal principal) Set the authenticated Principal that is associated with this Session.voidsetValid(boolean isValid) Set theisValidflag for this session.voidtellChangedSessionId(String newId, String oldId, boolean notifySessionListeners, boolean notifyContainerListeners) Inform the listeners about the change session ID.voidtellNew()Inform the listeners about the new session.toString()voidwriteObjectData(ObjectOutputStream stream) Write a serialized version of the contents of this session object to the specified object output stream, without requiring that the StandardSession itself have been serialized.
- 
Field Details- 
STRICT_SERVLET_COMPLIANCEprotected static final boolean STRICT_SERVLET_COMPLIANCE
- 
ACTIVITY_CHECKprotected static final boolean ACTIVITY_CHECK
- 
LAST_ACCESS_AT_STARTprotected static final boolean LAST_ACCESS_AT_START
- 
EMPTY_ARRAYType array.
- 
attributesThe collection of user data attributes associated with this Session.
- 
authTypeThe authentication type used to authenticate our cached Principal, if any. NOTE: This value is not included in the serialized version of this object.
- 
creationTimeprotected long creationTimeThe time this session was created, in milliseconds since midnight, January 1, 1970 GMT.
- 
expiringprotected transient volatile boolean expiringWe are currently processing a session expiration, so bypass certain IllegalStateException tests. NOTE: This value is not included in the serialized version of this object.
- 
facadeThe facade associated with this session. NOTE: This value is not included in the serialized version of this object.
- 
idThe session identifier of this Session.
- 
lastAccessedTimeprotected volatile long lastAccessedTimeThe last accessed time for this Session.
- 
listenersThe session event listeners for this Session.
- 
managerThe Manager with which this Session is associated.
- 
maxInactiveIntervalprotected volatile int maxInactiveIntervalThe maximum time interval, in seconds, between client requests before the servlet container may invalidate this session. A negative time indicates that the session should never time out.
- 
isNewprotected volatile boolean isNewFlag indicating whether this session is new or not.
- 
isValidprotected volatile boolean isValidFlag indicating whether this session is valid or not.
- 
notesInternal notes associated with this session by Catalina components and event listeners. IMPLEMENTATION NOTE: This object is not saved and restored across session serializations!
- 
principalThe authenticated Principal associated with this session, if any. IMPLEMENTATION NOTE: This object is not saved and restored across session serializations!
- 
smThe string manager for this package.
- 
sessionContextDeprecated.The HTTP session context associated with this session.
- 
supportThe property change support for this component. NOTE: This value is not included in the serialized version of this object.
- 
thisAccessedTimeprotected volatile long thisAccessedTimeThe current accessed time for this session.
- 
accessCountThe access count for this session.
 
- 
- 
Constructor Details- 
StandardSessionConstruct a new Session associated with the specified Manager.- Parameters:
- manager- The manager with which this Session is associated
 
 
- 
- 
Method Details- 
getAuthType- Specified by:
- getAuthTypein interface- Session
- Returns:
- the authentication type used to authenticate our cached Principal, if any.
 
- 
setAuthTypeDescription copied from interface:SessionSet the authentication type used to authenticate our cached Principal, if any.- Specified by:
- setAuthTypein interface- Session
- Parameters:
- authType- The new cached authentication type
 
- 
setCreationTimepublic void setCreationTime(long time) Description copied from interface:SessionSet the creation time for this session. This method is called by the Manager when an existing Session instance is reused.- Specified by:
- setCreationTimein interface- Session
- Parameters:
- time- The new creation time
 
- 
getIdDescription copied from interface:javax.servlet.http.HttpSessionReturns a string containing the unique identifier assigned to this session. The identifier is assigned by the servlet container and is implementation dependent.- Specified by:
- getIdin interface- HttpSession
- Specified by:
- getIdin interface- Session
- Returns:
- a string specifying the identifier assigned to this session
 
- 
getIdInternal- Specified by:
- getIdInternalin interface- Session
- Returns:
- the session identifier for this session.
 
- 
setIdDescription copied from interface:SessionSet the session identifier for this session and notifies any associated listeners that a new session has been created.
- 
setIdDescription copied from interface:SessionSet the session identifier for this session and optionally notifies any associated listeners that a new session has been created.
- 
tellNewpublic void tellNew()Inform the listeners about the new session.
- 
tellChangedSessionIdpublic void tellChangedSessionId(String newId, String oldId, boolean notifySessionListeners, boolean notifyContainerListeners) Description copied from interface:SessionInform the listeners about the change session ID.- Specified by:
- tellChangedSessionIdin interface- Session
- Parameters:
- newId- new session ID
- oldId- old session ID
- notifySessionListeners- Should any associated sessionListeners be notified that session ID has been changed?
- notifyContainerListeners- Should any associated ContainerListeners be notified that session ID has been changed?
 
- 
getThisAccessedTimepublic long getThisAccessedTime()- Specified by:
- getThisAccessedTimein interface- Session
- 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. This one gets updated whenever a request starts.
 
- 
getThisAccessedTimeInternalpublic long getThisAccessedTimeInternal()- Specified by:
- getThisAccessedTimeInternalin interface- Session
- Returns:
- the last client access time without invalidation check
- See Also:
 
- 
getLastAccessedTimepublic long getLastAccessedTime()Description copied from interface:javax.servlet.http.HttpSessionReturns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT, and marked by the time the container received the request.Actions that your application takes, such as getting or setting a value associated with the session, do not affect the access time. - Specified by:
- getLastAccessedTimein interface- HttpSession
- Specified by:
- getLastAccessedTimein interface- Session
- Returns:
- a longrepresenting the last time the client sent a request associated with this session, expressed in milliseconds since 1/1/1970 GMT
 
- 
getLastAccessedTimeInternalpublic long getLastAccessedTimeInternal()- Specified by:
- getLastAccessedTimeInternalin interface- Session
- Returns:
- the last client access time without invalidation check
- See Also:
 
- 
getIdleTimepublic long getIdleTime()- Specified by:
- getIdleTimein interface- Session
- Returns:
- the idle time (in milliseconds) from last client access time.
 
- 
getIdleTimeInternalpublic long getIdleTimeInternal()- Specified by:
- getIdleTimeInternalin interface- Session
- Returns:
- the idle time from last client access time without invalidation check
- See Also:
 
- 
getManager- Specified by:
- getManagerin interface- Session
- Returns:
- the Manager within which this Session is valid.
 
- 
setManagerDescription copied from interface:SessionSet the Manager within which this Session is valid.- Specified by:
- setManagerin interface- Session
- Parameters:
- manager- The new Manager
 
- 
getMaxInactiveIntervalpublic int getMaxInactiveInterval()Description copied from interface:javax.servlet.http.HttpSessionReturns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. After this interval, the servlet container will invalidate the session. The maximum time interval can be set with thesetMaxInactiveIntervalmethod. A zero or negative time indicates that the session should never timeout.- Specified by:
- getMaxInactiveIntervalin interface- HttpSession
- Specified by:
- getMaxInactiveIntervalin interface- Session
- Returns:
- an integer specifying the number of seconds this session remains open between client requests
- See Also:
 
- 
setMaxInactiveIntervalpublic void setMaxInactiveInterval(int interval) Description copied from interface:javax.servlet.http.HttpSessionSpecifies the time, in seconds, between client requests before the servlet container will invalidate this session. A zero or negative time indicates that the session should never timeout.- Specified by:
- setMaxInactiveIntervalin interface- HttpSession
- Specified by:
- setMaxInactiveIntervalin interface- Session
- Parameters:
- interval- An integer specifying the number of seconds
 
- 
setNewpublic void setNew(boolean isNew) Description copied from interface:SessionSet theisNewflag for this session.
- 
getPrincipal- Specified by:
- getPrincipalin interface- Session
- Returns:
- the authenticated Principal that is associated with this Session. This provides an
             Authenticatorwith a means to cache a previously authenticated Principal, and avoid potentially expensiveRealm.authenticate()calls on every request. If there is no current associated Principal, returnnull.
 
- 
setPrincipalDescription copied from interface:SessionSet the authenticated Principal that is associated with this Session. This provides anAuthenticatorwith a means to cache a previously authenticated Principal, and avoid potentially expensiveRealm.authenticate()calls on every request.- Specified by:
- setPrincipalin interface- Session
- Parameters:
- principal- The new Principal, or- nullif none
 
- 
getSession- Specified by:
- getSessionin interface- Session
- Returns:
- the HttpSessionfor which this object is the facade.
 
- 
isValidpublic boolean isValid()
- 
setValidpublic void setValid(boolean isValid) Description copied from interface:SessionSet theisValidflag for this session.
- 
accesspublic void access()Description copied from interface:SessionUpdate the accessed time information for this session. This method should be called by the context when a request comes in for a particular session, even if the application does not reference it.
- 
endAccesspublic void endAccess()Description copied from interface:SessionEnd access to the session.
- 
addSessionListenerDescription copied from interface:SessionAdd a session event listener to this component.- Specified by:
- addSessionListenerin interface- Session
- Parameters:
- listener- the SessionListener instance that should be notified for session events
 
- 
expirepublic void expire()Description copied from interface:SessionPerform the internal processing required to invalidate this session, without triggering an exception if the session has already expired.
- 
expirepublic void expire(boolean notify) Perform the internal processing required to invalidate this session, without triggering an exception if the session has already expired.- Parameters:
- notify- Should we notify listeners about the demise of this session?
 
- 
passivatepublic void passivate()Perform the internal processing required to passivate this session.
- 
activatepublic void activate()Perform internal processing required to activate this session.
- 
getNote
- 
getNoteNames- Specified by:
- getNoteNamesin interface- Session
- Returns:
- an Iterator containing the String names of all notes bindings that exist for this session.
 
- 
recyclepublic void recycle()Description copied from interface:SessionRelease all object references, and initialize instance variables, in preparation for reuse of this object.
- 
removeNoteDescription copied from interface:SessionRemove any object bound to the specified name in the internal notes for this session.- Specified by:
- removeNotein interface- Session
- Parameters:
- name- Name of the note to be removed
 
- 
removeSessionListenerDescription copied from interface:SessionRemove a session event listener from this component.- Specified by:
- removeSessionListenerin interface- Session
- Parameters:
- listener- remove the session listener, which will no longer be notified
 
- 
setNoteDescription copied from interface:SessionBind an object to a specified name in the internal notes associated with this session, replacing any existing binding for this name.
- 
toString
- 
readObjectDataRead a serialized version of the contents of this session object from the specified object input stream, without requiring that the StandardSession itself have been serialized.- Parameters:
- stream- The object input stream to read from
- Throws:
- ClassNotFoundException- if an unknown class is specified
- IOException- if an input/output error occurs
 
- 
writeObjectDataWrite a serialized version of the contents of this session object to the specified object output stream, without requiring that the StandardSession itself have been serialized.- Parameters:
- stream- The object output stream to write to
- Throws:
- IOException- if an input/output error occurs
 
- 
getCreationTimepublic long getCreationTime()Description copied from interface:javax.servlet.http.HttpSessionReturns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.- Specified by:
- getCreationTimein interface- HttpSession
- Specified by:
- getCreationTimein interface- Session
- Returns:
- a longspecifying when this session was created, expressed in milliseconds since 1/1/1970 GMT
 
- 
getCreationTimeInternalpublic long getCreationTimeInternal()- Specified by:
- getCreationTimeInternalin interface- Session
- Returns:
- the creation time for this session, bypassing the session validity checks.
 
- 
getServletContextDescription copied from interface:javax.servlet.http.HttpSessionReturns the ServletContext to which this session belongs.- Specified by:
- getServletContextin interface- HttpSession
- Returns:
- The ServletContext object for the web application
 
- 
getSessionContextDeprecated.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.Return the session context with which this session is associated.- Specified by:
- getSessionContextin interface- HttpSession
- Returns:
- A dummy implementation of HttpSessionContext
 
- 
getAttributeDescription copied from interface:javax.servlet.http.HttpSessionReturns the object bound with the specified name in this session, ornullif no object is bound under the name.- Specified by:
- getAttributein interface- HttpSession
- Parameters:
- name- a string specifying the name of the object
- Returns:
- the object with the specified name
 
- 
getAttributeNamesDescription copied from interface:javax.servlet.http.HttpSessionReturns anEnumerationofStringobjects containing the names of all the objects bound to this session.- Specified by:
- getAttributeNamesin interface- HttpSession
- Returns:
- an EnumerationofStringobjects specifying the names of all the objects bound to this session
 
- 
getValueDeprecated.- Specified by:
- getValuein interface- HttpSession
- Parameters:
- name- a string specifying the name of the object
- Returns:
- the object with the specified name
 
- 
getValueNamesDeprecated.- Specified by:
- getValueNamesin interface- HttpSession
- Returns:
- an array of Stringobjects specifying the names of all the objects bound to this session
 
- 
invalidatepublic void invalidate()Description copied from interface:javax.servlet.http.HttpSessionInvalidates this session then unbinds any objects bound to it.- Specified by:
- invalidatein interface- HttpSession
 
- 
isNewpublic boolean isNew()Description copied from interface:javax.servlet.http.HttpSessionReturnstrueif 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:
- isNewin interface- HttpSession
- Returns:
- trueif the server has created a session, but the client has not yet joined
 
- 
putValueDeprecated.- Specified by:
- putValuein interface- HttpSession
- Parameters:
- name- the name to which the object is bound; cannot be null
- value- the object to be bound; cannot be null
 
- 
removeAttributeDescription copied from interface:javax.servlet.http.HttpSessionRemoves 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.After this method executes, and if the object implements HttpSessionBindingListener, the container callsHttpSessionBindingListener.valueUnbound. The container then notifies anyHttpSessionAttributeListeners in the web application.- Specified by:
- removeAttributein interface- HttpSession
- Parameters:
- name- the name of the object to remove from this session
 
- 
removeAttributeRemove the object bound with the specified name from this session. If the session does not have an object bound with this name, this method does nothing.After this method executes, and if the object implements HttpSessionBindingListener, the container callsvalueUnbound()on the object.- Parameters:
- name- Name of the object to remove from this session.
- notify- Should we notify interested listeners that this attribute is being removed?
- Throws:
- IllegalStateException- if this method is called on an invalidated session
 
- 
removeValueDeprecated.- Specified by:
- removeValuein interface- HttpSession
- Parameters:
- name- the name of the object to remove from this session
 
- 
setAttributeDescription copied from interface:javax.servlet.http.HttpSessionBinds 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.After this method executes, and if the new object implements HttpSessionBindingListener, the container callsHttpSessionBindingListener.valueBound. The container then notifies anyHttpSessionAttributeListeners in the web application.If an object was already bound to this session of this name that implements HttpSessionBindingListener, itsHttpSessionBindingListener.valueUnboundmethod is called.If the value passed in is null, this has the same effect as calling removeAttribute().- Specified by:
- setAttributein interface- HttpSession
- Parameters:
- name- the name to which the object is bound; cannot be null
- value- the object to be bound
 
- 
setAttributeBind an object to this session, using the specified name. If an object of the same name is already bound to this session, the object is replaced.After this method executes, and if the object implements HttpSessionBindingListener, the container callsvalueBound()on the object.- Parameters:
- name- Name to which the object is bound, cannot be null
- value- Object to be bound, cannot be null
- notify- whether to notify session listeners
- Throws:
- IllegalArgumentException- if an attempt is made to add a non-serializable object in an environment marked distributable.
- IllegalStateException- if this method is called on an invalidated session
 
- 
isValidInternalprotected boolean isValidInternal()- Returns:
- the isValidflag for this session without any expiration check.
 
- 
isAttributeDistributableDoes the session implementation support the distributing of the given attribute? If the Manager is marked as distributable, then this method must be used to check attributes before adding them to a session and anIllegalArgumentExceptionthrown if the proposed attribute is not distributable.Note that the Managerimplementation may further restrict which attributes are distributed but aManagerlevel restriction should not trigger anIllegalArgumentExceptioninHttpSession.setAttribute(String, Object)This implementation simply checks the value for serializability. Sub-classes might use other distribution technology not based on serialization and can override this check. - Specified by:
- isAttributeDistributablein interface- Session
- Parameters:
- name- The attribute name
- value- The attribute value
- Returns:
- trueif distribution is supported, otherwise- false
 
- 
doReadObjectRead a serialized version of this session object from the specified object input stream.IMPLEMENTATION NOTE: The reference to the owning Manager is not restored by this method, and must be set explicitly. - Parameters:
- stream- The input stream to read from
- Throws:
- ClassNotFoundException- if an unknown class is specified
- IOException- if an input/output error occurs
 
- 
doWriteObjectWrite a serialized version of this session object to the specified object output stream.IMPLEMENTATION NOTE: The owning Manager will not be stored in the serialized representation of this Session. After calling readObject(), you must set the associated Manager explicitly.IMPLEMENTATION NOTE: Any attribute that is not Serializable will be unbound from the session, with appropriate actions if it implements HttpSessionBindingListener. If you do not want any such attributes, be sure the distributableproperty of the associated Manager is set totrue.- Parameters:
- stream- The output stream to write to
- Throws:
- IOException- if an input/output error occurs
 
- 
excludeShould the given session attribute be excluded? This implementation checks: Note: This method deliberately does not checkisAttributeDistributable(String, Object)which is kept separate to support the checks required insetAttribute(String, Object, boolean)- Parameters:
- name- The attribute name
- value- The attribute value
- Returns:
- trueif the attribute should be excluded from distribution, otherwise- false
 
- 
fireSessionEventNotify all session event listeners that a particular event has occurred for this Session. The default implementation performs this notification synchronously using the calling thread.- Parameters:
- type- Event type
- data- Event data
 
- 
keys- Returns:
- the names of all currently defined session attributes as an array of Strings. If there are no defined attributes, a zero-length array is returned.
 
- 
removeAttributeInternalRemove the object bound with the specified name from this session. If the session does not have an object bound with this name, this method does nothing.After this method executes, and if the object implements HttpSessionBindingListener, the container callsvalueUnbound()on the object.- Parameters:
- name- Name of the object to remove from this session.
- notify- Should we notify interested listeners that this attribute is being removed?
 
 
-