org.apache.commons.messagelet.impl
Class HttpSessionImpl

java.lang.Object
  extended by org.apache.commons.messagelet.impl.HttpSessionImpl
All Implemented Interfaces:
Serializable, javax.servlet.http.HttpSession

public class HttpSessionImpl
extends Object
implements javax.servlet.http.HttpSession, Serializable

Based on the Catalina StandardSession class. Standard implementation of the HttpSession interface. This object is serializable, so that it can be stored in persistent storage or transferred to a different JVM for distributable session support.

Version:
$Revision: 155459 $ $Date: 2005-02-26 13:24:44 +0000 (Sat, 26 Feb 2005) $
Author:
Craig R. McClanahan, Sean Legassick, Jon S. Stevens, James Strachan
See Also:
Serialized Form

Field Summary
protected  javax.servlet.ServletContext servletContext
          The ServletContext
 
Constructor Summary
HttpSessionImpl(javax.servlet.ServletContext servletContext)
           
 
Method Summary
 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(String type, Object data)
          Notify all session event listeners that a particular event has occurred for this Session.
 Object getAttribute(String name)
          Return the object bound with the specified name in this session, or null if no object is bound with that name.
 Enumeration getAttributeNames()
          Return an Enumeration of String objects containing the names of the objects bound to this session.
 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.
 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.
 Object getNote(String name)
          Return the object bound with the specified name to the internal notes for this session, or null if no such binding exists.
 Iterator getNoteNames()
          Return an Iterator containing the String names of all notes bindings that exist for this session.
 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.
 Object getValue(String name)
          Deprecated. As of Version 2.2, this method is replaced by getAttribute()
 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.
protected  void log(String message)
          Log a message to the current ServletContext
protected  void log(String message, Throwable throwable)
          Log a message to the current ServletContext
 void passivate()
          Perform the internal processing required to passivate this session.
 void putValue(String name, Object value)
          Deprecated. As of Version 2.2, this method is replaced by setAttribute()
 void recycle()
          Release all object references, and initialize instance variables, in preparation for reuse of this object.
 void removeAttribute(String name)
          Remove the object bound with the specified name from this session.
 void removeNote(String name)
          Remove any object bound to the specified name in the internal notes for this session.
 void removeValue(String name)
          Deprecated. As of Version 2.2, this method is replaced by removeAttribute()
 void setAttribute(String name, Object value)
          Bind an object to this session, using the specified name.
 void setAuthType(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(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(String name, 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(Principal principal)
          Set the authenticated Principal that is associated with this Session.
 void setValid(boolean isValid)
          Set the isValid flag for this session.
 String toString()
          Return a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

servletContext

protected javax.servlet.ServletContext servletContext
The ServletContext

Constructor Detail

HttpSessionImpl

public HttpSessionImpl(javax.servlet.ServletContext servletContext)
Method Detail

getAuthType

public String getAuthType()
Return the authentication type used to authenticate our cached Principal, if any.


setAuthType

public void setAuthType(String authType)
Set the authentication type used to authenticate our cached Principal, if any.

Parameters:
authType - The new cached authentication type

setCreationTime

public void setCreationTime(long time)
Set the creation time for this session. This method is called by the Manager when an existing Session instance is reused.

Parameters:
time - The new creation time

getId

public String getId()
Return the session identifier for this session.

Specified by:
getId in interface javax.servlet.http.HttpSession

setId

public void setId(String id)
Set the session identifier for this session.

Parameters:
id - The new session identifier

getLastAccessedTime

public 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. 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

getMaxInactiveInterval

public int getMaxInactiveInterval()
Return 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
Throws:
IllegalStateException - if this method is called on an invalidated session

setMaxInactiveInterval

public void setMaxInactiveInterval(int interval)
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:
interval - The new maximum interval

setNew

public void setNew(boolean isNew)
Set the isNew flag for this session.

Parameters:
isNew - The new value for the isNew flag

getPrincipal

public Principal getPrincipal()
Return the authenticated Principal that is associated with this Session. This provides an 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.


setPrincipal

public void setPrincipal(Principal principal)
Set the authenticated Principal that is associated with this Session. This provides an Authenticator with a means to cache a previously authenticated Principal, and avoid potentially expensive Realm.authenticate() calls on every request.

Parameters:
principal - The new Principal, or null if none

isValid

public boolean isValid()
Return the isValid flag for this session.


setValid

public void setValid(boolean isValid)
Set the isValid flag for this session.

Parameters:
isValid - The new value for the isValid flag

access

public void access()
Update 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.


expire

public void expire()
Perform the internal processing required to invalidate this session, without triggering an exception if the session has already expired.


passivate

public void passivate()
Perform the internal processing required to passivate this session.


activate

public void activate()
Perform internal processing required to activate this session.


getNote

public Object getNote(String name)
Return the object bound with the specified name to the internal notes for this session, or null if no such binding exists.

Parameters:
name - Name of the note to be returned

getNoteNames

public Iterator getNoteNames()
Return an Iterator containing the String names of all notes bindings that exist for this session.


recycle

public void recycle()
Release all object references, and initialize instance variables, in preparation for reuse of this object.


removeNote

public void removeNote(String name)
Remove any object bound to the specified name in the internal notes for this session.

Parameters:
name - Name of the note to be removed

setNote

public void setNote(String name,
                    Object value)
Bind an object to a specified name in the internal notes associated with this session, replacing any existing binding for this name.

Parameters:
name - Name to which the object should be bound
value - Object to be bound to the specified name

toString

public String toString()
Return a string representation of this object.

Overrides:
toString in class Object

getCreationTime

public long getCreationTime()
Return the time when this session was created, in milliseconds since midnight, January 1, 1970 GMT.

Specified by:
getCreationTime in interface javax.servlet.http.HttpSession
Throws:
IllegalStateException - if this method is called on an invalidated session

getServletContext

public javax.servlet.ServletContext getServletContext()
Return the ServletContext to which this session belongs.

Specified by:
getServletContext in interface javax.servlet.http.HttpSession

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.

Return the session context with which this session is associated.

Specified by:
getSessionContext in interface javax.servlet.http.HttpSession

getAttribute

public Object getAttribute(String name)
Return the object bound with the specified name in this session, or null if no object is bound with that name.

Specified by:
getAttribute in interface javax.servlet.http.HttpSession
Parameters:
name - Name of the attribute to be returned
Throws:
IllegalStateException - if this method is called on an invalidated session

getAttributeNames

public Enumeration getAttributeNames()
Return an Enumeration of String objects containing the names of the objects bound to this session.

Specified by:
getAttributeNames in interface javax.servlet.http.HttpSession
Throws:
IllegalStateException - if this method is called on an invalidated session

getValue

public Object getValue(String name)
Deprecated. As of Version 2.2, this method is replaced by getAttribute()

Return the object bound with the specified name in this session, or null if no object is bound with that name.

Specified by:
getValue in interface javax.servlet.http.HttpSession
Parameters:
name - Name of the value to be returned
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()

Return the set of names of objects bound to this session. If there are no such objects, a zero-length array is returned.

Specified by:
getValueNames in interface javax.servlet.http.HttpSession
Throws:
IllegalStateException - if this method is called on an invalidated session

invalidate

public void invalidate()
Invalidates this session and unbinds any objects bound to it.

Specified by:
invalidate in interface javax.servlet.http.HttpSession
Throws:
IllegalStateException - if this method is called on an invalidated session

isNew

public boolean isNew()
Return 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.

Specified by:
isNew in interface javax.servlet.http.HttpSession
Throws:
IllegalStateException - if this method is called on an invalidated session

putValue

public void putValue(String name,
                     Object value)
Deprecated. As of Version 2.2, this method is replaced by setAttribute()

Bind 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 calls valueBound() on the object.

Specified by:
putValue in interface javax.servlet.http.HttpSession
Parameters:
name - Name to which the object is bound, cannot be null
value - Object to be bound, cannot be null
Throws:
IllegalStateException - if this method is called on an invalidated session

removeAttribute

public void removeAttribute(String name)
Remove 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 calls valueUnbound() on the object.

Specified by:
removeAttribute in interface javax.servlet.http.HttpSession
Parameters:
name - 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 name)
Deprecated. As of Version 2.2, this method is replaced by removeAttribute()

Remove 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 calls valueUnbound() on the object.

Specified by:
removeValue in interface javax.servlet.http.HttpSession
Parameters:
name - 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 name,
                         Object value)
Bind 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 calls valueBound() on the object.

Specified by:
setAttribute in interface javax.servlet.http.HttpSession
Parameters:
name - Name to which the object is bound, cannot be null
value - Object to be bound, cannot be null
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

fireSessionEvent

public void fireSessionEvent(String type,
                             Object data)
Notify 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

log

protected void log(String message)
Log a message to the current ServletContext

Parameters:
message - Message to be logged

log

protected void log(String message,
                   Throwable throwable)
Log a message to the current ServletContext

Parameters:
message - Message to be logged
throwable - Associated exception


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.