org.szegedi.spring.web.jsflow.support
Class AbstractFlowStateStorage

java.lang.Object
  extended by org.szegedi.spring.web.jsflow.support.FlowStateSerializer
      extended by org.szegedi.spring.web.jsflow.support.AbstractFlowStateStorage
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, FlowStateStorage
Direct Known Subclasses:
ClientSideFlowStateStorage, JdbcFlowStateStorage

public abstract class AbstractFlowStateStorage
extends FlowStateSerializer
implements FlowStateStorage

A flow state storage that serializes the flow states. It requires access to a script storage. If none is configured, then the FlowController will pass it its own script storage - this is usually the intention.

When creating the serialized flowstates, it stubs all the application context beans and script function objects, thus minimizing the size of the serialized state. When deserializing, it will reattach the deserialized state to stubbed objects, resolving them by name. This way, it is allowed to have references to application context objects in the reachability graph of the serialized state, as they will get stubbed and resolved correctly. It is however strongly not advised to have references to any other external objects in the running scripts or objects referenced by them, as they will either fail serialization, or - lacking stubbing - cause duplicate instances to be created upon deserialization.

As a safety feature, the MD5 fingerprint of each function's code that is on the continuation's call stack is stored along with the continuation, and matched upon retrieval, with an exception being thrown if they don't match. In case that the underlying script changed since the continuation last run (i.e. because you restarted the servlet context and reloaded a changed script) this causes clean fast failure, instead of unpredictable behavior caused by invalid return addresses in the continuation stack frames.

The class supports setting a BinaryStateCodec, enabling pluggable compression, encryption, and/or digital signing of the serialized state. This is most useful with the ClientSideFlowStateStorage subclass where the client is entrusted with storing the flowstates, so you might wish to ensure they're resistant to tampering.

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

Nested Class Summary
 
Nested classes/interfaces inherited from class org.szegedi.spring.web.jsflow.support.FlowStateSerializer
FlowStateSerializer.StubProvider, FlowStateSerializer.StubResolver
 
Constructor Summary
AbstractFlowStateStorage()
           
 
Method Summary
protected abstract  byte[] getSerializedState(javax.servlet.http.HttpServletRequest request, java.lang.String id)
          Implement in subclasses to retrieve the serialized state.
 org.mozilla.javascript.NativeContinuation getState(javax.servlet.http.HttpServletRequest request, java.lang.String id)
          Retrieves the state associated with a request
 void setBinaryStateCodec(BinaryStateCodec binaryStateCodec)
           
protected abstract  java.lang.String storeSerializedState(javax.servlet.http.HttpServletRequest request, byte[] state)
          Implement in subclasses to store the serialized state.
 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
afterPropertiesSet, 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

AbstractFlowStateStorage

public AbstractFlowStateStorage()
Method Detail

setBinaryStateCodec

public void setBinaryStateCodec(BinaryStateCodec binaryStateCodec)

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

getSerializedState

protected abstract byte[] getSerializedState(javax.servlet.http.HttpServletRequest request,
                                             java.lang.String id)
                                      throws java.lang.Exception
Implement in subclasses to retrieve the serialized state.

Parameters:
request - the HTTP request that triggered the retrieval. Can be used to implement session-private storages for states.
id - the id of the state
Returns:
the byte array representing the serialized state
Throws:
java.lang.Exception

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.

storeSerializedState

protected abstract java.lang.String storeSerializedState(javax.servlet.http.HttpServletRequest request,
                                                         byte[] state)
                                                  throws java.lang.Exception
Implement in subclasses to store the serialized state.

Parameters:
request - the HTTP request that triggered the store operation. Can be used to implement session-private storages for states.
state - byte array representing the serialized state
Returns:
the id of the state
Throws:
java.lang.Exception