Expresso 5-6

com.jcorporate.expresso.core.controller.session
Class HTTPPersistentSession

java.lang.Object
  extended bycom.jcorporate.expresso.core.controller.session.HTTPPersistentSession
All Implemented Interfaces:
PersistentSession, Serializable

public class HTTPPersistentSession
extends Object
implements PersistentSession

A HTTPPersistentSession is simply a place to stash some values between states of a controller object. Different environments may employ different ways of doing this - the simplest being this one, where a hashtable does all the required work.

A servlet environment must use HTTPPersistentSession, which stores it's values in the HTTPSession for storage from one invokation to the next.

If you are inside a controller environment, then call ControllerRequest.getSession() to get a PersistentSession object, and do not install this class directly. See the PersistentSession javadoc documentation for an example usage of this class

Since:
Expresso 4.0
Author:
Michael Nash
See Also:
PersistentSession, Serialized Form

Constructor Summary
HTTPPersistentSession()
          Creates new HTTPPersistentSession
HTTPPersistentSession(HttpServletRequest req, HttpServletResponse res)
          Creates new HTTPPersistentSession and set the request object in one step
 
Method Summary
 Object getAttribute(String attribName)
          Retrieves the object from the request context.
 Enumeration getAttributeNames()
          Retrieves all attribute names in the request context.
 String getClientAttribute(String attribName)
          Retrieves a value of a cookie set on the client's system.
 Enumeration getPeristentAttributeNames()
          Retrieves all attribute names from the session context.
 Object getPersistentAttribute(String attribName)
          Retrieves the object from the session context.
 void invalidate()
          Clear out the session.
 void removeAttribute(String attribName)
          Clears an attribute from the request context
 void removePersistentAttribute(String attribName)
          Clears an attribute from the session context
 void setAttribute(String attribName, Object attribValue)
          Sets an attribute on the Servlet request
 void setClientAttribute(String attribName, String attribValue)
          Sets a cookie in the client's system.
 void setPersistentAttribute(String attribName, Object attribValue)
          Saves an attribute to the actual session, rather than simply the response.
 void setRequest(HttpServletRequest req)
          Set the request object so we can get to the session.
 void setResponse(HttpServletResponse res)
          Set the response object so we can get to all the http objects we need.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTTPPersistentSession

public HTTPPersistentSession()
Creates new HTTPPersistentSession


HTTPPersistentSession

public HTTPPersistentSession(HttpServletRequest req,
                             HttpServletResponse res)
Creates new HTTPPersistentSession and set the request object in one step

Parameters:
req - a HttpServletRequest object
res - a HttpServletResponse object
Method Detail

setAttribute

public void setAttribute(String attribName,
                         Object attribValue)
Sets an attribute on the Servlet request

Specified by:
setAttribute in interface PersistentSession
Parameters:
attribName - The name of the object you wish to set.
attribValue - the object you want to set.
Throws:
IllegalArgumentException - if the current object's Request object has not be set yet.

getAttribute

public Object getAttribute(String attribName)
Retrieves the object from the request context.

Specified by:
getAttribute in interface PersistentSession
Parameters:
attribName - the name of the object to retrieve
Returns:
the object or null if it doesn't exist.

getAttributeNames

public Enumeration getAttributeNames()
Retrieves all attribute names in the request context.

Specified by:
getAttributeNames in interface PersistentSession
Returns:
java.util.Enumeration

setClientAttribute

public void setClientAttribute(String attribName,
                               String attribValue)
Sets a cookie in the client's system. Note that this cookie is encrypted with the password you set up in your expresso-config.xml file.

Specified by:
setClientAttribute in interface PersistentSession
Parameters:
attribName - the name of the attribute to
attribValue - the value of the attribute to set.
Throws:
IllegalArgumentException - If the cookie encryption fails for some reason. The actual chained exception is logged.

getClientAttribute

public String getClientAttribute(String attribName)
Retrieves a value of a cookie set on the client's system. It also decrypts the value with the password you set up in your expresso-config.xml file.

Specified by:
getClientAttribute in interface PersistentSession
Parameters:
attribName - the name of the cookie to retrieve
Returns:
java.lang.String the value of the cookie or null if the cookie doesn't exist.
Throws:
IllegalArgumentException - If there's a problem decrypting the cookie. The full error is logged. [Especially important for chained exceptions]

getPeristentAttributeNames

public Enumeration getPeristentAttributeNames()
Retrieves all attribute names from the session context.

Specified by:
getPeristentAttributeNames in interface PersistentSession
Returns:
java.util.Enumeration

setPersistentAttribute

public void setPersistentAttribute(String attribName,
                                   Object attribValue)
Saves an attribute to the actual session, rather than simply the response. Use this for storing objects between requests, but only use it with care since the extra memory used may bog down systems under high load.

Specified by:
setPersistentAttribute in interface PersistentSession
Parameters:
attribName - the name of the attribute to set
attribValue - a Serializable java object.
Throws:
IllegalArgumentException - If there is an error storing the cookie to the session.
See Also:
Serializable

getPersistentAttribute

public Object getPersistentAttribute(String attribName)
Retrieves the object from the session context.

Specified by:
getPersistentAttribute in interface PersistentSession
Parameters:
attribName - the name of the object to retrieve
Returns:
the object or null if it doesn't exist.

setRequest

public void setRequest(HttpServletRequest req)
Set the request object so we can get to the session.

Parameters:
req - An HttpServletRequest object.

setResponse

public void setResponse(HttpServletResponse res)
Set the response object so we can get to all the http objects we need.

Parameters:
res - A HttpServletResponse object

invalidate

public void invalidate()
Clear out the session. Invalidates the entire session.

Specified by:
invalidate in interface PersistentSession

removeAttribute

public void removeAttribute(String attribName)
Clears an attribute from the request context

Specified by:
removeAttribute in interface PersistentSession
Parameters:
attribName - the name of the attribute to remove.

removePersistentAttribute

public void removePersistentAttribute(String attribName)
Clears an attribute from the session context

Specified by:
removePersistentAttribute in interface PersistentSession
Parameters:
attribName - the name of the attribute to remove.

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.