org.szegedi.spring.web.jsflow
Class HttpSessionFlowStateStorage

java.lang.Object
  extended by org.szegedi.spring.web.jsflow.support.FlowStateSerializer
      extended by org.szegedi.spring.web.jsflow.HttpSessionFlowStateStorage
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, FlowStateStorage

public class HttpSessionFlowStateStorage
extends FlowStateSerializer
implements FlowStateStorage

An implementation for flow state storage that stores flow states in the HttpSession objects. As states are stored privately to HTTP sessions, no crossover between sessions is possible (requesting a state from a session it doesn't belong to won't work, and it is also possible to have identical flowstate ids in two sessions without any interference).

Version:
$Id: HttpSessionFlowStateStorage.java 104 2009-12-01 18:44:14Z szegedia $
Author:
Attila Szegedi

Nested Class Summary
static interface HttpSessionFlowStateStorage.ContinuationCallback
          Should be implemented by classes used as callbacks for forEachContinuation(HttpSession, ContinuationCallback)
 
Nested classes/interfaces inherited from class org.szegedi.spring.web.jsflow.support.FlowStateSerializer
FlowStateSerializer.StubProvider, FlowStateSerializer.StubResolver
 
Constructor Summary
HttpSessionFlowStateStorage()
           
 
Method Summary
 void afterPropertiesSet()
           
static void bindStubProvider(javax.servlet.http.HttpSession session, FlowStateSerializer.StubProvider provider)
          Binds a stub provider into the HttpSession.
static void bindStubResolver(javax.servlet.http.HttpSession session, FlowStateSerializer.StubResolver resolver)
          Binds a stub resolver into the HttpSession.
 void forEachContinuation(javax.servlet.http.HttpSession session, HttpSessionFlowStateStorage.ContinuationCallback callback)
          Enumerates all the continuations bound to a particular HTTP session.
 org.mozilla.javascript.NativeContinuation getState(javax.servlet.http.HttpServletRequest request, java.lang.String id)
          Retrieves the state associated with a request
 void setFlowStateIdGenerator(FlowStateIdGenerator flowStateIdGenerator)
           
 void setMaxStates(int maxStates)
          Sets the maximum number of states per HTTP session that this manager will store.
 void setRandom(java.util.Random random)
          Deprecated. use setFlowStateIdGenerator(FlowStateIdGenerator) with a RandomFlowStateIdGenerator instead.
 java.lang.String storeState(javax.servlet.http.HttpServletRequest request, org.mozilla.javascript.NativeContinuation state)
          Stores the state associated with the current request
 
Methods inherited from class org.szegedi.spring.web.jsflow.support.FlowStateSerializer
deserializeContinuation, getScriptStorage, serializeContinuation, setApplicationContext, setScriptStorage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpSessionFlowStateStorage

public HttpSessionFlowStateStorage()
Method Detail

setMaxStates

public void setMaxStates(int maxStates)
Sets the maximum number of states per HTTP session that this manager will store. If the number is exceeded, the least recently used state will be discareded. Defaults to 100.

Parameters:
maxStates -

setRandom

public void setRandom(java.util.Random random)
Deprecated. use setFlowStateIdGenerator(FlowStateIdGenerator) with a RandomFlowStateIdGenerator instead.

Sets a source of randomness for generating state IDs. If not explicitly set, it will create and use a private instance of SecureRandom.

Parameters:
random -

setFlowStateIdGenerator

public void setFlowStateIdGenerator(FlowStateIdGenerator flowStateIdGenerator)

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Overrides:
afterPropertiesSet in class FlowStateSerializer
Throws:
java.lang.Exception

bindStubProvider

public static void bindStubProvider(javax.servlet.http.HttpSession session,
                                    FlowStateSerializer.StubProvider provider)
Binds a stub provider into the HttpSession. Client code can use this provider to provide serialization stubs for various session-related objects

Parameters:
session - the HttpSession to bind the provider into
provider - the provider
Since:
1.2

bindStubResolver

public static void bindStubResolver(javax.servlet.http.HttpSession session,
                                    FlowStateSerializer.StubResolver resolver)
Binds a stub resolver into the HttpSession. Client code can use this resolver to resolve serialization stubs for various session-related objects

Parameters:
session - the HttpSession to bind the resolver into
resolver - the resolver
Since:
1.2

storeState

public java.lang.String storeState(javax.servlet.http.HttpServletRequest request,
                                   org.mozilla.javascript.NativeContinuation state)
Description copied from interface: FlowStateStorage
Stores the state associated with the current request

Specified by:
storeState in interface FlowStateStorage
Parameters:
request - the HTTP request
state - the state
Returns:
an identifier for the state. The identifier is unique at least in the scope of the current HTTP request's session.

getState

public org.mozilla.javascript.NativeContinuation getState(javax.servlet.http.HttpServletRequest request,
                                                          java.lang.String id)
Description copied from interface: FlowStateStorage
Retrieves the state associated with a request

Specified by:
getState in interface FlowStateStorage
Parameters:
request - the HTTP request
id - the unique identifier for the flow state
Returns:
the flow state, or null if it couldn't be resolved

forEachContinuation

public void forEachContinuation(javax.servlet.http.HttpSession session,
                                HttpSessionFlowStateStorage.ContinuationCallback callback)
Enumerates all the continuations bound to a particular HTTP session. Can be used from a session listener to post-process continuations in invalidated/expired sessions.

Parameters:
session - the http session
callback - a callback that will be invoked for each continuation.