Interface ExternalContext
- All Known Implementing Classes:
MockExternalContext
,MvcExternalContext
,ServletExternalContext
This context object provides a normalized interface for internal web flow artifacts to use to reason on and manipulate the state of an external actor calling into SWF to execute flows. It represents the context about a single, external client request to manipulate a flow execution.
The design of this interface was inspired by JSF's own ExternalContext abstraction and shares the same name for
consistency. If a particular external client type does not support all methods defined by this interface, they can
just be implemented as returning an empty map or null
.
- Author:
- Keith Donald, Erwin Vervaet, Jeremy Grelle, Scott Andrews
-
Method Summary
Modifier and TypeMethodDescriptionProvides 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.Returns the logical path to the application hosting this external context.Provides access to the user's principal security object.getFlowExecutionUrl
(String flowId, String flowExecutionKey) Get a flow execution URL for the execution with the provided key.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.Returns the client locale.Provides access to the context object for the current environment.Provides access to the request object for the current environment.Provides access to the response object for the current environment.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.Provides access to the parameters associated with the user request that led to SWF being called.Get a writer for writing out a response.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
Returns true if the current request is an asynchronous Ajax request.boolean
Is a render response allowed to be written for this request? Always return false after a response has been completed.boolean
Has the response been completed? Response complete status can be achieved by: Writing out the response and callingrecordResponseComplete()
, or Calling one of the redirect request methodsboolean
Returns true if the response has been completed with flow execution redirect request.void
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
(String location) Request a redirect to an arbitrary resource location.void
requestFlowDefinitionRedirect
(String flowId, MutableAttributeMap<?> input) Request that a flow definition redirect be performed by the calling environment.void
Request that a flow execution redirect be performed by the calling environment.void
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.
-
Method Details
-
getContextPath
String getContextPath()Returns the logical path to the application hosting this external context.- Returns:
- the context path
-
getRequestParameterMap
ParameterMap getRequestParameterMap()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.- Returns:
- the immutable request parameter map
-
getRequestMap
MutableAttributeMap<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.- Returns:
- the mutable request attribute map
-
getSessionMap
SharedAttributeMap<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.- Returns:
- the mutable session attribute map
-
getGlobalSessionMap
SharedAttributeMap<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.Note: most external context implementations do not distinguish between the concept of a "local" user session scope and a "global" session scope. Otherwise this method returns the same map as calling
getSessionMap()
.- Returns:
- the mutable global session attribute map
-
getApplicationMap
SharedAttributeMap<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.- Returns:
- the mutable application attribute map
-
isAjaxRequest
boolean isAjaxRequest()Returns true if the current request is an asynchronous Ajax request.- Returns:
- true if the current request is an Ajax request
-
getFlowExecutionUrl
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.- Parameters:
flowId
- the flow definition idflowExecutionKey
- the flow execution key- Returns:
- the flow execution URL
-
getCurrentUser
Principal getCurrentUser()Provides access to the user's principal security object.- Returns:
- the user principal
-
getLocale
Locale getLocale()Returns the client locale.- Returns:
- the locale
-
getNativeContext
Object getNativeContext()Provides access to the context object for the current environment.- Returns:
- the environment specific context object
-
getNativeRequest
Object getNativeRequest()Provides access to the request object for the current environment.- Returns:
- the environment specific request object.
-
getNativeResponse
Object getNativeResponse()Provides access to the response object for the current environment.- Returns:
- the environment specific response object.
-
getResponseWriter
Get a writer for writing out a response.- Returns:
- the writer
- Throws:
IllegalStateException
- if the response has completed or is not allowed
-
isResponseAllowed
boolean isResponseAllowed()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.- Returns:
- true if yes, false otherwise
-
requestFlowExecutionRedirect
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.- Throws:
IllegalStateException
- if the response has completed- See Also:
-
requestFlowDefinitionRedirect
void requestFlowDefinitionRedirect(String flowId, MutableAttributeMap<?> input) throws IllegalStateException 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.- Parameters:
flowId
- the id of the flow definition to redirect toinput
- input to pass the flow; this input is generally encoded the url to launch the flow- Throws:
IllegalStateException
- if the response has completed- See Also:
-
requestExternalRedirect
Request a redirect to an arbitrary resource location. May not be supported in some environments. Calling this method also sets responseComplete status to true.- Parameters:
location
- the location of the resource to redirect to- Throws:
IllegalStateException
- if the response has completed- See Also:
-
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. Only call this method after a redirect has been requested.- Throws:
IllegalStateException
- if a redirect has not been requested- See Also:
-
recordResponseComplete
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. 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. -
isResponseComplete
boolean isResponseComplete()Has the response been completed? Response complete status can be achieved by:- Writing out the response and calling
recordResponseComplete()
, or - Calling one of the redirect request methods
- Returns:
- true if yes, false otherwise
- See Also:
- Writing out the response and calling
-
isResponseCompleteFlowExecutionRedirect
boolean isResponseCompleteFlowExecutionRedirect()Returns true if the response has been completed with flow execution redirect request.- Returns:
- true if a redirect response has been completed
- See Also:
-