public class HttpSessionImpl
extends java.lang.Object
implements javax.servlet.http.HttpSession, java.io.Serializable
Modifier and Type | Field and Description |
---|---|
private java.util.HashMap |
attributes
The collection of user data attributes associated with this Session.
|
private java.lang.String |
authType
The authentication type used to authenticate our cached Principal,
if any.
|
private long |
creationTime
The time this session was created, in milliseconds since midnight,
January 1, 1970 GMT.
|
private int |
debug
The debugging detail level for this component.
|
private boolean |
distributable
Is this session distributable.
|
private boolean |
expiring
We are currently processing a session expiration, so bypass
certain IllegalStateException tests.
|
private java.lang.String |
id
The session identifier of this Session.
|
private boolean |
isNew
Flag indicating whether this session is new or not.
|
private boolean |
isValid
Flag indicating whether this session is valid or not.
|
private long |
lastAccessedTime
The last accessed time for this Session.
|
private java.util.ArrayList |
listeners
The session event listeners for this Session.
|
private int |
maxInactiveInterval
The maximum time interval, in seconds, between client requests before
the servlet container may invalidate this session.
|
private static java.lang.String |
NOT_SERIALIZED
The dummy attribute value serialized when a NotSerializableException is
encountered in
writeObject() . |
private java.util.HashMap |
notes
Internal notes associated with this session by Catalina components
and event listeners.
|
private java.security.Principal |
principal
The authenticated Principal associated with this session, if any.
|
protected javax.servlet.ServletContext |
servletContext
The ServletContext
|
private java.beans.PropertyChangeSupport |
support
The property change support for this component.
|
private long |
thisAccessedTime
The current accessed time for this session.
|
Constructor and Description |
---|
HttpSessionImpl(javax.servlet.ServletContext servletContext) |
Modifier and Type | Method and Description |
---|---|
void |
access()
Update the accessed time information for this session.
|
void |
activate()
Perform internal processing required to activate this
session.
|
void |
expire()
Perform the internal processing required to invalidate this session,
without triggering an exception if the session has already expired.
|
void |
fireSessionEvent(java.lang.String type,
java.lang.Object data)
Notify all session event listeners that a particular event has
occurred for this Session.
|
java.lang.Object |
getAttribute(java.lang.String name)
Return the object bound with the specified name in this session, or
null if no object is bound with that name. |
java.util.Enumeration |
getAttributeNames()
Return an
Enumeration of String objects
containing the names of the objects bound to this session. |
java.lang.String |
getAuthType()
Return the authentication type used to authenticate our cached
Principal, if any.
|
long |
getCreationTime()
Return the time when this session was created, in milliseconds since
midnight, January 1, 1970 GMT.
|
java.lang.String |
getId()
Return the session identifier for this session.
|
long |
getLastAccessedTime()
Return the last time the client sent a request associated with this
session, as the number of milliseconds since midnight, January 1, 1970
GMT.
|
int |
getMaxInactiveInterval()
Return the maximum time interval, in seconds, between client requests
before the servlet container will invalidate the session.
|
java.lang.Object |
getNote(java.lang.String name)
Return the object bound with the specified name to the internal notes
for this session, or
null if no such binding exists. |
java.util.Iterator |
getNoteNames()
Return an Iterator containing the String names of all notes bindings
that exist for this session.
|
java.security.Principal |
getPrincipal()
Return the authenticated Principal that is associated with this Session.
|
javax.servlet.ServletContext |
getServletContext()
Return the ServletContext to which this session belongs.
|
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.
|
java.lang.Object |
getValue(java.lang.String name)
Deprecated.
As of Version 2.2, this method is replaced by
getAttribute() |
java.lang.String[] |
getValueNames()
Deprecated.
As of Version 2.2, this method is replaced by
getAttributeNames() |
void |
invalidate()
Invalidates this session and unbinds any objects bound to it.
|
boolean |
isNew()
Return
true if the client does not yet know about the
session, or if the client chooses not to join the session. |
boolean |
isValid()
Return the
isValid flag for this session. |
private java.lang.String[] |
keys()
Return the names of all currently defined session attributes
as an array of Strings.
|
protected void |
log(java.lang.String message)
Log a message to the current ServletContext
|
protected void |
log(java.lang.String message,
java.lang.Throwable throwable)
Log a message to the current ServletContext
|
void |
passivate()
Perform the internal processing required to passivate
this session.
|
void |
putValue(java.lang.String name,
java.lang.Object value)
Deprecated.
As of Version 2.2, this method is replaced by
setAttribute() |
private void |
readObject(java.io.ObjectInputStream stream)
Read a serialized version of this session object from the specified
object input stream.
|
(package private) void |
readObjectData(java.io.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.
|
void |
recycle()
Release all object references, and initialize instance variables, in
preparation for reuse of this object.
|
void |
removeAttribute(java.lang.String name)
Remove the object bound with the specified name from this session.
|
void |
removeNote(java.lang.String name)
Remove any object bound to the specified name in the internal notes
for this session.
|
void |
removeValue(java.lang.String name)
Deprecated.
As of Version 2.2, this method is replaced by
removeAttribute() |
void |
setAttribute(java.lang.String name,
java.lang.Object value)
Bind an object to this session, using the specified name.
|
void |
setAuthType(java.lang.String authType)
Set the authentication type used to authenticate our cached
Principal, if any.
|
void |
setCreationTime(long time)
Set the creation time for this session.
|
void |
setId(java.lang.String id)
Set the session identifier for this session.
|
void |
setMaxInactiveInterval(int interval)
Set the maximum time interval, in seconds, between client requests
before the servlet container will invalidate the session.
|
void |
setNew(boolean isNew)
Set the
isNew flag for this session. |
void |
setNote(java.lang.String name,
java.lang.Object value)
Bind an object to a specified name in the internal notes associated
with this session, replacing any existing binding for this name.
|
void |
setPrincipal(java.security.Principal principal)
Set the authenticated Principal that is associated with this Session.
|
void |
setValid(boolean isValid)
Set the
isValid flag for this session. |
java.lang.String |
toString()
Return a string representation of this object.
|
private void |
writeObject(java.io.ObjectOutputStream stream)
Write a serialized version of this session object to the specified
object output stream.
|
(package private) void |
writeObjectData(java.io.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.
|
private static final java.lang.String NOT_SERIALIZED
writeObject()
.private java.util.HashMap attributes
private transient java.lang.String authType
private long creationTime
private transient int debug
private transient boolean expiring
private java.lang.String id
private long lastAccessedTime
private transient java.util.ArrayList listeners
private int maxInactiveInterval
private boolean isNew
private boolean isValid
private transient java.util.HashMap notes
private transient java.security.Principal principal
private transient java.beans.PropertyChangeSupport support
private long thisAccessedTime
protected javax.servlet.ServletContext servletContext
private boolean distributable
public HttpSessionImpl(javax.servlet.ServletContext servletContext)
public java.lang.String getAuthType()
public void setAuthType(java.lang.String authType)
authType
- The new cached authentication typepublic void setCreationTime(long time)
time
- The new creation timepublic java.lang.String getId()
getId
in interface javax.servlet.http.HttpSession
public void setId(java.lang.String id)
id
- The new session identifierpublic long getLastAccessedTime()
getLastAccessedTime
in interface javax.servlet.http.HttpSession
public int getMaxInactiveInterval()
getMaxInactiveInterval
in interface javax.servlet.http.HttpSession
java.lang.IllegalStateException
- if this method is called on
an invalidated sessionpublic void setMaxInactiveInterval(int interval)
setMaxInactiveInterval
in interface javax.servlet.http.HttpSession
interval
- The new maximum intervalpublic void setNew(boolean isNew)
isNew
flag for this session.isNew
- The new value for the isNew
flagpublic java.security.Principal getPrincipal()
Authenticator
with a means to cache a
previously authenticated Principal, and avoid potentially expensive
Realm.authenticate()
calls on every request. If there
is no current associated Principal, return null
.public void setPrincipal(java.security.Principal principal)
Authenticator
with a means to cache a
previously authenticated Principal, and avoid potentially expensive
Realm.authenticate()
calls on every request.principal
- The new Principal, or null
if nonepublic boolean isValid()
isValid
flag for this session.public void setValid(boolean isValid)
isValid
flag for this session.isValid
- The new value for the isValid
flagpublic void access()
public void expire()
public void passivate()
public void activate()
public java.lang.Object getNote(java.lang.String name)
null
if no such binding exists.name
- Name of the note to be returnedpublic java.util.Iterator getNoteNames()
public void recycle()
public void removeNote(java.lang.String name)
name
- Name of the note to be removedpublic void setNote(java.lang.String name, java.lang.Object value)
name
- Name to which the object should be boundvalue
- Object to be bound to the specified namepublic java.lang.String toString()
toString
in class java.lang.Object
void readObjectData(java.io.ObjectInputStream stream) throws java.lang.ClassNotFoundException, java.io.IOException
stream
- The object input stream to read fromjava.lang.ClassNotFoundException
- if an unknown class is specifiedjava.io.IOException
- if an input/output error occursvoid writeObjectData(java.io.ObjectOutputStream stream) throws java.io.IOException
stream
- The object output stream to write tojava.io.IOException
- if an input/output error occurspublic long getCreationTime()
getCreationTime
in interface javax.servlet.http.HttpSession
java.lang.IllegalStateException
- if this method is called on an
invalidated sessionpublic javax.servlet.ServletContext getServletContext()
getServletContext
in interface javax.servlet.http.HttpSession
public javax.servlet.http.HttpSessionContext getSessionContext()
getSessionContext
in interface javax.servlet.http.HttpSession
public java.lang.Object getAttribute(java.lang.String name)
null
if no object is bound with that name.getAttribute
in interface javax.servlet.http.HttpSession
name
- Name of the attribute to be returnedjava.lang.IllegalStateException
- if this method is called on an
invalidated sessionpublic java.util.Enumeration getAttributeNames()
Enumeration
of String
objects
containing the names of the objects bound to this session.getAttributeNames
in interface javax.servlet.http.HttpSession
java.lang.IllegalStateException
- if this method is called on an
invalidated sessionpublic java.lang.Object getValue(java.lang.String name)
getAttribute()
null
if no object is bound with that name.getValue
in interface javax.servlet.http.HttpSession
name
- Name of the value to be returnedjava.lang.IllegalStateException
- if this method is called on an
invalidated sessionpublic java.lang.String[] getValueNames()
getAttributeNames()
getValueNames
in interface javax.servlet.http.HttpSession
java.lang.IllegalStateException
- if this method is called on an
invalidated sessionpublic void invalidate()
invalidate
in interface javax.servlet.http.HttpSession
java.lang.IllegalStateException
- if this method is called on
an invalidated sessionpublic boolean isNew()
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
has disabled the use of cookies, then a session would be new on each
request.isNew
in interface javax.servlet.http.HttpSession
java.lang.IllegalStateException
- if this method is called on an
invalidated sessionpublic void putValue(java.lang.String name, java.lang.Object value)
setAttribute()
After this method executes, and if the object implements
HttpSessionBindingListener
, the container calls
valueBound()
on the object.
putValue
in interface javax.servlet.http.HttpSession
name
- Name to which the object is bound, cannot be nullvalue
- Object to be bound, cannot be nulljava.lang.IllegalStateException
- if this method is called on an
invalidated sessionpublic void removeAttribute(java.lang.String name)
After this method executes, and if the object implements
HttpSessionBindingListener
, the container calls
valueUnbound()
on the object.
removeAttribute
in interface javax.servlet.http.HttpSession
name
- Name of the object to remove from this session.java.lang.IllegalStateException
- if this method is called on an
invalidated sessionpublic void removeValue(java.lang.String name)
removeAttribute()
After this method executes, and if the object implements
HttpSessionBindingListener
, the container calls
valueUnbound()
on the object.
removeValue
in interface javax.servlet.http.HttpSession
name
- Name of the object to remove from this session.java.lang.IllegalStateException
- if this method is called on an
invalidated sessionpublic void setAttribute(java.lang.String name, java.lang.Object value)
After this method executes, and if the object implements
HttpSessionBindingListener
, the container calls
valueBound()
on the object.
setAttribute
in interface javax.servlet.http.HttpSession
name
- Name to which the object is bound, cannot be nullvalue
- Object to be bound, cannot be nulljava.lang.IllegalArgumentException
- if an attempt is made to add a
non-serializable object in an environment marked distributable.java.lang.IllegalStateException
- if this method is called on an
invalidated sessionprivate void readObject(java.io.ObjectInputStream stream) throws java.lang.ClassNotFoundException, java.io.IOException
IMPLEMENTATION NOTE: The reference to the owning Manager is not restored by this method, and must be set explicitly.
stream
- The input stream to read fromjava.lang.ClassNotFoundException
- if an unknown class is specifiedjava.io.IOException
- if an input/output error occursprivate void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException
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 distributable
property of the
associated Manager is set to true
.
stream
- The output stream to write tojava.io.IOException
- if an input/output error occurspublic void fireSessionEvent(java.lang.String type, java.lang.Object data)
type
- Event typedata
- Event dataprivate java.lang.String[] keys()
protected void log(java.lang.String message)
message
- Message to be loggedprotected void log(java.lang.String message, java.lang.Throwable throwable)
message
- Message to be loggedthrowable
- Associated exception