Class Dispatcher
- Direct Known Subclasses:
- MockDispatcher
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classProvide an accessor class for static XWork utility.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected ConfigurationManagerStore ConfigurationManager instance, set on init.static final Stringstatic final StringHttpServletRequest.getMethod()protected jakarta.servlet.ServletContextKeeps current reference to external world and must be protected to support class inheritance
- 
Constructor SummaryConstructorsConstructorDescriptionDispatcher(jakarta.servlet.ServletContext servletContext, Map<String, String> initParams) Create the Dispatcher instance for a given ServletContext and set of initialization parameters.
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidaddDispatcherListener(DispatcherListener listener) Add a dispatcher lifecycle listener.voidcleanup()Releases all instances bound to this dispatcher instance.voidCleanup any resources used to initialise DispatchervoidcleanUpRequest(jakarta.servlet.http.HttpServletRequest request) Removes all the files created by MultiPartRequestWrapper.static voidRemoves the dispatcher instance for this thread.protected ActionProxyprotected ConfigurationManagercreateContextMap(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, ActionMapping mapping) Create a context map containing all the wrapped request objectscreateContextMap(Map<String, Object> requestMap, HttpParameters parameters, Map<String, Object> sessionMap, Map<String, Object> applicationMap, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Merge all application and servlet attributes into a single HashMap to represent the entire Action context.protected StrutsJavaConfigurationProviderprotected XmlConfigurationProvidercreateStrutsXmlConfigurationProvider(String filename, jakarta.servlet.ServletContext ctx) Expose the ConfigurationManager instance.Exposes a thread-cached reference of the dependency injection container.static DispatcherProvide the dispatcher instance for the current thread.static DispatchergetInstance(jakarta.servlet.ServletContext servletContext) protected LocalegetLocale(jakarta.servlet.http.HttpServletRequest request) protected MultiPartRequestOn each request it must return a new instance as implementation could be not thread safe and thus ensure of resource clean upprotected StringReturn the path to save uploaded files to (this is configurable).voidinit()Load configurations, including both XML and zero-configuration strategies, and update optional settings, including whether to reload configurations and resource files.booleanbooleanprotected booleanisMultipartRequest(jakarta.servlet.http.HttpServletRequest request) Checks if request is a multipart request (a file upload request)protected booleanisMultipartSupportEnabled(jakarta.servlet.http.HttpServletRequest request) Checks if support to parse multipart requests is enabledprotected booleanisSameAction(ActionProxy actionProxy, String namespace, String actionName, String method) protected voidlogConfigurationException(jakarta.servlet.http.HttpServletRequest request, ConfigurationException e) Performs logging of missing action/result configuration exceptionvoidprepare(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Prepare a request, including setting the encoding and locale.protected ActionProxyprepareActionProxy(Map<String, Object> extraContext, String actionNamespace, String actionName, String actionMethod) static voidremoveDispatcherListener(DispatcherListener listener) Remove a specific dispatcher lifecycle listener.voidsendError(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, int code, Exception e) Send an HTTP error response code.voidserviceAction(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, ActionMapping mapping) Load Action class for mapping and invoke the appropriate Action method, or go directly to the Result.voidsetActionExcludedPatterns(String excludedPatterns) voidsetActionExcludedPatternsSeparator(String separator) voidsetActionMapper(ActionMapper actionMapper) voidsetActionProxyFactory(ActionProxyFactory actionProxyFactory) voidsetDefaultEncoding(String val) Modify state of StrutsConstants.STRUTS_I18N_ENCODING setting.voidsetDefaultLocale(String val) Modify state of StrutsConstants.STRUTS_LOCALE setting.voidsetDevMode(String mode) Modify state of StrutsConstants.STRUTS_DEVMODE setting.voidsetDisableRequestAttributeValueStackLookup(String disableRequestAttributeValueStackLookup) Modify state of StrutsConstants.DISABLE_REQUEST_ATTRIBUTE_VALUE_STACK_LOOKUP setting.voidsetDispatcherErrorHandler(DispatcherErrorHandler errorHandler) voidsetDispatchersParametersWorkaround(String dispatchersParametersWorkaround) voidsetHandleException(String handleException) static voidsetInstance(Dispatcher instance) Store the dispatcher instance for this thread.voidsetLocaleProviderFactory(LocaleProviderFactory localeProviderFactory) voidModify state of StrutsConstants.STRUTS_MULTIPART_SAVEDIR setting.voidsetMultipartSupportEnabled(String multipartSupportEnabled) voidsetMultipartValidationRegex(String multipartValidationRegex) voidsetObjectFactory(ObjectFactory objectFactory) voidsetStaticContentLoader(StaticContentLoader staticContentLoader) voidsetThreadAllowlist(ThreadAllowlist threadAllowlist) voidsetValueStackFactory(ValueStackFactory valueStackFactory) jakarta.servlet.http.HttpServletRequestwrapRequest(jakarta.servlet.http.HttpServletRequest request) Wrap and return the given request or return the original request object.
- 
Field Details- 
REQUEST_POST_METHODHttpServletRequest.getMethod()- See Also:
 
- 
MULTIPART_FORM_DATA_REGEX- See Also:
 
- 
configurationManagerStore ConfigurationManager instance, set on init.
- 
servletContextprotected jakarta.servlet.ServletContext servletContextKeeps current reference to external world and must be protected to support class inheritance
- 
initParams
 
- 
- 
Constructor Details- 
DispatcherCreate the Dispatcher instance for a given ServletContext and set of initialization parameters.- Parameters:
- servletContext- Our servlet context
- initParams- The set of initialization parameters
 
 
- 
- 
Method Details- 
getInstanceProvide the dispatcher instance for the current thread.- Returns:
- The dispatcher instance
 
- 
setInstanceStore the dispatcher instance for this thread.- Parameters:
- instance- The instance
 
- 
clearInstancepublic static void clearInstance()Removes the dispatcher instance for this thread.
- 
addDispatcherListenerAdd a dispatcher lifecycle listener.- Parameters:
- listener- The listener to add
 
- 
removeDispatcherListenerRemove a specific dispatcher lifecycle listener.- Parameters:
- listener- The listener
 
- 
getInstance
- 
setDevModeModify state of StrutsConstants.STRUTS_DEVMODE setting.- Parameters:
- mode- New setting
 
- 
isDevModepublic boolean isDevMode()
- 
setDisableRequestAttributeValueStackLookuppublic void setDisableRequestAttributeValueStackLookup(String disableRequestAttributeValueStackLookup) Modify state of StrutsConstants.DISABLE_REQUEST_ATTRIBUTE_VALUE_STACK_LOOKUP setting.- Parameters:
- disableRequestAttributeValueStackLookup- New setting
 
- 
setDefaultLocaleModify state of StrutsConstants.STRUTS_LOCALE setting.- Parameters:
- val- New setting
 
- 
setDefaultEncodingModify state of StrutsConstants.STRUTS_I18N_ENCODING setting.- Parameters:
- val- New setting
 
- 
setMultipartSaveDirModify state of StrutsConstants.STRUTS_MULTIPART_SAVEDIR setting.- Parameters:
- val- New setting
 
- 
setMultipartSupportEnabled
- 
setMultipartValidationRegex
- 
setActionExcludedPatternsSeparator
- 
setActionExcludedPatterns
- 
getActionExcludedPatterns
- 
setValueStackFactory
- 
getValueStackFactory
- 
setHandleException
- 
setDispatchersParametersWorkaround
- 
isHandleExceptionpublic boolean isHandleException()
- 
setDispatcherErrorHandler
- 
setObjectFactory
- 
setActionProxyFactory
- 
getActionProxyFactory
- 
setLocaleProviderFactory
- 
setStaticContentLoader
- 
getStaticContentLoader
- 
setActionMapper
- 
getActionMapper
- 
setThreadAllowlist
- 
cleanuppublic void cleanup()Releases all instances bound to this dispatcher instance.
- 
createStrutsXmlConfigurationProviderprotected XmlConfigurationProvider createStrutsXmlConfigurationProvider(String filename, jakarta.servlet.ServletContext ctx) 
- 
createJavaConfigurationProviderprotected StrutsJavaConfigurationProvider createJavaConfigurationProvider(StrutsJavaConfiguration config) 
- 
initpublic void init()Load configurations, including both XML and zero-configuration strategies, and update optional settings, including whether to reload configurations and resource files.
- 
createConfigurationManager
- 
serviceActionpublic void serviceAction(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, ActionMapping mapping) throws jakarta.servlet.ServletException Load Action class for mapping and invoke the appropriate Action method, or go directly to the Result. This method first creates the action context from the given parameters, and then loads an ActionProxy from the given action name and namespace. After that, the Action method is executed and output channels through the response object. Actions not found are sent back to the user via the sendError(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse, int, java.lang.Exception)method, using the 404 return code. All other errors are reported by throwing a ServletException.- Parameters:
- request- the HttpServletRequest object
- response- the HttpServletResponse object
- mapping- the action mapping object
- Throws:
- jakarta.servlet.ServletException- when an unknown error occurs (not a 404, but typically something that would end up as a 5xx by the servlet container)
- Since:
- 2.3.17
 
- 
prepareActionProxy
- 
createActionProxy
- 
isSameActionprotected boolean isSameAction(ActionProxy actionProxy, String namespace, String actionName, String method) 
- 
logConfigurationExceptionprotected void logConfigurationException(jakarta.servlet.http.HttpServletRequest request, ConfigurationException e) Performs logging of missing action/result configuration exception- Parameters:
- request- current- HttpServletRequest
- e-- ConfigurationExceptionthat occurred
 
- 
createContextMappublic Map<String,Object> createContextMap(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, ActionMapping mapping) Create a context map containing all the wrapped request objects- Parameters:
- request- The servlet request
- response- The servlet response
- mapping- The action mapping
- Returns:
- A map of context objects
- Since:
- 2.3.17
 
- 
createContextMappublic Map<String,Object> createContextMap(Map<String, Object> requestMap, HttpParameters parameters, Map<String, Object> sessionMap, Map<String, Object> applicationMap, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Merge all application and servlet attributes into a single HashMap to represent the entire Action context.- Parameters:
- requestMap- a Map of all request attributes.
- parameters- an Object of all request parameters.
- sessionMap- a Map of all session attributes.
- applicationMap- a Map of all servlet context attributes.
- request- the HttpServletRequest object.
- response- the HttpServletResponse object.
- Returns:
- a HashMap representing the Action context.
- Since:
- 2.3.17
 
- 
getLocale
- 
getSaveDirReturn the path to save uploaded files to (this is configurable).- Returns:
- the path to save uploaded files to
 
- 
preparepublic void prepare(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Prepare a request, including setting the encoding and locale.- Parameters:
- request- The request
- response- The response
 
- 
wrapRequestpublic jakarta.servlet.http.HttpServletRequest wrapRequest(jakarta.servlet.http.HttpServletRequest request) throws IOException Wrap and return the given request or return the original request object. This method transparently handles multipart data as a wrapped class around the given request. Override this method to handle multipart requests in a special way or to handle other types of requests. Note, MultiPartRequestWrapperis flexible - look first to that object before overriding this method to handle multipart data.- Parameters:
- request- the HttpServletRequest object.
- Returns:
- a wrapped request or original request.
- Throws:
- IOException- on any error.
- Since:
- 2.3.17
- See Also:
 
- 
isMultipartSupportEnabledprotected boolean isMultipartSupportEnabled(jakarta.servlet.http.HttpServletRequest request) Checks if support to parse multipart requests is enabled- Parameters:
- request- current servlet request
- Returns:
- false if disabled
- Since:
- 2.5.11
 
- 
isMultipartRequestprotected boolean isMultipartRequest(jakarta.servlet.http.HttpServletRequest request) Checks if request is a multipart request (a file upload request)- Parameters:
- request- current servlet request
- Returns:
- true if it is a multipart request
- Since:
- 2.5.11
 
- 
getMultiPartRequestOn each request it must return a new instance as implementation could be not thread safe and thus ensure of resource clean up- Returns:
- a multi part request object
 
- 
cleanUpRequestpublic void cleanUpRequest(jakarta.servlet.http.HttpServletRequest request) Removes all the files created by MultiPartRequestWrapper.- Parameters:
- request- the HttpServletRequest object.
- See Also:
 
- 
sendErrorpublic void sendError(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, int code, Exception e) Send an HTTP error response code.- Parameters:
- request- the HttpServletRequest object.
- response- the HttpServletResponse object.
- code- the HttpServletResponse error code (see- HttpServletResponsefor possible error codes).
- e- the Exception that is reported.
- Since:
- 2.3.17
 
- 
cleanUpAfterInitpublic void cleanUpAfterInit()Cleanup any resources used to initialise Dispatcher
- 
getConfigurationManagerExpose the ConfigurationManager instance.- Returns:
- The instance
 
- 
getContainerExposes a thread-cached reference of the dependency injection container. If the container is found to have changed since the last time it was cached, this Dispatcher instance is re-injected to ensure no stale configuration/dependencies persist.A non-cached reference can be obtained by calling getConfigurationManager().- Returns:
- Our dependency injection container
 
 
-