NextApp Echo
App Container 1.0.5

nextapp.echoservlet
Class CookieManager

java.lang.Object
  extended bynextapp.echoservlet.CookieManager
All Implemented Interfaces:
java.io.Serializable

public class CookieManager
extends java.lang.Object
implements java.io.Serializable

A utility class used to cookies set by an application on the client browser. Applications may obtain access to this object by retrieving their ServerContext from their EchoInstance and calling ServerContext.getCookieManager().

See Also:
Serialized Form

Field Summary
private  javax.servlet.http.Cookie[] clientCookies
          Contains the cookies that were most recently sent in by the client's most recent HTTP request.
private  java.util.Map localCookieMap
          Contains the Echo applications "working copy" of the cookies.
private  java.util.Set updatedCookies
          A set of cookies that have changed.
 
Constructor Summary
CookieManager()
           
 
Method Summary
 void add(javax.servlet.http.Cookie cookie)
          Adds a new cookie or updates an existing one.
private  void clearLocalCookieMap()
          Clears the locally held information about cookies.
 javax.servlet.http.Cookie get(java.lang.String name)
          Returns a cookie with the given name if it is exists or null if it does not.
private  java.util.Map getLocalCookieMap()
          Creates a new local cookie set, copying the client cookies array into it.
 java.util.Iterator iterator()
          Returns an iterator over all present cookies.
 void remove(java.lang.String name)
          Removes the specified cookie.
(package private)  void retrieveCookies(javax.servlet.http.HttpServletRequest request)
          Retrieves cookies from a client HTTP request and stores them in the CookieManager.
 int size()
          Returns the number of cookies present.
(package private)  void storeCookies(javax.servlet.http.HttpServletResponse response)
          Stores cookies on the client by adding them to the HTTP response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

clientCookies

private transient javax.servlet.http.Cookie[] clientCookies
Contains the cookies that were most recently sent in by the client's most recent HTTP request. If no cookies are present on the client, clientCookies may be null.


localCookieMap

private java.util.Map localCookieMap
Contains the Echo applications "working copy" of the cookies. This map references cookies by their names, and may contain cookies that the Echo application has requested to be set but that have not yet been set on the client.


updatedCookies

private java.util.Set updatedCookies
A set of cookies that have changed. Cookies are stored in this set when addCookie() is called, such that they will be updated in the HttpResponse generated by the Connection. Deleted cookies are also stored in this set, with there expiration set to zero, such that the client will delete them. The contents of this set are sent to the client at the next possible opportunity.

Constructor Detail

CookieManager

public CookieManager()
Method Detail

add

public void add(javax.servlet.http.Cookie cookie)
Adds a new cookie or updates an existing one. In the case of updating an existing cookie, be certain to reset its maximum age with setMaxAge() if necessary. (Cookies on the client browser do not report their maximum age to the server, only their value.)

Parameters:
cookie - The cookie to add or update.

clearLocalCookieMap

private void clearLocalCookieMap()
Clears the locally held information about cookies.


get

public javax.servlet.http.Cookie get(java.lang.String name)
Returns a cookie with the given name if it is exists or null if it does not.

Parameters:
name - The name of the cookie to return.
Returns:
The cookie identified by name.

getLocalCookieMap

private java.util.Map getLocalCookieMap()
Creates a new local cookie set, copying the client cookies array into it. This method is lazily called by other methods that need to work with the local cookie map.

Returns:
A map containing the client's cookies.

iterator

public java.util.Iterator iterator()
Returns an iterator over all present cookies.

Returns:
An iterator over all present cookies.

remove

public void remove(java.lang.String name)
Removes the specified cookie. This is accomplished by setting the cookie on the client with a maximum age of 0.

Parameters:
name - The name of the cookie to remove.

retrieveCookies

void retrieveCookies(javax.servlet.http.HttpServletRequest request)
Retrieves cookies from a client HTTP request and stores them in the CookieManager. When this method is called, all "working information" about cookies is destroyed.

Parameters:
request - An HttpServletRequest from which to extract cookies.

size

public int size()
Returns the number of cookies present. This is the number of cookies that the Echo application is tracking at the current time. Calls to the add and remove methods will increase or decrease this number even though the cookie has not yet been added or removed on the client.

Returns:
The number of cookies present.

storeCookies

void storeCookies(javax.servlet.http.HttpServletResponse response)
Stores cookies on the client by adding them to the HTTP response. When this method is called, all "working information" about cookies is destroyed.

Parameters:
response - An HttpServletResponse to feed the cookies to.

NextApp Echo
App Container 1.0.5