CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation

com.tangosol.coherence.servlet
Class SessionHelper

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.coherence.servlet.SessionHelper

public class SessionHelper
extends Base

A collection of methods that support the implementation of Coherence web container components used to replace the corresponding implementations provided by the application server vendor.

Must NOT be serializable just in case the application server implements clustering on the ServletContext level (because the session helper will be stored in the app server's ServletContext).

Version:
Coherence 2.3
Author:
cp 2003.07.21

Nested Class Summary
static interface SessionHelper.Factory
          This interface is used by the SessionHelper to obtain objects that implement various important parts of the Servlet specification, and by doing so, can be placed in front of the application in lieu of the application server's own objects, thus changing the "apparent implementation" of the application server itself (e.g.
 class SessionHelper.SessionReaperDaemon
          A daemon thread class that will clean up expired sessions.
protected static interface SessionHelper.Task
          Interface for detecting when a Runnable Task has completed.
 
Field Summary
static String CACHE_CONFIGURATION_PATH
          The name of the resource that will be used to configure the session management module's own ConfigurableCacheFactory.
static String CFG_KEY_REAPER
          The key in the configuration cache for coordating cluster-wide session reaping.
static String CTX_ATTR_CONTEXT
          The name of the application server context's attribute that Coherence stores its servlet context object under.
static String CTX_ATTR_HELPER
          The name of the application server context's attribute that Coherence stores its session helper object under.
static String CTX_INIT_ALLOW_LOCAL_ATTRIBUTES
          The configuration property that specifies whether non-serializable attributes should be preserved as local.
static String CTX_INIT_ATTR_OVERFLOW_THRESHOLD
          The configuration property for the "split" model that overrides the length that attributes must be below to be stored inside a session ("embedded") or above which they will be stored in the separated "overflow" cache ("external").
static String CTX_INIT_CACHENAME_CONTEXT
          The name of the Coherence cache that will be used to hold the servlet context data if the servlet context is clustered by Coherence.
static String CTX_INIT_CACHENAME_DEATHCERTS
          The configuration property that overrides the name of the clustered cache that stores the IDs of "recently departed" sessions.
static String CTX_INIT_CACHENAME_LOCAL_ATTRIBUTES
          The configuration property that overrides the name of the local cache that stores non-distributed session attributes (if allowed.)
static String CTX_INIT_CACHENAME_LOCAL_SESSIONS
          The configuration property that overrides the name of the local cache that stores non-distributed sessions when the SessionDistributionController option is implemented.
static String CTX_INIT_CACHENAME_MANAGEMENT
          The configuration property that overrides the name of the clustered cache that stores the sessions management configuration data.
static String CTX_INIT_CACHENAME_OVERFLOW
          The configuration property that overrides the name of the clustered cache that stores the "overflowing" (split-out due to size) session attributes.
static String CTX_INIT_CACHENAME_SESSIONS
          The configuration property that overrides the name of the clustered cache that stores the sessions.
static String CTX_INIT_CLUSTER
          The name of the application server context's initialization parameter that specifies whether the ServletContext attribute values will be clustered.
static String CTX_INIT_CLUSTER_OWNED
          True if the cluster software is deployed as part of the application and thus must be shut down fully by the application when it shuts down.
static String CTX_INIT_COLLECTION
          The name of the application server context's initialization parameter that specifies the fully qualified class name of the HttpSessionCollection implementation to use.
static String CTX_INIT_CONTROLLER_CLASS
          The configuration property that specifies an implementation of the SessionDistributionController interface to use.
static String CTX_INIT_COOKIE_DOMAIN
          The domain of the session cookie.
static String CTX_INIT_COOKIE_MAX_AGE
          The maximum age in seconds of the session cookie.
static String CTX_INIT_COOKIE_NAME
          The name of the session cookie.
static String CTX_INIT_COOKIE_PATH
          The path of the session cookie.
static String CTX_INIT_COOKIES_ENABLED
          True to enable session cookies.
static String CTX_INIT_DAEMON_ASSUME_LOCALITY
          True to assume that the sessions in the cache are split across only the servers that are doing reaping.
static String CTX_INIT_DAEMON_COORDINATED
          True to coordinate reaping in the cluster such that only one server will perform reaping within a given reaping cycle, and it will check all session ids in the cluster.
static String CTX_INIT_DAEMON_CYCLE_SECS
          The number of seconds that the daemon rests between reaping.
static String CTX_INIT_DAEMON_PRIORITY
          The priority for the session reaper daemon.
static String CTX_INIT_DAEMON_SWEEP_MODULO
          The number of times that the reaper reaps the sessions that are being used locally before it will check sessions that may be orphaned or expired elsewhere in the cluster.
static String CTX_INIT_FACTORY
          The name of the application server context's initialization parameter that specifies the fully qualified class name of the SessionHelper Factory to use.
static String CTX_INIT_FILTER
          In the filter's configuration, the name of the filter class that is wrapped by the Coherence filter.
static String CTX_INIT_LISTENS
          The comma-delimited list of names of application classes that wish to receive events from the web container.
static String CTX_INIT_SERVICENAME_OWNERSHIP
          The configuration property that specifies the name of the invocation service that will be used to manage sticky session ownership.
static String CTX_INIT_SERVLET
          In the servlet's configuration, the name of the servlet class that is wrapped by the Coherence servlet.
static String CTX_INIT_SESSION_EXPIRE_SECS
          The configuration property that overrides the session expirty time.
static String CTX_INIT_SESSION_ID_LENGTH
          The configuration property that overrides the session id length.
static String CTX_INIT_SESSION_RETAIN_MILLIS
          The length of time to defer async exit on a session that is accessed "out of context".
static String CTX_INIT_SESSION_STICKY
          The configuration property that specifies whether sticky sessions optimizations will be used.
static String CTX_INIT_SESSION_STRICT_SPEC
          The configuration property that specifies strict spec adherence.
static String CTX_INIT_SESSION_THREAD_LOCK
          The configuration property that specifies thread level session locking.
static String CTX_INIT_SESSIONCONTEXT_ENABLED
          True to allow the application to iterate sessions from the session context, thus disobeying the deprecation in the servlet spec.
static String CTX_INIT_SHUTDOWN_DELAY_SECS
          The configuration property that overrides the shutdown delay time.
static String CTX_INIT_UNWRAP_REQUEST
          True to force the request dispatcher to unwrap the servlet request before forwarding or including.
static String CTX_INIT_UNWRAP_RESPONSE
          True to force the request dispatcher to unwrap the servlet response before forwarding or including.
static String CTX_INIT_URLDECODE_DEFAULT
          True to use the container's decoding of the URL session ID.
static String CTX_INIT_URLENCODE_DEFAULT
          True to use the container's encoding of the URL session ID.
static String CTX_INIT_URLENCODE_ENABLED
          True to enable URL encoding of session ids.
static String CTX_INIT_URLENCODE_NAME
          The parameter name to encode the session id into the URL with.
static String DEFAULT_CTXNAME
          The default cache name for the ServletContext attribute map.
static String DEFAULT_FACTORY
          The default class name for the SessionHelper factory implementation.
static String DEFAULT_MGTNAME
          The default cache name for the session management configuration data.
static Object DISPATCH_FORWARD
          The value of the REQ_ATTR_DISPATCH request attribute that indicates the current request has been forwarded.
static Object DISPATCH_INCLUDE
          The value of the REQ_ATTR_DISPATCH request attribute that indicates the current request has been included.
static int EVT_ADDED
          The internal enum for an attribute-added event.
static int EVT_REMOVED
          The internal enum for an attribute-removed event.
static int EVT_REPLACED
          The internal enum for an attribute-replaced event.
protected static String KEY_REQUEST
           
static String KEY_REQUEST_RESOLVED
          The key used to store the dispatchable Servlet request in the map returned by preDispatch.
protected static String KEY_RESPONSE
           
static String KEY_RESPONSE_RESOLVED
          The key used to store the dispatchable Servlet response in the map returned by preDispatch.
protected static String KEY_SESSION_ID
           
static Filter NAME_FILTER
          The Filter object that hides init param names for Coherence params.
static String PRODUCT_BANNER
          The product name banner.
static String REQ_ATTR_CONTEXT
          The name of the request attribute that Coherence stores the request context object in.
static String REQ_ATTR_DISPATCH
          The name of the request attribute that Coherence stores the current request dispatch method.
static String REQ_ATTR_OK_WRAP
          The name of the request attribute that indicates that wrapping is not required.
static String REQ_ATTR_REQUEST
          The name of the request attribute that Coherence stores the current request object in.
static String REQ_ATTR_RESPONSE
          The name of the request attribute that Coherence stores the original wrapped response object in.
static String REQ_ATTR_TEST
          The name of the request attribute that tests if the Coherence wrapper is in place.
static String REQ_ATTR_WRAPPED
          The name of the request attribute that Coherence stores its own request object in.
protected static ConfigurableCacheFactory s_cachefactory
          The session management module's own ConfigurableCacheFactory.
 
Constructor Summary
SessionHelper(SessionHelper.Factory factory, ServletContext ctx)
          Construct a Coherence SessionHelper that will support the implementation of clustered web container services.
 
Method Summary
protected  void checkExpiredSessionId(String sId)
          Check the specified session to see if it has expired.
protected  void checkForDeadSessions()
          Discard the HttpSession objects that are no longer alive.
protected  void configure(int nVersionMajor, int nVersionMinor)
          Called immediately after construction.
 void contextDestroyed()
          Called by the Coherence ServletContextListener on contextDestroyed() if an event listener is registered.
 void contextInitialized()
          Called by the Coherence ServletContextListener on contextInitialized() if an event listener is registered.
 HttpSession createHttpSession()
          Create a new HttpSession object.
 String decodeCookie(HttpServletRequest req)
          Obtain a session ID from a request object by examining the cookies attached to the request.
 String decodeUrl(HttpServletRequest request)
          Decodes the session ID from the URL represented by the passed request.
 void encodeCookie(HttpServletRequest req, HttpServletResponse resp, String sId, boolean fNew)
          Encode a session ID into a cookie and attach it to the response object.
 String encodeUrl(String sUrl, HttpServletRequest request)
          Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.
protected  String encodeUrl(String sUrl, String sId)
          Encodes the specified URL by including the given session ID in it.
protected  NamedCache ensureConfigurationCache()
          Get the NamedCache used to store configuration and management information for the session management implementation if it exists, otherwise create it.
 RequestContext ensureRequestContext(ServletRequest req, ServletResponse res)
          Given the specified request and response, provide a request context.
 RequestContext ensureRequestContext(ServletRequest req, ServletResponse res, boolean fExternal)
          Given the specified request and response, provide a request context.
protected  NamedCache ensureServletContextAttributeCache()
          Get the clustered attribute map if it exists, otherwise create it (if the ServletContext is supposed to be clustered).
static SessionHelper ensureSessionHelper(ServletContext ctx)
          Find the existing (or create new) Coherence SessionHelper that will act as a coordinator to manage the creation and lookup of container objects, fake container objects (the Coherence implementation of the Servlet spec interfaces), and helper classes (such as the SessionHelper itself, the servlet model collection, etc.).
 TaskDaemon ensureSessionWorkerDaemon()
          Get the daemon thread that is used for scheduled tasks, creating it if necessary.
static ServletContext ensureWrappedServletContext(ServletContext ctx)
          Make sure that there is a ServletContext wrapper for the specified servlet context for this application, creating one if necessary.
 void filter(Filter filter, ServletRequest req, ServletResponse resp, FilterChain chain)
          Issue the service call to the specified servlet, given the passed request and response objects.
 void filterDestroyed()
          Called by each Coherence Filter wrapper on destroy().
 void filterInitialized()
          Called by each Coherence Filter wrapper on init().
static String formatCacheName(NamedCache cache)
          Format a NamedCache object into a human readable string.
static String formatListeners(Listeners listeners)
          Format a Listeners object into a human readable string.
static String formatMapKeys(Map map)
          Format a map into a list of keys.
static NamedCache getCache(String sCacheName)
          Obtain a session management cache by name.
 XmlElement getConfig()
          Determine the current configuration of the object.
 NamedCache getConfigurationCache()
          Get the NamedCache used to store configuration and management information for the session management implementation.
protected  int getDaemonCheckCollectionModulo()
          Determine how many times the daemon will perform its check before checking the session models that the collection considers "local".
protected  long getDaemonCycleMillis()
          Determine the number of milliseconds per reap cycle.
protected  int getDaemonPriority()
          Determine the configured priority for the session reaper daemon.
protected  String getDescription()
          Returns a string representation of this object's attributes.
 SessionHelper.Factory getFactory()
          Determine the factory to use to instantiate container-specific implementations of the Servlet specification interfaces.
 HttpSession getHttpSession(String sId)
          Get the HttpSession object for the specified ID.
 HttpSessionCollection getHttpSessionCollection()
          Get the HttpSessionCollection object that manages the HttpSessionModel objects.
 HttpSessionContext getHttpSessionContext()
          Get the HttpSessionContext.
protected  Map getHttpSessionMap()
          Get the map of session ID to session object for HttpSession objects managed in this application within this JVM/classloader.
static InvocationService getInvocationService(String sService)
          Obtain a session management invocation service by name.
 Listeners getListeners()
          Get the application listeners.
protected  String getMBeanObjectName()
          Return a string representation of the ObjectName used to register the MBean instance for this SessionHelper.
 RequestContext getRequestContext(ServletRequest req)
          Get the request context for the passed request, if one exists.
 ServletContext getServletContext()
          Returns the Coherence ServletContext wrapper that this SessionHelper is helping with.
 NamedCache getServletContextAttributeCache()
          Get the clustered attribute map.
 int getServletContextMajorVersion()
          Returns the major version of the Java Servlet API that this servlet container supports.
 int getServletContextMinorVersion()
          Returns the minor version of the Servlet API that this servlet container supports.
 ServletRequest getServletRequest(ServletRequest req)
          If the passed ServletRequest has been wrapped, return the current request object that was wrapped.
 ServletRequest getServletRequestWrapper(ServletRequest req)
          If the passed ServletRequest has been wrapped, return the request wrapper.
 String getSessionIdCookieDomain()
          Determine the domain of the cookie for holding the session ID.
 int getSessionIdCookieMaxAge()
          Determine the max age (in seconds) of the cookie for holding the session ID.
 String getSessionIdCookieName()
          Determine the name of the cookie for holding the session ID.
 String getSessionIdCookiePath()
          Determine the path of the cookie for holding the session ID.
 String getSessionIdEncodingName()
          Determine the name of the URL parameter for session ID encoding and decoding.
protected  SessionHelper.SessionReaperDaemon getSessionReaperDaemon()
          Get the daemon thread that cleans up expired sessions.
protected  TaskDaemon getSessionWorkerDaemon()
          Get the daemon thread that is used for scheduled tasks.
protected  long getShutdownDelayMillis()
          Determine the number of milliseconds to defer shutdown after the app appears to have stopped.
protected static int[] getSupportedVersion(ServletContext ctx)
          Determine the version of the spec to find the factory for based on the passed application server ServletContext object.
 ServletContext getWrappedServletContext()
          Returns the application server's ServletContext that this SessionHelper is helping with.
static ServletContext getWrappedServletContext(ServletContext ctx)
          Determine the ServletContext wrapper for the specified application server context.
protected  HttpSessionCollection instantiateHttpSessionCollection()
          Get the HttpSessionCollection object that manages the HttpSessionModel objects.
protected  Object instantiateMBean()
          Factory Method: Instantiate a MBean implementation for this SessionHelper.
protected  SessionHelper.SessionReaperDaemon instantiateSessionReaperDaemon()
          Factory method: Instantiate a daemon thread that will clean up expired sessions.
protected  TaskDaemon instantiateSessionWorkerDaemon()
          Factory method: Instantiate a daemon thread that will be used for scheduled tasks.
protected  boolean isClusterOwned()
          Determine if the responsibility for shutting down the cluster is owned by the application.
protected  boolean isDaemonAssumeLocality()
          Determine if the reaper daemon assumes that session data is stored only on nodes that are running the session reaper daemon thread.
protected  boolean isDaemonCheckCoordinated()
          Determine if the reaper daemon coordinates the check across the cluster instead of just doing its own "local" scan.
 boolean isRequestUnwrapRequired()
          Determine if the custom servlet request wrapper needs to be unwrapped before including or forwarding to other content.
 boolean isResponseUnwrapRequired()
          Determine if the custom servlet response wrapper needs to be unwrapped before including or forwarding to other content.
 boolean isServletContextClustered()
          Determine if the context clusters attributes.
 boolean isServletRequestDispatched(ServletRequest req)
          Test to see if the passed ServletRequest has been dispatched as a result of an include or forward.
 boolean isServletRequestForwarded(ServletRequest req)
          Test to see if the passed ServletRequest has been dispatched as a result of a forward.
 boolean isServletRequestIncluded(ServletRequest req)
          Test to see if the passed ServletRequest has been dispatched as a result of an include.
 boolean isServletRequestWrapped(ServletRequest req)
          Test to see if the passed ServletRequest is wrapped, which means that invoking a method on the passed ServletRequest object will invoke the Coherence implementation, and will do so before the container implementation is invoked.
 boolean isSessionContextEnabled()
          Determine if the session context should disobey the deprecation and allow an application to enumerate sessions.
 boolean isSessionIdCookie(Cookie cookie)
          Tests to see if the supplied cookie is a session ID cookie.
 boolean isSessionIdCookieEnabled()
          Determine if a cookie may be used to hold the session ID.
 boolean isSessionIdEncodingEnabled()
          Determine if URL encoding may be used to hold the session ID.
 boolean isStrict()
          Determine if the Servlet specification is being followed strictly.
 boolean isUseDefaultSessionIdDecoding()
          Determine if the session ID decoding (from a URL) performed by the application server's request object is sufficient.
 boolean isUseDefaultSessionIdEncoding()
          Determine if the session ID encoding (into a URL) performed by the application server's response object is sufficient.
 void killSession(String sId)
          Forcibly destroy a session.
static void logEventException(RuntimeException e, String sMethod, boolean fContinue)
          Log an event exception.
static boolean parseBoolean(ServletContext ctx, String sParam, boolean fDefault)
          Helper: Get a boolean init parameter from the context.
static int parseInt(ServletContext ctx, String sParam, int nDefault)
          Helper: Get an int init parameter from the context.
static String parseString(ServletContext ctx, String sParam, String sDefault)
          Helper: Get a String init parameter from the context.
 void postDispatch(ServletRequest req, Map map)
          Restores a Servlet request to the state it was in prior to being dispatched.
 void postService(RequestContext ctx)
          Finish the request processing after the servlet/jsp is complete.
 Map preDispatch(ServletRequest req, ServletResponse res)
          Prepares a Servlet request to be dispatched by a RequestDispatcher.
 RequestContext preService(ServletRequest req, ServletResponse res)
          Wrap the passed request and response (if necessary) and build a request context that contains all the pertinent information about the request.
protected  void registerMBean()
          Register an MBean instance for this SessionHelper.
 void requestAsyncOwnership(String sId)
          Enter (obtain) and schedule an asynchronous call to exit (release) the specified session ID.
 ServletRequest resolveRequest(ServletRequest req)
          Determine what request object should be sent to the application server's request dispatcher: the application server's request object, or the wrapper that we created.
 ServletResponse resolveResponse(ServletRequest req, ServletResponse res)
          Determine what response object should be sent to the application server's request dispatcher: the application server's response object, or the wrapper that we created.
 void service(Servlet servlet, ServletRequest req, ServletResponse resp)
          Issue the service call to the specified servlet, given the passed request and response objects.
 void servletDestroyed()
          Called by each Coherence Servlet wrapper on destroy().
 void servletInitialized()
          Called by each Coherence Servlet wrapper on init().
 void setConfig(XmlElement xml)
          Specify the configuration for the object.
 void setListeners(Listeners listeners)
          Store the application listeners.
protected  void setSessionWorkerDaemon(TaskDaemon daemon)
          Set the daemon thread that is used for scheduled tasks.
protected  void shutdown()
          Shuts down the SessionHelper and any mess that it created.
protected  void shutdownConfigurationCache()
          Shutdown the NamedCache used to store configuration and management information for the session management implementation.
 void shutdownHttpSessionCollection()
          Shutdown the http session collection.
protected  void shutdownServletContextAttributeCache()
          Shutdown the clustered attribute map.
 void shutdownSessionReaperDaemon()
          Stop the daemon thread that is used for expiring sessions.
 void shutdownSessionWorkerDaemon()
          Stop the daemon thread that is used for scheduled tasks.
 String toString()
          Returns a string representation of the object.
protected  void unregisterMBean()
          Unregister the MBean instance for this SessionHelper.
 FilterConfig unwrapFilterConfig(FilterConfig cfg)
          Attempt to unwrap the passed FilterConfig wrapper to get the container's FilterConfig object back.
 ServletConfig unwrapServletConfig(ServletConfig cfg)
          Attempt to unwrap the passed ServletConfig wrapper to get the container's ServletConfig object back.
 ServletRequest unwrapServletRequest(ServletRequest req)
          Unwrap the specified request object.
 FilterConfig wrapFilterConfig(FilterConfig cfg)
          Given the specified FilterConfig object, return a wrapper to use.
 RequestDispatcher wrapRequestDispatcher(RequestDispatcher disp)
          Wrap the specified RequestDispatcher object from the container.
 ServletConfig wrapServletConfig(ServletConfig cfg)
          Given the specified servlet config object, return a wrapper to use.
 ServletRequest wrapServletRequest(ServletRequest req)
          Given the specified request, create a request wrapper.
 ServletRequest wrapServletRequest(ServletRequest req, boolean fExternal)
          Given the specified request, create a request wrapper.
 

Field Detail

PRODUCT_BANNER

public static final String PRODUCT_BANNER
The product name banner.


CACHE_CONFIGURATION_PATH

public static final String CACHE_CONFIGURATION_PATH
The name of the resource that will be used to configure the session management module's own ConfigurableCacheFactory.

See Also:
Constant Field Values

EVT_ADDED

public static final int EVT_ADDED
The internal enum for an attribute-added event.

See Also:
Constant Field Values

EVT_REMOVED

public static final int EVT_REMOVED
The internal enum for an attribute-removed event.

See Also:
Constant Field Values

EVT_REPLACED

public static final int EVT_REPLACED
The internal enum for an attribute-replaced event.

See Also:
Constant Field Values

CTX_INIT_FACTORY

public static final String CTX_INIT_FACTORY
The name of the application server context's initialization parameter that specifies the fully qualified class name of the SessionHelper Factory to use.

See Also:
Constant Field Values

CTX_INIT_COLLECTION

public static final String CTX_INIT_COLLECTION
The name of the application server context's initialization parameter that specifies the fully qualified class name of the HttpSessionCollection implementation to use.

See Also:
Constant Field Values

CTX_INIT_CLUSTER_OWNED

public static final String CTX_INIT_CLUSTER_OWNED
True if the cluster software is deployed as part of the application and thus must be shut down fully by the application when it shuts down. For example, this should be set to true if coherence.jar and tangosol.jar are deployed within the application "WAR" file.

See Also:
Constant Field Values

CTX_INIT_CLUSTER

public static final String CTX_INIT_CLUSTER
The name of the application server context's initialization parameter that specifies whether the ServletContext attribute values will be clustered. If the configuration value is "true", then all ServletContext attribute values must be serializable.

See Also:
Constant Field Values

CTX_INIT_CACHENAME_CONTEXT

public static final String CTX_INIT_CACHENAME_CONTEXT
The name of the Coherence cache that will be used to hold the servlet context data if the servlet context is clustered by Coherence.

See Also:
Constant Field Values

CTX_INIT_LISTENS

public static final String CTX_INIT_LISTENS
The comma-delimited list of names of application classes that wish to receive events from the web container.

See Also:
Constant Field Values

CTX_INIT_SESSIONCONTEXT_ENABLED

public static final String CTX_INIT_SESSIONCONTEXT_ENABLED
True to allow the application to iterate sessions from the session context, thus disobeying the deprecation in the servlet spec.

See Also:
Constant Field Values

CTX_INIT_SESSION_RETAIN_MILLIS

public static final String CTX_INIT_SESSION_RETAIN_MILLIS
The length of time to defer async exit on a session that is accessed "out of context".

See Also:
Constant Field Values

CTX_INIT_COOKIES_ENABLED

public static final String CTX_INIT_COOKIES_ENABLED
True to enable session cookies.

See Also:
Constant Field Values

CTX_INIT_COOKIE_NAME

public static final String CTX_INIT_COOKIE_NAME
The name of the session cookie.

See Also:
Constant Field Values

CTX_INIT_COOKIE_DOMAIN

public static final String CTX_INIT_COOKIE_DOMAIN
The domain of the session cookie.

See Also:
Constant Field Values

CTX_INIT_COOKIE_PATH

public static final String CTX_INIT_COOKIE_PATH
The path of the session cookie.

See Also:
Constant Field Values

CTX_INIT_COOKIE_MAX_AGE

public static final String CTX_INIT_COOKIE_MAX_AGE
The maximum age in seconds of the session cookie.

See Also:
Constant Field Values

CTX_INIT_URLENCODE_ENABLED

public static final String CTX_INIT_URLENCODE_ENABLED
True to enable URL encoding of session ids.

See Also:
Constant Field Values

CTX_INIT_URLENCODE_NAME

public static final String CTX_INIT_URLENCODE_NAME
The parameter name to encode the session id into the URL with.

See Also:
Constant Field Values

CTX_INIT_URLDECODE_DEFAULT

public static final String CTX_INIT_URLDECODE_DEFAULT
True to use the container's decoding of the URL session ID.

See Also:
Constant Field Values

CTX_INIT_URLENCODE_DEFAULT

public static final String CTX_INIT_URLENCODE_DEFAULT
True to use the container's encoding of the URL session ID.

See Also:
Constant Field Values

CTX_INIT_UNWRAP_REQUEST

public static final String CTX_INIT_UNWRAP_REQUEST
True to force the request dispatcher to unwrap the servlet request before forwarding or including.

See Also:
Constant Field Values

CTX_INIT_UNWRAP_RESPONSE

public static final String CTX_INIT_UNWRAP_RESPONSE
True to force the request dispatcher to unwrap the servlet response before forwarding or including.

See Also:
Constant Field Values

CTX_INIT_DAEMON_PRIORITY

public static final String CTX_INIT_DAEMON_PRIORITY
The priority for the session reaper daemon.

See Also:
Constant Field Values

CTX_INIT_DAEMON_CYCLE_SECS

public static final String CTX_INIT_DAEMON_CYCLE_SECS
The number of seconds that the daemon rests between reaping.

See Also:
Constant Field Values

CTX_INIT_DAEMON_COORDINATED

public static final String CTX_INIT_DAEMON_COORDINATED
True to coordinate reaping in the cluster such that only one server will perform reaping within a given reaping cycle, and it will check all session ids in the cluster.

See Also:
Constant Field Values

CTX_INIT_DAEMON_ASSUME_LOCALITY

public static final String CTX_INIT_DAEMON_ASSUME_LOCALITY
True to assume that the sessions in the cache are split across only the servers that are doing reaping.

See Also:
Constant Field Values

CTX_INIT_DAEMON_SWEEP_MODULO

public static final String CTX_INIT_DAEMON_SWEEP_MODULO
The number of times that the reaper reaps the sessions that are being used locally before it will check sessions that may be orphaned or expired elsewhere in the cluster.

See Also:
Constant Field Values

CTX_INIT_CACHENAME_MANAGEMENT

public static final String CTX_INIT_CACHENAME_MANAGEMENT
The configuration property that overrides the name of the clustered cache that stores the sessions management configuration data.

See Also:
Constant Field Values

CTX_INIT_CACHENAME_SESSIONS

public static final String CTX_INIT_CACHENAME_SESSIONS
The configuration property that overrides the name of the clustered cache that stores the sessions.

See Also:
Constant Field Values

CTX_INIT_CACHENAME_DEATHCERTS

public static final String CTX_INIT_CACHENAME_DEATHCERTS
The configuration property that overrides the name of the clustered cache that stores the IDs of "recently departed" sessions.

See Also:
Constant Field Values

CTX_INIT_CACHENAME_OVERFLOW

public static final String CTX_INIT_CACHENAME_OVERFLOW
The configuration property that overrides the name of the clustered cache that stores the "overflowing" (split-out due to size) session attributes. Only used for the "Split" model.

See Also:
Constant Field Values

CTX_INIT_CACHENAME_LOCAL_SESSIONS

public static final String CTX_INIT_CACHENAME_LOCAL_SESSIONS
The configuration property that overrides the name of the local cache that stores non-distributed sessions when the SessionDistributionController option is implemented.

See Also:
Constant Field Values

CTX_INIT_CACHENAME_LOCAL_ATTRIBUTES

public static final String CTX_INIT_CACHENAME_LOCAL_ATTRIBUTES
The configuration property that overrides the name of the local cache that stores non-distributed session attributes (if allowed.)

See Also:
Constant Field Values

CTX_INIT_SESSION_EXPIRE_SECS

public static final String CTX_INIT_SESSION_EXPIRE_SECS
The configuration property that overrides the session expirty time.

See Also:
Constant Field Values

CTX_INIT_SESSION_ID_LENGTH

public static final String CTX_INIT_SESSION_ID_LENGTH
The configuration property that overrides the session id length.

See Also:
Constant Field Values

CTX_INIT_ATTR_OVERFLOW_THRESHOLD

public static final String CTX_INIT_ATTR_OVERFLOW_THRESHOLD
The configuration property for the "split" model that overrides the length that attributes must be below to be stored inside a session ("embedded") or above which they will be stored in the separated "overflow" cache ("external").

See Also:
Constant Field Values

CTX_INIT_SESSION_THREAD_LOCK

public static final String CTX_INIT_SESSION_THREAD_LOCK
The configuration property that specifies thread level session locking.

See Also:
Constant Field Values

CTX_INIT_SESSION_STRICT_SPEC

public static final String CTX_INIT_SESSION_STRICT_SPEC
The configuration property that specifies strict spec adherence.

See Also:
Constant Field Values

CTX_INIT_SHUTDOWN_DELAY_SECS

public static final String CTX_INIT_SHUTDOWN_DELAY_SECS
The configuration property that overrides the shutdown delay time.

See Also:
Constant Field Values

CTX_INIT_SERVLET

public static final String CTX_INIT_SERVLET
In the servlet's configuration, the name of the servlet class that is wrapped by the Coherence servlet.

This is used in a web-xml

<servlet>
element to designate the application servlet name that the Coherence implementation is being wrapped around; this must be done for each application servlet.

Before:

 <servlet>
   <servlet-name>MyServlet</servlet-name>
   <display-name>MyServlet</display-name>
   <description>this servlet is part of my app</description>
   <servlet-class>com.mypkg.MyServlet</servlet-class>
   <init-param>
     <param-name>ContextPath</param-name>
     <param-value>/tomcat</param-value>
   </init-param>
 </servlet>
 

After:

 <servlet>
   <servlet-name>MyServlet</servlet-name>
   <display-name>MyServlet</display-name>
   <description>this servlet is part of my app</description>
   <servlet-class>com.tangosol.coherence.servlet.api22.HttpServletWrapper</servlet-class>
   <init-param>
     <param-name>ContextPath</param-name>
     <param-value>/tomcat</param-value>
   </init-param>
   <init-param>
     <param-name>coherence-servlet-class</param-name>
     <param-value>com.mypkg.MyServlet</param-value>
   </init-param>
 </servlet>
 

See Also:
Constant Field Values

CTX_INIT_FILTER

public static final String CTX_INIT_FILTER
In the filter's configuration, the name of the filter class that is wrapped by the Coherence filter.

This is used in a web-xml

<filter>
element to designate the application filter name that the Coherence implementation is being wrapped around; this must be done for each application filter.

See Also:
Constant Field Values

CTX_INIT_CONTROLLER_CLASS

public static final String CTX_INIT_CONTROLLER_CLASS
The configuration property that specifies an implementation of the SessionDistributionController interface to use.

See Also:
Constant Field Values

CTX_INIT_SESSION_STICKY

public static final String CTX_INIT_SESSION_STICKY
The configuration property that specifies whether sticky sessions optimizations will be used. This should only be turned on if a sticky load balancer is being used.

See Also:
Constant Field Values

CTX_INIT_SERVICENAME_OWNERSHIP

public static final String CTX_INIT_SERVICENAME_OWNERSHIP
The configuration property that specifies the name of the invocation service that will be used to manage sticky session ownership.

See Also:
Constant Field Values

CTX_INIT_ALLOW_LOCAL_ATTRIBUTES

public static final String CTX_INIT_ALLOW_LOCAL_ATTRIBUTES
The configuration property that specifies whether non-serializable attributes should be preserved as local.

See Also:
Constant Field Values

CTX_ATTR_HELPER

public static final String CTX_ATTR_HELPER
The name of the application server context's attribute that Coherence stores its session helper object under.

See Also:
Constant Field Values

CTX_ATTR_CONTEXT

public static final String CTX_ATTR_CONTEXT
The name of the application server context's attribute that Coherence stores its servlet context object under.

Also, the name of the request attribute used to store the request context.

See Also:
Constant Field Values

REQ_ATTR_CONTEXT

public static final String REQ_ATTR_CONTEXT
The name of the request attribute that Coherence stores the request context object in.

See Also:
Constant Field Values

REQ_ATTR_DISPATCH

public static final String REQ_ATTR_DISPATCH
The name of the request attribute that Coherence stores the current request dispatch method.

See Also:
Constant Field Values

REQ_ATTR_REQUEST

public static final String REQ_ATTR_REQUEST
The name of the request attribute that Coherence stores the current request object in.

See Also:
Constant Field Values

REQ_ATTR_RESPONSE

public static final String REQ_ATTR_RESPONSE
The name of the request attribute that Coherence stores the original wrapped response object in.

See Also:
Constant Field Values

REQ_ATTR_WRAPPED

public static final String REQ_ATTR_WRAPPED
The name of the request attribute that Coherence stores its own request object in. This request object wraps the current request.

See Also:
Constant Field Values

REQ_ATTR_TEST

public static final String REQ_ATTR_TEST
The name of the request attribute that tests if the Coherence wrapper is in place.

See Also:
Constant Field Values

REQ_ATTR_OK_WRAP

public static final String REQ_ATTR_OK_WRAP
The name of the request attribute that indicates that wrapping is not required.

See Also:
Constant Field Values

DEFAULT_FACTORY

public static final String DEFAULT_FACTORY
The default class name for the SessionHelper factory implementation.

See Also:
Constant Field Values

DEFAULT_CTXNAME

public static final String DEFAULT_CTXNAME
The default cache name for the ServletContext attribute map.

See Also:
Constant Field Values

DEFAULT_MGTNAME

public static final String DEFAULT_MGTNAME
The default cache name for the session management configuration data.

See Also:
Constant Field Values

CFG_KEY_REAPER

public static final String CFG_KEY_REAPER
The key in the configuration cache for coordating cluster-wide session reaping.

See Also:
Constant Field Values

NAME_FILTER

public static final Filter NAME_FILTER
The Filter object that hides init param names for Coherence params.


DISPATCH_FORWARD

public static final Object DISPATCH_FORWARD
The value of the REQ_ATTR_DISPATCH request attribute that indicates the current request has been forwarded.


DISPATCH_INCLUDE

public static final Object DISPATCH_INCLUDE
The value of the REQ_ATTR_DISPATCH request attribute that indicates the current request has been included.


KEY_REQUEST_RESOLVED

public static final String KEY_REQUEST_RESOLVED
The key used to store the dispatchable Servlet request in the map returned by preDispatch.

See Also:
Constant Field Values

KEY_RESPONSE_RESOLVED

public static final String KEY_RESPONSE_RESOLVED
The key used to store the dispatchable Servlet response in the map returned by preDispatch.

See Also:
Constant Field Values

KEY_REQUEST

protected static final String KEY_REQUEST
See Also:
Constant Field Values

KEY_RESPONSE

protected static final String KEY_RESPONSE
See Also:
Constant Field Values

KEY_SESSION_ID

protected static final String KEY_SESSION_ID
See Also:
Constant Field Values

s_cachefactory

protected static ConfigurableCacheFactory s_cachefactory
The session management module's own ConfigurableCacheFactory.

Constructor Detail

SessionHelper

public SessionHelper(SessionHelper.Factory factory,
                     ServletContext ctx)
Construct a Coherence SessionHelper that will support the implementation of clustered web container services.

Parameters:
factory - the object that will instantiate the container-specific (or servlet spec specific) implementations
ctx - the application server's ServletContext object
Method Detail

configure

protected void configure(int nVersionMajor,
                         int nVersionMinor)
Called immediately after construction.

Parameters:
nVersionMajor - the servlet specification major version number
nVersionMinor - the servlet specification minor version number

getConfig

public XmlElement getConfig()
Determine the current configuration of the object.

Returns:
the XML configuration or null

setConfig

public void setConfig(XmlElement xml)
Specify the configuration for the object.

Parameters:
xml - the XML configuration for the object
Throws:
IllegalStateException - if the object is not in a state that allows the configuration to be set; for example, if the object has already been configured and cannot be reconfigured

ensureSessionHelper

public static SessionHelper ensureSessionHelper(ServletContext ctx)
Find the existing (or create new) Coherence SessionHelper that will act as a coordinator to manage the creation and lookup of container objects, fake container objects (the Coherence implementation of the Servlet spec interfaces), and helper classes (such as the SessionHelper itself, the servlet model collection, etc.).

Parameters:
ctx - the application server's ServletContext object

getSupportedVersion

protected static int[] getSupportedVersion(ServletContext ctx)
Determine the version of the spec to find the factory for based on the passed application server ServletContext object.

Note: Hard-coded to support 2.2 through 2.4.

Parameters:
ctx - the application server's ServletContext object
Returns:
an array containing [0] major and [1] minor version of the servlet spec to find the factory for

getCache

public static NamedCache getCache(String sCacheName)
Obtain a session management cache by name.

Parameters:
sCacheName - the name of the cache to obtain

getInvocationService

public static InvocationService getInvocationService(String sService)
Obtain a session management invocation service by name.

Parameters:
sService - the name of the invocation service to obtain

getMBeanObjectName

protected String getMBeanObjectName()
Return a string representation of the ObjectName used to register the MBean instance for this SessionHelper.

Returns:
a string representation of the ObjectName

instantiateMBean

protected Object instantiateMBean()
Factory Method: Instantiate a MBean implementation for this SessionHelper.

Returns:
a new MBean instance

registerMBean

protected void registerMBean()
Register an MBean instance for this SessionHelper.


unregisterMBean

protected void unregisterMBean()
Unregister the MBean instance for this SessionHelper.


contextInitialized

public void contextInitialized()
Called by the Coherence ServletContextListener on contextInitialized() if an event listener is registered.


contextDestroyed

public void contextDestroyed()
Called by the Coherence ServletContextListener on contextDestroyed() if an event listener is registered.


servletInitialized

public void servletInitialized()
Called by each Coherence Servlet wrapper on init().


servletDestroyed

public void servletDestroyed()
Called by each Coherence Servlet wrapper on destroy().


filterInitialized

public void filterInitialized()
Called by each Coherence Filter wrapper on init().


filterDestroyed

public void filterDestroyed()
Called by each Coherence Filter wrapper on destroy().


shutdown

protected void shutdown()
Shuts down the SessionHelper and any mess that it created.


isClusterOwned

protected boolean isClusterOwned()
Determine if the responsibility for shutting down the cluster is owned by the application.

Returns:
true if the cluster software is running within the domain of the application context, false if within the domain of the application server

getShutdownDelayMillis

protected long getShutdownDelayMillis()
Determine the number of milliseconds to defer shutdown after the app appears to have stopped.

Returns:
the length of time in milliseconds to defer shutdown after the app is stopped

getWrappedServletContext

public static ServletContext getWrappedServletContext(ServletContext ctx)
Determine the ServletContext wrapper for the specified application server context. This method can also be used to determine if another application has a Coherence ServletContext wrapper.

Parameters:
ctx - a ServletContext
Returns:
a ServletContext that wraps around the specified ServletContext or the passed ServletContext itself if it is a wrapper already or null if there is no wrapper

ensureWrappedServletContext

public static ServletContext ensureWrappedServletContext(ServletContext ctx)
Make sure that there is a ServletContext wrapper for the specified servlet context for this application, creating one if necessary.

Parameters:
ctx - this application's ServletContext
Returns:
a ServletContext that wraps around the specified ServletContext or the passed ServletContext itself if it is a wrapper already

getServletContext

public ServletContext getServletContext()
Returns the Coherence ServletContext wrapper that this SessionHelper is helping with.

Returns:
the Coherence ServletContext

getServletContextAttributeCache

public NamedCache getServletContextAttributeCache()
Get the clustered attribute map.

Returns:
the clustered attribute map, or null if the context does not cluster attributes

ensureServletContextAttributeCache

protected NamedCache ensureServletContextAttributeCache()
Get the clustered attribute map if it exists, otherwise create it (if the ServletContext is supposed to be clustered).

Returns:
the clustered attribute map, or null if the context does not cluster attributes

shutdownServletContextAttributeCache

protected void shutdownServletContextAttributeCache()
Shutdown the clustered attribute map.


getServletContextMajorVersion

public int getServletContextMajorVersion()
Returns the major version of the Java Servlet API that this servlet container supports.

Returns:
the major version of the Java Servlet API that this servlet container supports

getServletContextMinorVersion

public int getServletContextMinorVersion()
Returns the minor version of the Servlet API that this servlet container supports.

Returns:
the minor version of the Servlet API that this servlet container supports

getWrappedServletContext

public ServletContext getWrappedServletContext()
Returns the application server's ServletContext that this SessionHelper is helping with.

Returns:
the application server's ServletContext

isServletContextClustered

public boolean isServletContextClustered()
Determine if the context clusters attributes.

Returns:
true if the context clusters attributes; false otherwise

isStrict

public boolean isStrict()
Determine if the Servlet specification is being followed strictly.

Returns:
true if the Servlet specification is being followed strictly

parseString

public static String parseString(ServletContext ctx,
                                 String sParam,
                                 String sDefault)
Helper: Get a String init parameter from the context. The parsed init parameter will be stipped of leading and trailing whitespace. If the result is blank, the default will be returned.

Parameters:
ctx - the ServletContext
sParam - the init parameter name
sDefault - the default to return if the init parameter is not present or is blank
Returns:
the specified init parameter, or if it is not present or it is blank, then the passed default

parseBoolean

public static boolean parseBoolean(ServletContext ctx,
                                   String sParam,
                                   boolean fDefault)
Helper: Get a boolean init parameter from the context.

Parameters:
ctx - the ServletContext
sParam - the init parameter name
fDefault - the default to return if the init parameter is not present or is not a boolean value
Returns:
the specified boolean init parameter, or its default

parseInt

public static int parseInt(ServletContext ctx,
                           String sParam,
                           int nDefault)
Helper: Get an int init parameter from the context.

Parameters:
ctx - the ServletContext
sParam - the init parameter name
nDefault - the default to return if the init parameter is not present or is not an int value
Returns:
the specified int init parameter, or its default

getListeners

public Listeners getListeners()
Get the application listeners.

Returns:
a Listeners object containing all EventListener objects for the application

setListeners

public void setListeners(Listeners listeners)
Store the application listeners. This should only be called once.

Parameters:
listeners - a Listeners object containing all EventListener objects for the application

wrapFilterConfig

public FilterConfig wrapFilterConfig(FilterConfig cfg)
Given the specified FilterConfig object, return a wrapper to use.

Parameters:
cfg - the container's FilterConfig object
Returns:
a wrapper for the container's FilterConfig object

unwrapFilterConfig

public FilterConfig unwrapFilterConfig(FilterConfig cfg)
Attempt to unwrap the passed FilterConfig wrapper to get the container's FilterConfig object back. Note: This does require that each Filter is configured with a different name.

Returns:
the unwrapped FilterConfig object

filter

public void filter(Filter filter,
                   ServletRequest req,
                   ServletResponse resp,
                   FilterChain chain)
            throws ServletException,
                   IOException
Issue the service call to the specified servlet, given the passed request and response objects.

Parameters:
filter - the application's filter to invoke
req - the ServletRequest object that contains the client's request
resp - the ServletResponse object that contains the servlet's response
chain - the FilterChain to use to invoke the next filter or the Servlet
Throws:
ServletException
IOException

wrapServletConfig

public ServletConfig wrapServletConfig(ServletConfig cfg)
Given the specified servlet config object, return a wrapper to use.

Parameters:
cfg - the container's servlet config object
Returns:
a wrapper for the container's servlet config object

unwrapServletConfig

public ServletConfig unwrapServletConfig(ServletConfig cfg)
Attempt to unwrap the passed ServletConfig wrapper to get the container's ServletConfig object back. Note: This does require that each servlet is configured with a different name.

Returns:
the unwrapped ServletConfig object

getServletRequest

public ServletRequest getServletRequest(ServletRequest req)
If the passed ServletRequest has been wrapped, return the current request object that was wrapped.

Parameters:
req - a ServletRequest object
Returns:
the current servlet request if the ServletRequest object has been wrapped; otherwise the passed request itself

getServletRequestWrapper

public ServletRequest getServletRequestWrapper(ServletRequest req)
If the passed ServletRequest has been wrapped, return the request wrapper. Consider three request objects, "original", "coherence" and "application", where original is from the container, coherence is our wrapper, and application is a request wrapper provided by an application filter. The order of delegation is such that the coherence wrapper would delegate to the original, and the application wrapper would delegate to the coherence wrapper, (thinking it was the container's request object). Passing any of these request objects to this method would return the coherence request wrapper.

Parameters:
req - a ServletRequest object
Returns:
the servlet request wrapper if the ServletRequest object has been wrapped; otherwise null

isServletRequestWrapped

public boolean isServletRequestWrapped(ServletRequest req)
Test to see if the passed ServletRequest is wrapped, which means that invoking a method on the passed ServletRequest object will invoke the Coherence implementation, and will do so before the container implementation is invoked.

Parameters:
req - a ServletRequest object
Returns:
true if the use of the passed ServletRequest object will result in the Coherence implementation will be invoked before the container implementation

isServletRequestDispatched

public boolean isServletRequestDispatched(ServletRequest req)
Test to see if the passed ServletRequest has been dispatched as a result of an include or forward.

Parameters:
req - a ServletRequest object
Returns:
true if the ServletRequest has been dispatched by a RequestDispatcher

isServletRequestForwarded

public boolean isServletRequestForwarded(ServletRequest req)
Test to see if the passed ServletRequest has been dispatched as a result of a forward.

Parameters:
req - a ServletRequest object
Returns:
true if the ServletRequest has been forwarded by a RequestDispatcher

isServletRequestIncluded

public boolean isServletRequestIncluded(ServletRequest req)
Test to see if the passed ServletRequest has been dispatched as a result of an include.

Parameters:
req - a ServletRequest object
Returns:
true if the ServletRequest has been included by a RequestDispatcher

wrapServletRequest

public ServletRequest wrapServletRequest(ServletRequest req)
Given the specified request, create a request wrapper. This method also creates the request context object for the request.

Parameters:
req - a ServletRequest object that might need wrapping or might have already been wrapped
Returns:
a request object that wraps the specified ServletRequest

wrapServletRequest

public ServletRequest wrapServletRequest(ServletRequest req,
                                         boolean fExternal)
Given the specified request, create a request wrapper. This method also creates the request context object for the request.

Parameters:
req - a ServletRequest object that might need wrapping or might have already been wrapped
fExternal - if true, the ServletRequest will be treated as an "external" request, that is, one originating from a web application with a different ServletContext.
Returns:
a request object that wraps the specified ServletRequest

unwrapServletRequest

public ServletRequest unwrapServletRequest(ServletRequest req)
Unwrap the specified request object.

Parameters:
req - a ServletRequest object
Returns:
the container's ServletRequest object

decodeCookie

public String decodeCookie(HttpServletRequest req)
Obtain a session ID from a request object by examining the cookies attached to the request.

Parameters:
req - an HttpServletRequest object that may have a session cookie attached to it
Returns:
the HttpSession id as a String value, or null if no session id is found in a cookie attached to the request

encodeCookie

public void encodeCookie(HttpServletRequest req,
                         HttpServletResponse resp,
                         String sId,
                         boolean fNew)
Encode a session ID into a cookie and attach it to the response object.

Parameters:
req - the HttpServletRequest object for the current request
resp - the HttpServletResponse object for the current request that the session cookie should be attached to
sId - the session ID
fNew - true if the session was just created

isSessionIdCookie

public boolean isSessionIdCookie(Cookie cookie)
Tests to see if the supplied cookie is a session ID cookie.

Parameters:
cookie - the cookie to test
Returns:
true if the cookie is a session ID cookie

getRequestContext

public RequestContext getRequestContext(ServletRequest req)
Get the request context for the passed request, if one exists.

Parameters:
req - a container, Coherence or application ServletRequest object
Returns:
request context for the passed request, if one exists, or null

ensureRequestContext

public RequestContext ensureRequestContext(ServletRequest req,
                                           ServletResponse res)
Given the specified request and response, provide a request context.

Parameters:
req - a ServletRequest object that might need wrapping or might have already been wrapped
res - a ServletResponse object that might need wrapping or might have already been wrapped
Returns:
the request context that matches the passed request and response objects

ensureRequestContext

public RequestContext ensureRequestContext(ServletRequest req,
                                           ServletResponse res,
                                           boolean fExternal)
Given the specified request and response, provide a request context.

Parameters:
req - a ServletRequest object that might need wrapping or might have already been wrapped
res - a ServletResponse object that might need wrapping or might have already been wrapped
fExternal - if true, the ServletRequest will be treated as an "external" request, that is, one originating from a web application with a different ServletContext
Returns:
the request context that matches the passed request and response objects

service

public void service(Servlet servlet,
                    ServletRequest req,
                    ServletResponse resp)
             throws ServletException,
                    IOException
Issue the service call to the specified servlet, given the passed request and response objects.

Parameters:
servlet - the servlet to invoke
req - a ServletRequest object that might need wrapping or might have already been wrapped
resp - might a ServletResponse object that might need wrapping or have already been wrapped
Throws:
ServletException
IOException

preService

public RequestContext preService(ServletRequest req,
                                 ServletResponse res)
                          throws ServletException,
                                 IOException
Wrap the passed request and response (if necessary) and build a request context that contains all the pertinent information about the request. This also touches the pre-existing session, if any, if this is the "point of initial entry" into the web container.

Parameters:
req - the servlet response object (could already be wrapped)
res - the servlet response object (could already be wrapped)
Returns:
a request context that contains all the information about this request that is being processed
Throws:
ServletException
IOException

postService

public void postService(RequestContext ctx)
                 throws ServletException,
                        IOException
Finish the request processing after the servlet/jsp is complete. This includes marking the session (if new) as not new and releasing any locks.

Parameters:
ctx - the request context returned by preService()
Throws:
ServletException
IOException

wrapRequestDispatcher

public RequestDispatcher wrapRequestDispatcher(RequestDispatcher disp)
Wrap the specified RequestDispatcher object from the container.

Parameters:
disp - the request dispatcher object from the container
Returns:
the RequestDispatcher object to give to the application to use

isRequestUnwrapRequired

public boolean isRequestUnwrapRequired()
Determine if the custom servlet request wrapper needs to be unwrapped before including or forwarding to other content. In other words, if the app server will choke on the custom request wrapper, then unwrap it to the app server's own request object.

Returns:
true if the app server will choke on the request wrapper

isResponseUnwrapRequired

public boolean isResponseUnwrapRequired()
Determine if the custom servlet response wrapper needs to be unwrapped before including or forwarding to other content. In other words, if the app server will choke on the custom response wrapper, then unwrap it to the app server's own response object.

Returns:
true if the app server will choke on the response wrapper

preDispatch

public Map preDispatch(ServletRequest req,
                       ServletResponse res)
Prepares a Servlet request to be dispatched by a RequestDispatcher. The Servlet request and response objects that should be passed to the RequestDispatcher can be retrieved from the returned Map using the KEY_REQUEST_RESOLVED and KEY_RESPONSE_RESOLVED keys.

After the request has been dispatched postDispatch must be called with the Map returned from this method.

This method prepares the Servlet request by calling saveRequestState on the request context. If the dispatch request was made from an "external" web application (a web application with a different ServetContext), it is possible that the class of the request context object was loaded by a different ClassLoader than that of the request context class referenced here. In this case, reflection is used to invoke saveRequestState and a new request context is created for the request.

Parameters:
req - a ServletRequest object that contains the client's request
res - a ServletResponse object that contains the servlet's response
Returns:
a Map that contains all request state that must be restored after the request has been dispatched.

postDispatch

public void postDispatch(ServletRequest req,
                         Map map)
Restores a Servlet request to the state it was in prior to being dispatched.

This method restores the Servlet request state by calling restoreRequestState on the request context. If the dispatch request was made from an "external" web application (a web application with a different ServetContext), it is possible that the class of the request context object was loaded by a different ClassLoader than that of the request context class referenced here. In this case, reflection is used to invoke restoreRequestState.

Parameters:
req - the dispatched Servlet request
map - the Map returned from a call to preDispatch

resolveRequest

public ServletRequest resolveRequest(ServletRequest req)
Determine what request object should be sent to the application server's request dispatcher: the application server's request object, or the wrapper that we created.

Parameters:
req - the ServletRequest object that the application passed to the request dispatcher wrapper
Returns:
the ServletRequest object to use

resolveResponse

public ServletResponse resolveResponse(ServletRequest req,
                                       ServletResponse res)
Determine what response object should be sent to the application server's request dispatcher: the application server's response object, or the wrapper that we created.

Parameters:
req - the ServletRequest object that the application passed to the request dispatcher wrapper
res - the ServletResponse object that the application passed to the request dispatcher wrapper
Returns:
the ServletResponse object to use

instantiateHttpSessionCollection

protected HttpSessionCollection instantiateHttpSessionCollection()
Get the HttpSessionCollection object that manages the HttpSessionModel objects.

Returns:
the HttpSessionCollection that manages the session models for the application

getHttpSessionCollection

public HttpSessionCollection getHttpSessionCollection()
Get the HttpSessionCollection object that manages the HttpSessionModel objects.

Returns:
the HttpSessionCollection that manages the session models for the application

getHttpSessionMap

protected Map getHttpSessionMap()
Get the map of session ID to session object for HttpSession objects managed in this application within this JVM/classloader.

Returns:
the map of session IDs to HttpSession objects

createHttpSession

public HttpSession createHttpSession()
Create a new HttpSession object.

Returns:
an HttpSession object

getHttpSession

public HttpSession getHttpSession(String sId)
Get the HttpSession object for the specified ID.

Parameters:
sId - the session ID
Returns:
an HttpSession object, if it exists, or null

isSessionContextEnabled

public boolean isSessionContextEnabled()
Determine if the session context should disobey the deprecation and allow an application to enumerate sessions.

Returns:
true if the session context should allow the application to enumerate sessions

getHttpSessionContext

public HttpSessionContext getHttpSessionContext()
Get the HttpSessionContext.

Returns:
an HttpSessionContext object

isSessionIdCookieEnabled

public boolean isSessionIdCookieEnabled()
Determine if a cookie may be used to hold the session ID.

Returns:
true if a cookie may be used to hold the session ID

getSessionIdCookieName

public String getSessionIdCookieName()
Determine the name of the cookie for holding the session ID.

Returns:
the name of the cookie for holding the session ID

getSessionIdCookieDomain

public String getSessionIdCookieDomain()
Determine the domain of the cookie for holding the session ID.

Returns:
the domain of the cookie for holding the session ID

getSessionIdCookiePath

public String getSessionIdCookiePath()
Determine the path of the cookie for holding the session ID.

Returns:
the path of the cookie for holding the session ID

getSessionIdCookieMaxAge

public int getSessionIdCookieMaxAge()
Determine the max age (in seconds) of the cookie for holding the session ID.

Returns:
the max age of the cookie for holding the session ID

isSessionIdEncodingEnabled

public boolean isSessionIdEncodingEnabled()
Determine if URL encoding may be used to hold the session ID.

Returns:
true if URL encoding may be used to hold the session ID

getSessionIdEncodingName

public String getSessionIdEncodingName()
Determine the name of the URL parameter for session ID encoding and decoding.

Returns:
the name of the URL parameter that contains the session id

isUseDefaultSessionIdDecoding

public boolean isUseDefaultSessionIdDecoding()
Determine if the session ID decoding (from a URL) performed by the application server's request object is sufficient. Sometimes, it is necessary to use the application server's own decoding because it will "hide" the "jsessionid" parameter, making custom parsing impossible.

Returns:
true to use the session ID provided by the application server's request object

isUseDefaultSessionIdEncoding

public boolean isUseDefaultSessionIdEncoding()
Determine if the session ID encoding (into a URL) performed by the application server's response object is sufficient. This will be false for all known cases, since the container has no way of knowing the session ID of the custom session implementation.

Returns:
true to use the app server to URL encode the session ID; false to use the custom implementation to encode it

decodeUrl

public String decodeUrl(HttpServletRequest request)
Decodes the session ID from the URL represented by the passed request.

Parameters:
request - the current HttpServletRequest
Returns:
the session id if there were one encoded in the URL, otherwise null

encodeUrl

public String encodeUrl(String sUrl,
                        HttpServletRequest request)
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary.

Parameters:
sUrl - the URL to be encoded
request - the current HttpServletRequest
Returns:
the encoded URL if encoding is needed; the unchanged URL otherwise

encodeUrl

protected String encodeUrl(String sUrl,
                           String sId)
Encodes the specified URL by including the given session ID in it.

Parameters:
sUrl - the URL to be encoded
sId - the session ID to encode in the URL
Returns:
the encoded URL

requestAsyncOwnership

public void requestAsyncOwnership(String sId)
Enter (obtain) and schedule an asynchronous call to exit (release) the specified session ID.

Parameters:
sId - the session ID to async enter and exit

shutdownHttpSessionCollection

public void shutdownHttpSessionCollection()
Shutdown the http session collection.


toString

public String toString()
Returns a string representation of the object.

Returns:
a string representation of the object

getConfigurationCache

public NamedCache getConfigurationCache()
Get the NamedCache used to store configuration and management information for the session management implementation.

Returns:
the clustered cache used to store configuration and management information

ensureConfigurationCache

protected NamedCache ensureConfigurationCache()
Get the NamedCache used to store configuration and management information for the session management implementation if it exists, otherwise create it.

Returns:
the clustered cache used to store configuration and management information

shutdownConfigurationCache

protected void shutdownConfigurationCache()
Shutdown the NamedCache used to store configuration and management information for the session management implementation.


getDescription

protected String getDescription()
Returns a string representation of this object's attributes.

Returns:
a string representation of this object's attributes

getFactory

public SessionHelper.Factory getFactory()
Determine the factory to use to instantiate container-specific implementations of the Servlet specification interfaces.

Returns:
the factory used by the session helper

instantiateSessionReaperDaemon

protected SessionHelper.SessionReaperDaemon instantiateSessionReaperDaemon()
Factory method: Instantiate a daemon thread that will clean up expired sessions.


getSessionReaperDaemon

protected SessionHelper.SessionReaperDaemon getSessionReaperDaemon()
Get the daemon thread that cleans up expired sessions.

Returns:
the session reaper daemon, if it exists, otherwise null

getDaemonPriority

protected int getDaemonPriority()
Determine the configured priority for the session reaper daemon.

Returns:
the configured priority of the session reaper daemon

getDaemonCycleMillis

protected long getDaemonCycleMillis()
Determine the number of milliseconds per reap cycle. This means that a new cycle will not start until this many milliseconds has passed since the previous cycle started.

Returns:
the number of milliseconds per reap cycle

getDaemonCheckCollectionModulo

protected int getDaemonCheckCollectionModulo()
Determine how many times the daemon will perform its check before checking the session models that the collection considers "local".

Returns:
the modulo on which the daemon will check the session models that the collection considers "local"

isDaemonCheckCoordinated

protected boolean isDaemonCheckCoordinated()
Determine if the reaper daemon coordinates the check across the cluster instead of just doing its own "local" scan.

Returns:
true if the daemon coordinates a global scan with other nodes in the cluster

isDaemonAssumeLocality

protected boolean isDaemonAssumeLocality()
Determine if the reaper daemon assumes that session data is stored only on nodes that are running the session reaper daemon thread.

Returns:
true if the daemon can assume that all cluster nodes that store sessions are also running a reaper daemon

checkForDeadSessions

protected void checkForDeadSessions()
Discard the HttpSession objects that are no longer alive.


checkExpiredSessionId

protected void checkExpiredSessionId(String sId)
Check the specified session to see if it has expired.

Parameters:
sId - a session id

killSession

public void killSession(String sId)
Forcibly destroy a session. Use HttpSession invalidate method instead; this is only a last-ditch attempt to get rid of the session model when nothing else works.

Parameters:
sId - the session ID to destroy

shutdownSessionReaperDaemon

public void shutdownSessionReaperDaemon()
Stop the daemon thread that is used for expiring sessions.


instantiateSessionWorkerDaemon

protected TaskDaemon instantiateSessionWorkerDaemon()
Factory method: Instantiate a daemon thread that will be used for scheduled tasks.

Returns:
a new session worker daemon, but without starting the thread

getSessionWorkerDaemon

protected TaskDaemon getSessionWorkerDaemon()
Get the daemon thread that is used for scheduled tasks.

Returns:
the session worker daemon, or null if it does not exist

setSessionWorkerDaemon

protected void setSessionWorkerDaemon(TaskDaemon daemon)
Set the daemon thread that is used for scheduled tasks.

Parameters:
daemon - the session worker daemon

ensureSessionWorkerDaemon

public TaskDaemon ensureSessionWorkerDaemon()
Get the daemon thread that is used for scheduled tasks, creating it if necessary.

Returns:
the session worker daemon

shutdownSessionWorkerDaemon

public void shutdownSessionWorkerDaemon()
Stop the daemon thread that is used for scheduled tasks.


formatListeners

public static String formatListeners(Listeners listeners)
Format a Listeners object into a human readable string.

Parameters:
listeners - a Listeners object
Returns:
a human readable description of the Listeners contents

formatCacheName

public static String formatCacheName(NamedCache cache)
Format a NamedCache object into a human readable string.

Parameters:
cache - a NamedCache object
Returns:
a human readable string describing the named cache

formatMapKeys

public static String formatMapKeys(Map map)
Format a map into a list of keys.

Parameters:
map - a Map object
Returns:
a human readable list of keys from the Map

logEventException

public static void logEventException(RuntimeException e,
                                     String sMethod,
                                     boolean fContinue)
Log an event exception.

Parameters:
e - the exception
sMethod - the event method name etc.
fContinue - true if the execution will be continued; false if the exception has to be logged and re-thrown

CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation