Spring Web Flow

org.springframework.webflow.context.servlet
Class ServletExternalContext

java.lang.Object
  extended by org.springframework.webflow.context.servlet.ServletExternalContext
All Implemented Interfaces:
ExternalContext
Direct Known Subclasses:
MvcExternalContext

public class ServletExternalContext
extends java.lang.Object
implements ExternalContext

Provides contextual information about an HTTP Servlet environment that has interacted with Spring Web Flow.

Author:
Keith Donald, Erwin Vervaet, Jeremy Grelle

Constructor Summary
ServletExternalContext(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Create a new external context wrapping given servlet HTTP request and response and given servlet context.
ServletExternalContext(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, FlowUrlHandler flowUrlHandler)
          Create a new external context wrapping given servlet HTTP request and response and given servlet context.
 
Method Summary
 SharedAttributeMap<java.lang.Object> getApplicationMap()
          Provides access to the external application map, providing a storage for data local to the current user application and accessible to both internal and external SWF artifacts.
protected  javax.servlet.ServletContext getContext()
          Returns the servlet context.
 java.lang.String getContextPath()
          Returns the logical path to the application hosting this external context.
 java.security.Principal getCurrentUser()
          Provides access to the user's principal security object.
 boolean getExternalRedirectRequested()
          Returns the flag indicating if an external redirect response has been requested by the flow.
 java.lang.String getExternalRedirectUrl()
          Returns the URL to redirect to.
 boolean getFlowDefinitionRedirectRequested()
          Returns the flag indicating if a flow definition redirect response has been requested by the flow.
 boolean getFlowExecutionRedirectRequested()
          Returns the flag indicating if a flow execution redirect response has been requested by the flow.
 java.lang.String getFlowExecutionUrl(java.lang.String flowId, java.lang.String flowExecutionKey)
          Get a flow execution URL for the execution with the provided key.
 java.lang.String getFlowRedirectFlowId()
          Returns the id of the flow definition to redirect to.
 MutableAttributeMap<java.lang.Object> getFlowRedirectFlowInput()
          Returns the input to pass the flow definition through the redirect.
protected  FlowUrlHandler getFlowUrlHandler()
          Returns the configured flow url handler.
 SharedAttributeMap<java.lang.Object> getGlobalSessionMap()
          Provides access to the global external session map, providing a storage for data globally accross the user session and accessible to both internal and external SWF artifacts.
 java.util.Locale getLocale()
          Returns the client locale.
 java.lang.Object getNativeContext()
          Provides access to the context object for the current environment.
 java.lang.Object getNativeRequest()
          Provides access to the request object for the current environment.
 java.lang.Object getNativeResponse()
          Provides access to the response object for the current environment.
 boolean getRedirectInPopup()
          If a redirect response has been requested, indicates if the redirect should be issued from a popup dialog.
protected  javax.servlet.http.HttpServletRequest getRequest()
          Returns the underlying HttpServletRequest.
 MutableAttributeMap<java.lang.Object> getRequestMap()
          Provides access to the external request attribute map, providing a storage for data local to the current user request and accessible to both internal and external SWF artifacts.
 ParameterMap getRequestParameterMap()
          Provides access to the parameters associated with the user request that led to SWF being called.
protected  javax.servlet.http.HttpServletResponse getResponse()
          Returns the underlying HttpServletResponse.
 java.io.Writer getResponseWriter()
          Get a writer for writing out a response.
 SharedAttributeMap<java.lang.Object> getSessionMap()
          Provides access to the external session map, providing a storage for data local to the current user session and accessible to both internal and external SWF artifacts.
 boolean isAjaxRequest()
          Returns true if the current request is an asynchronous Ajax request.
 boolean isResponseAllowed()
          Is a render response allowed to be written for this request? Always return false after a response has been completed.
 boolean isResponseComplete()
          Has the response been completed? Response complete status can be achieved by: Writing out the response and calling ExternalContext.recordResponseComplete(), or Calling one of the redirect request methods
 boolean isResponseCompleteFlowExecutionRedirect()
          Returns true if the response has been completed with flow execution redirect request.
 void recordResponseComplete()
          Called by flow artifacts such as View states and end states to indicate they handled the response, typically by writing out content to the response stream.
 void requestExternalRedirect(java.lang.String location)
          Request a redirect to an arbitrary resource location.
 void requestFlowDefinitionRedirect(java.lang.String flowId, MutableAttributeMap<?> input)
          Request that a flow definition redirect be performed by the calling environment.
 void requestFlowExecutionRedirect()
          Request that a flow execution redirect be performed by the calling environment.
 void requestRedirectInPopup()
          Request that the current redirect requested be sent to the client in a manner that causes the client to issue the redirect from a popup dialog.
 void setAjaxRequest(boolean ajaxRequest)
          Indicates if the current request from this client is an ajax request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletExternalContext

public ServletExternalContext(javax.servlet.ServletContext context,
                              javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
Create a new external context wrapping given servlet HTTP request and response and given servlet context.

Parameters:
context - the servlet context
request - the http servlet request
response - the http servlet response

ServletExternalContext

public ServletExternalContext(javax.servlet.ServletContext context,
                              javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response,
                              FlowUrlHandler flowUrlHandler)
Create a new external context wrapping given servlet HTTP request and response and given servlet context.

Parameters:
context - the servlet context
request - the http servlet request
response - the http servlet response
flowUrlHandler - the flow url handler
Method Detail

setAjaxRequest

public void setAjaxRequest(boolean ajaxRequest)
Indicates if the current request from this client is an ajax request. This flag may effect the handling of response writing within Spring Web Flow.

Parameters:
ajaxRequest - the ajax request flag

getContextPath

public java.lang.String getContextPath()
Description copied from interface: ExternalContext
Returns the logical path to the application hosting this external context.

Specified by:
getContextPath in interface ExternalContext
Returns:
the context path

getRequestParameterMap

public ParameterMap getRequestParameterMap()
Description copied from interface: ExternalContext
Provides access to the parameters associated with the user request that led to SWF being called. This map is expected to be immutable and cannot be changed.

Specified by:
getRequestParameterMap in interface ExternalContext
Returns:
the immutable request parameter map

getRequestMap

public MutableAttributeMap<java.lang.Object> getRequestMap()
Description copied from interface: ExternalContext
Provides access to the external request attribute map, providing a storage for data local to the current user request and accessible to both internal and external SWF artifacts.

Specified by:
getRequestMap in interface ExternalContext
Returns:
the mutable request attribute map

getSessionMap

public SharedAttributeMap<java.lang.Object> getSessionMap()
Description copied from interface: ExternalContext
Provides access to the external session map, providing a storage for data local to the current user session and accessible to both internal and external SWF artifacts.

Specified by:
getSessionMap in interface ExternalContext
Returns:
the mutable session attribute map

getGlobalSessionMap

public SharedAttributeMap<java.lang.Object> getGlobalSessionMap()
Description copied from interface: ExternalContext
Provides access to the global external session map, providing a storage for data globally accross the user session and accessible to both internal and external SWF artifacts.

Note: most external context implementations do not distinguish between the concept of a "local" user session scope and a "global" session scope. The Portlet world does, but not the Servlet for example. In those cases calling this method returns the same map as calling ExternalContext.getSessionMap().

Specified by:
getGlobalSessionMap in interface ExternalContext
Returns:
the mutable global session attribute map

getApplicationMap

public SharedAttributeMap<java.lang.Object> getApplicationMap()
Description copied from interface: ExternalContext
Provides access to the external application map, providing a storage for data local to the current user application and accessible to both internal and external SWF artifacts.

Specified by:
getApplicationMap in interface ExternalContext
Returns:
the mutable application attribute map

getCurrentUser

public java.security.Principal getCurrentUser()
Description copied from interface: ExternalContext
Provides access to the user's principal security object.

Specified by:
getCurrentUser in interface ExternalContext
Returns:
the user principal

getLocale

public java.util.Locale getLocale()
Description copied from interface: ExternalContext
Returns the client locale.

Specified by:
getLocale in interface ExternalContext
Returns:
the locale

getNativeContext

public java.lang.Object getNativeContext()
Description copied from interface: ExternalContext
Provides access to the context object for the current environment.

Specified by:
getNativeContext in interface ExternalContext
Returns:
the environment specific context object

getNativeRequest

public java.lang.Object getNativeRequest()
Description copied from interface: ExternalContext
Provides access to the request object for the current environment.

Specified by:
getNativeRequest in interface ExternalContext
Returns:
the environment specific request object.

getNativeResponse

public java.lang.Object getNativeResponse()
Description copied from interface: ExternalContext
Provides access to the response object for the current environment.

Specified by:
getNativeResponse in interface ExternalContext
Returns:
the environment specific response object.

isAjaxRequest

public boolean isAjaxRequest()
Description copied from interface: ExternalContext
Returns true if the current request is an asynchronous Ajax request.

Specified by:
isAjaxRequest in interface ExternalContext
Returns:
true if the current request is an Ajax request

getFlowExecutionUrl

public java.lang.String getFlowExecutionUrl(java.lang.String flowId,
                                            java.lang.String flowExecutionKey)
Description copied from interface: ExternalContext
Get a flow execution URL for the execution with the provided key. Typically used by response writers that write out references to the flow execution to support postback on a subsequent request. The URL returned is encoded.

Specified by:
getFlowExecutionUrl in interface ExternalContext
Parameters:
flowId - the flow definition id
flowExecutionKey - the flow execution key
Returns:
the flow execution URL

getResponseWriter

public java.io.Writer getResponseWriter()
                                 throws java.lang.IllegalStateException
Description copied from interface: ExternalContext
Get a writer for writing out a response.

Specified by:
getResponseWriter in interface ExternalContext
Returns:
the writer
Throws:
java.lang.IllegalStateException - if the response has completed or is not allowed

isResponseAllowed

public boolean isResponseAllowed()
Description copied from interface: ExternalContext
Is a render response allowed to be written for this request? Always return false after a response has been completed. May return false before that to indicate a response is not allowed to be completed. For example, in a Portlet environment, render responses are only allowed in render requests.

Specified by:
isResponseAllowed in interface ExternalContext
Returns:
true if yes, false otherwise

isResponseComplete

public boolean isResponseComplete()
Description copied from interface: ExternalContext
Has the response been completed? Response complete status can be achieved by:

Specified by:
isResponseComplete in interface ExternalContext
Returns:
true if yes, false otherwise
See Also:
ExternalContext.getResponseWriter(), ExternalContext.recordResponseComplete(), ExternalContext.requestFlowExecutionRedirect(), ExternalContext.requestFlowDefinitionRedirect(String, MutableAttributeMap), ExternalContext.requestExternalRedirect(String)

recordResponseComplete

public void recordResponseComplete()
Description copied from interface: ExternalContext
Called by flow artifacts such as View states and end states to indicate they handled the response, typically by writing out content to the response stream. Setting this flag allows this external context to know the response was handled, and that it not need to take additional response handling action itself.

Specified by:
recordResponseComplete in interface ExternalContext

isResponseCompleteFlowExecutionRedirect

public boolean isResponseCompleteFlowExecutionRedirect()
Description copied from interface: ExternalContext
Returns true if the response has been completed with flow execution redirect request.

Specified by:
isResponseCompleteFlowExecutionRedirect in interface ExternalContext
Returns:
true if a redirect response has been completed
See Also:
ExternalContext.isResponseComplete(), ExternalContext.requestFlowExecutionRedirect()

requestFlowExecutionRedirect

public void requestFlowExecutionRedirect()
                                  throws java.lang.IllegalStateException
Description copied from interface: ExternalContext
Request that a flow execution redirect be performed by the calling environment. Typically called from within a flow execution to request a refresh operation, usually to support "refresh after event processing" behavior. Calling this method also sets responseComplete status to true.

Specified by:
requestFlowExecutionRedirect in interface ExternalContext
Throws:
java.lang.IllegalStateException - if the response has completed
See Also:
ExternalContext.isResponseComplete()

requestFlowDefinitionRedirect

public void requestFlowDefinitionRedirect(java.lang.String flowId,
                                          MutableAttributeMap<?> input)
                                   throws java.lang.IllegalStateException
Description copied from interface: ExternalContext
Request that a flow definition redirect be performed by the calling environment. Typically called from within a flow execution end state to request starting a new, independent execution of a flow in a chain-like manner. Calling this method also sets responseComplete status to true.

Specified by:
requestFlowDefinitionRedirect in interface ExternalContext
Parameters:
flowId - the id of the flow definition to redirect to
input - input to pass the flow; this input is generally encoded the url to launch the flow
Throws:
java.lang.IllegalStateException - if the response has completed
See Also:
ExternalContext.isResponseComplete()

requestExternalRedirect

public void requestExternalRedirect(java.lang.String location)
                             throws java.lang.IllegalStateException
Description copied from interface: ExternalContext
Request a redirect to an arbitrary resource location. May not be supported in some environments. Calling this method also sets responseComplete status to true.

Specified by:
requestExternalRedirect in interface ExternalContext
Parameters:
location - the location of the resource to redirect to
Throws:
java.lang.IllegalStateException - if the response has completed
See Also:
ExternalContext.isResponseComplete()

requestRedirectInPopup

public void requestRedirectInPopup()
                            throws java.lang.IllegalStateException
Description copied from interface: ExternalContext
Request that the current redirect requested be sent to the client in a manner that causes the client to issue the redirect from a popup dialog. Only call this method after a redirect has been requested.

Specified by:
requestRedirectInPopup in interface ExternalContext
Throws:
java.lang.IllegalStateException - if a redirect has not been requested
See Also:
ExternalContext.requestFlowExecutionRedirect(), ExternalContext.requestFlowDefinitionRedirect(String, MutableAttributeMap), ExternalContext.requestExternalRedirect(String)

getFlowExecutionRedirectRequested

public boolean getFlowExecutionRedirectRequested()
Returns the flag indicating if a flow execution redirect response has been requested by the flow.


getFlowDefinitionRedirectRequested

public boolean getFlowDefinitionRedirectRequested()
Returns the flag indicating if a flow definition redirect response has been requested by the flow.


getFlowRedirectFlowId

public java.lang.String getFlowRedirectFlowId()
Returns the id of the flow definition to redirect to. Only set when getFlowDefinitionRedirectRequested() returns true.


getFlowRedirectFlowInput

public MutableAttributeMap<java.lang.Object> getFlowRedirectFlowInput()
Returns the input to pass the flow definition through the redirect. Only set when getFlowDefinitionRedirectRequested() returns true.


getExternalRedirectRequested

public boolean getExternalRedirectRequested()
Returns the flag indicating if an external redirect response has been requested by the flow.


getExternalRedirectUrl

public java.lang.String getExternalRedirectUrl()
Returns the URL to redirect to. Only set if getExternalRedirectRequested() returns true.


getRedirectInPopup

public boolean getRedirectInPopup()
If a redirect response has been requested, indicates if the redirect should be issued from a popup dialog.


getContext

protected javax.servlet.ServletContext getContext()
Returns the servlet context.


getRequest

protected javax.servlet.http.HttpServletRequest getRequest()
Returns the underlying HttpServletRequest.


getResponse

protected javax.servlet.http.HttpServletResponse getResponse()
Returns the underlying HttpServletResponse.


getFlowUrlHandler

protected FlowUrlHandler getFlowUrlHandler()
Returns the configured flow url handler.


Spring Web Flow