public class MockExternalContext extends java.lang.Object implements ExternalContext
ExternalContext
interface.ExternalContext
Constructor and Description |
---|
MockExternalContext()
Creates a mock external context with an empty request parameter map.
|
MockExternalContext(ParameterMap requestParameterMap)
Creates a mock external context with the specified parameters in the request parameter map.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
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.
|
MockParameterMap |
getMockRequestParameterMap()
Returns the request parameter map as a
MockParameterMap for convenient access in a unit test. |
java.io.StringWriter |
getMockResponseWriter()
Returns the implementation of this mock context's response writer.
|
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.
|
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.
|
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 |
isRedirectRequested() |
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 |
putRequestParameter(java.lang.String parameterName,
java.util.List<org.springframework.web.multipart.MultipartFile> parameterValue)
Puts a multi-valued MultipartFile request parameter into the mock parameter map.
|
void |
putRequestParameter(java.lang.String parameterName,
org.springframework.web.multipart.MultipartFile parameterValue)
Puts a MultipartFile request parameter into the mock parameter map.
|
void |
putRequestParameter(java.lang.String parameterName,
java.lang.String parameterValue)
Puts a request parameter into the mock parameter map.
|
void |
putRequestParameter(java.lang.String parameterName,
java.lang.String[] parameterValues)
Puts a multi-valued request parameter into the mock parameter map.
|
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 uri)
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)
Set whether this request is an ajax request.
|
void |
setApplicationMap(SharedAttributeMap<java.lang.Object> applicationMap)
Set the application attribute map.
|
void |
setContextPath(java.lang.String contextPath)
Set the context path of the application.
|
void |
setCurrentUser(java.security.Principal currentUser)
Sets the current user principal.
|
void |
setCurrentUser(java.lang.String currentUser)
Convenience method that sets the current user principal as a string.
|
void |
setEventId(java.lang.String eventId)
Sets the id of the event that should be signaled by this context.
|
void |
setGlobalSessionMap(SharedAttributeMap<java.lang.Object> globalSessionMap)
Set the global session attribute map.
|
void |
setLocale(java.util.Locale locale)
Sets the client locale.
|
void |
setNativeContext(java.lang.Object nativeContext)
Set the native context object.
|
void |
setNativeRequest(java.lang.Object nativeRequest)
Set the native request object.
|
void |
setNativeResponse(java.lang.Object nativeResponse)
Set the native response object.
|
void |
setRequestMap(MutableAttributeMap<java.lang.Object> requestMap)
Set the request attribute map.
|
void |
setRequestParameterMap(ParameterMap requestParameterMap)
Set the request parameter map.
|
void |
setResponseAllowed(boolean responseAllowed)
Set the response allows flag to a value for testing.
|
void |
setSessionMap(SharedAttributeMap<java.lang.Object> sessionMap)
Set the session attribute map.
|
public MockExternalContext()
public MockExternalContext(ParameterMap requestParameterMap)
requestParameterMap
- the request parameterspublic java.lang.String getContextPath()
ExternalContext
getContextPath
in interface ExternalContext
public ParameterMap getRequestParameterMap()
ExternalContext
getRequestParameterMap
in interface ExternalContext
public MutableAttributeMap<java.lang.Object> getRequestMap()
ExternalContext
getRequestMap
in interface ExternalContext
public SharedAttributeMap<java.lang.Object> getSessionMap()
ExternalContext
getSessionMap
in interface ExternalContext
public SharedAttributeMap<java.lang.Object> getGlobalSessionMap()
ExternalContext
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()
.
getGlobalSessionMap
in interface ExternalContext
public SharedAttributeMap<java.lang.Object> getApplicationMap()
ExternalContext
getApplicationMap
in interface ExternalContext
public java.security.Principal getCurrentUser()
ExternalContext
getCurrentUser
in interface ExternalContext
public java.util.Locale getLocale()
ExternalContext
getLocale
in interface ExternalContext
public java.lang.Object getNativeContext()
ExternalContext
getNativeContext
in interface ExternalContext
public java.lang.Object getNativeRequest()
ExternalContext
getNativeRequest
in interface ExternalContext
public java.lang.Object getNativeResponse()
ExternalContext
getNativeResponse
in interface ExternalContext
public boolean isAjaxRequest()
ExternalContext
isAjaxRequest
in interface ExternalContext
public java.lang.String getFlowExecutionUrl(java.lang.String flowId, java.lang.String flowExecutionKey)
ExternalContext
getFlowExecutionUrl
in interface ExternalContext
flowId
- the flow definition idflowExecutionKey
- the flow execution keypublic java.io.Writer getResponseWriter()
ExternalContext
getResponseWriter
in interface ExternalContext
public boolean isResponseAllowed()
ExternalContext
isResponseAllowed
in interface ExternalContext
public boolean isResponseComplete()
ExternalContext
ExternalContext.recordResponseComplete()
, or
isResponseComplete
in interface ExternalContext
ExternalContext.getResponseWriter()
,
ExternalContext.recordResponseComplete()
,
ExternalContext.requestFlowExecutionRedirect()
,
ExternalContext.requestFlowDefinitionRedirect(String, MutableAttributeMap)
,
ExternalContext.requestExternalRedirect(String)
public void recordResponseComplete()
ExternalContext
recordResponseComplete
in interface ExternalContext
public boolean isResponseCompleteFlowExecutionRedirect()
ExternalContext
isResponseCompleteFlowExecutionRedirect
in interface ExternalContext
ExternalContext.isResponseComplete()
,
ExternalContext.requestFlowExecutionRedirect()
public void requestFlowExecutionRedirect() throws java.lang.IllegalStateException
ExternalContext
requestFlowExecutionRedirect
in interface ExternalContext
java.lang.IllegalStateException
- if the response has completedExternalContext.isResponseComplete()
public void requestFlowDefinitionRedirect(java.lang.String flowId, MutableAttributeMap<?> input) throws java.lang.IllegalStateException
ExternalContext
requestFlowDefinitionRedirect
in interface ExternalContext
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 flowjava.lang.IllegalStateException
- if the response has completedExternalContext.isResponseComplete()
public void requestExternalRedirect(java.lang.String uri) throws java.lang.IllegalStateException
ExternalContext
requestExternalRedirect
in interface ExternalContext
uri
- the location of the resource to redirect tojava.lang.IllegalStateException
- if the response has completedExternalContext.isResponseComplete()
public void requestRedirectInPopup() throws java.lang.IllegalStateException
ExternalContext
requestRedirectInPopup
in interface ExternalContext
java.lang.IllegalStateException
- if a redirect has not been requestedExternalContext.requestFlowExecutionRedirect()
,
ExternalContext.requestFlowDefinitionRedirect(String, MutableAttributeMap)
,
ExternalContext.requestExternalRedirect(String)
public void setContextPath(java.lang.String contextPath)
contextPath
- the context pathpublic void setRequestParameterMap(ParameterMap requestParameterMap)
public void setRequestMap(MutableAttributeMap<java.lang.Object> requestMap)
ExternalContext.getRequestMap()
public void setSessionMap(SharedAttributeMap<java.lang.Object> sessionMap)
ExternalContext.getSessionMap()
public void setGlobalSessionMap(SharedAttributeMap<java.lang.Object> globalSessionMap)
public void setApplicationMap(SharedAttributeMap<java.lang.Object> applicationMap)
ExternalContext.getApplicationMap()
public void setNativeContext(java.lang.Object nativeContext)
nativeContext
- the native contextpublic void setNativeRequest(java.lang.Object nativeRequest)
nativeRequest
- the native request objectpublic void setNativeResponse(java.lang.Object nativeResponse)
nativeResponse
- the native response objectpublic void setCurrentUser(java.security.Principal currentUser)
currentUser
- the current userpublic void setCurrentUser(java.lang.String currentUser)
currentUser
- the current user namepublic void setLocale(java.util.Locale locale)
locale
- the localepublic MockParameterMap getMockRequestParameterMap()
MockParameterMap
for convenient access in a unit test.getRequestParameterMap()
public void putRequestParameter(java.lang.String parameterName, java.lang.String parameterValue)
parameterName
- the parameter nameparameterValue
- the parameter valuepublic void putRequestParameter(java.lang.String parameterName, java.lang.String[] parameterValues)
parameterName
- the parameter nameparameterValues
- the parameter valuespublic void putRequestParameter(java.lang.String parameterName, org.springframework.web.multipart.MultipartFile parameterValue)
parameterName
- the parameter nameparameterValue
- the parameter valuepublic void putRequestParameter(java.lang.String parameterName, java.util.List<org.springframework.web.multipart.MultipartFile> parameterValue)
parameterName
- the parameter nameparameterValue
- the parameter valuepublic void setEventId(java.lang.String eventId)
eventId
- the id of the event to signalpublic void setAjaxRequest(boolean ajaxRequest)
ajaxRequest
- true or falsepublic void setResponseAllowed(boolean responseAllowed)
responseAllowed
- true or falsepublic java.io.StringWriter getMockResponseWriter()
public boolean getFlowExecutionRedirectRequested()
public boolean getFlowDefinitionRedirectRequested()
public java.lang.String getFlowRedirectFlowId()
getFlowDefinitionRedirectRequested()
returns true.public MutableAttributeMap<java.lang.Object> getFlowRedirectFlowInput()
getFlowDefinitionRedirectRequested()
returns true.public boolean getExternalRedirectRequested()
public java.lang.String getExternalRedirectUrl()
getExternalRedirectRequested()
returns true.public boolean getRedirectInPopup()
public boolean isRedirectRequested()