public class Dispatcher extends Object
InitOperations
Modifier and Type | Class and Description |
---|---|
static class |
Dispatcher.Locator
Provide an accessor class for static XWork utility.
|
Modifier and Type | Field and Description |
---|---|
protected ConfigurationManager |
configurationManager
Store ConfigurationManager instance, set on init.
|
protected Map<String,String> |
initParams |
protected javax.servlet.ServletContext |
servletContext
Keeps current reference to external world and must be protected to support class inheritance
|
Constructor and Description |
---|
Dispatcher(javax.servlet.ServletContext servletContext,
Map<String,String> initParams)
Create the Dispatcher instance for a given ServletContext and set of initialization parameters.
|
Modifier and Type | Method and Description |
---|---|
static void |
addDispatcherListener(DispatcherListener listener)
Add a dispatcher lifecycle listener.
|
void |
cleanup()
Releases all instances bound to this dispatcher instance.
|
void |
cleanUpAfterInit()
Cleanup any resources used to initialise Dispatcher
|
void |
cleanUpRequest(javax.servlet.http.HttpServletRequest request)
Removes all the files created by MultiPartRequestWrapper.
|
protected ConfigurationManager |
createConfigurationManager(String name) |
Map<String,Object> |
createContextMap(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
ActionMapping mapping)
Create a context map containing all the wrapped request objects
|
HashMap<String,Object> |
createContextMap(Map requestMap,
Map parameterMap,
Map sessionMap,
Map applicationMap,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Merge all application and servlet attributes into a single HashMap to represent the entire
Action context.
|
protected XmlConfigurationProvider |
createStrutsXmlConfigurationProvider(String filename,
boolean errorIfMissing,
javax.servlet.ServletContext ctx) |
protected XmlConfigurationProvider |
createXmlConfigurationProvider(String filename,
boolean errorIfMissing) |
ConfigurationManager |
getConfigurationManager()
Expose the ConfigurationManager instance.
|
Container |
getContainer()
Expose the dependency injection container.
|
static Dispatcher |
getInstance()
Provide the dispatcher instance for the current thread.
|
protected MultiPartRequest |
getMultiPartRequest()
On each request it must return a new instance as implementation could be not thread safe
and thus ensure of resource clean up
|
void |
init()
Load configurations, including both XML and zero-configuration strategies,
and update optional settings, including whether to reload configurations and resource files.
|
protected void |
logConfigurationException(javax.servlet.http.HttpServletRequest request,
ConfigurationException e)
Performs logging of missing action/result configuration exception
|
void |
prepare(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Prepare a request, including setting the encoding and locale.
|
static void |
removeDispatcherListener(DispatcherListener listener)
Remove a specific dispatcher lifecycle listener.
|
void |
sendError(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
int code,
Exception e)
Send an HTTP error response code.
|
void |
serviceAction(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
ActionMapping mapping)
Load Action class for mapping and invoke the appropriate Action method, or go directly to the Result.
|
void |
setDefaultEncoding(String val)
Modify state of StrutsConstants.STRUTS_I18N_ENCODING setting.
|
void |
setDefaultLocale(String val)
Modify state of StrutsConstants.STRUTS_LOCALE setting.
|
void |
setDevMode(String mode)
Modify state of StrutsConstants.STRUTS_DEVMODE setting.
|
void |
setDisableRequestAttributeValueStackLookup(String disableRequestAttributeValueStackLookup)
Modify state of StrutsConstants.DISABLE_REQUEST_ATTRIBUTE_VALUE_STACK_LOOKUP setting.
|
void |
setDispatcherErrorHandler(DispatcherErrorHandler errorHandler) |
void |
setHandleException(String handleException) |
static void |
setInstance(Dispatcher instance)
Store the dispatcher instance for this thread.
|
void |
setMultipartHandler(String val) |
void |
setMultipartSaveDir(String val)
Modify state of StrutsConstants.STRUTS_MULTIPART_SAVEDIR setting.
|
void |
setValueStackFactory(ValueStackFactory valueStackFactory) |
javax.servlet.http.HttpServletRequest |
wrapRequest(javax.servlet.http.HttpServletRequest request)
Wrap and return the given request or return the original request object.
|
protected ConfigurationManager configurationManager
protected javax.servlet.ServletContext servletContext
public static Dispatcher getInstance()
public static void setInstance(Dispatcher instance)
instance
- The instancepublic static void addDispatcherListener(DispatcherListener listener)
listener
- The listener to addpublic static void removeDispatcherListener(DispatcherListener listener)
listener
- The listenerpublic void setDevMode(String mode)
mode
- New settingpublic void setDisableRequestAttributeValueStackLookup(String disableRequestAttributeValueStackLookup)
disableRequestAttributeValueStackLookup
- New settingpublic void setDefaultLocale(String val)
val
- New settingpublic void setDefaultEncoding(String val)
val
- New settingpublic void setMultipartSaveDir(String val)
val
- New settingpublic void setMultipartHandler(String val)
public void setValueStackFactory(ValueStackFactory valueStackFactory)
public void setHandleException(String handleException)
public void setDispatcherErrorHandler(DispatcherErrorHandler errorHandler)
public void cleanup()
protected XmlConfigurationProvider createXmlConfigurationProvider(String filename, boolean errorIfMissing)
protected XmlConfigurationProvider createStrutsXmlConfigurationProvider(String filename, boolean errorIfMissing, javax.servlet.ServletContext ctx)
public void init()
protected ConfigurationManager createConfigurationManager(String name)
public void serviceAction(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ActionMapping mapping) throws javax.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(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int, java.lang.Exception)
method,
using the 404 return code.
All other errors are reported by throwing a ServletException.
request
- the HttpServletRequest objectresponse
- the HttpServletResponse objectmapping
- the action mapping objectjavax.servlet.ServletException
- when an unknown error occurs (not a 404, but typically something that
would end up as a 5xx by the servlet container)protected void logConfigurationException(javax.servlet.http.HttpServletRequest request, ConfigurationException e)
request
- current HttpServletRequest
e
- ConfigurationException
that occurredpublic Map<String,Object> createContextMap(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ActionMapping mapping)
request
- The servlet requestresponse
- The servlet responsemapping
- The action mappingpublic HashMap<String,Object> createContextMap(Map requestMap, Map parameterMap, Map sessionMap, Map applicationMap, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
requestMap
- a Map of all request attributes.parameterMap
- a Map 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.public void prepare(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
request
- The requestresponse
- The responsepublic javax.servlet.http.HttpServletRequest wrapRequest(javax.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, MultiPartRequestWrapper
is
flexible - look first to that object before overriding this method to handle multipart data.
request
- the HttpServletRequest object.IOException
- on any error.MultiPartRequestWrapper
protected MultiPartRequest getMultiPartRequest()
public void cleanUpRequest(javax.servlet.http.HttpServletRequest request)
request
- the HttpServletRequest object.MultiPartRequestWrapper
public void sendError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, int code, Exception e)
request
- the HttpServletRequest object.response
- the HttpServletResponse object.code
- the HttpServletResponse error code (see HttpServletResponse
for possible error codes).e
- the Exception that is reported.public void cleanUpAfterInit()
public ConfigurationManager getConfigurationManager()
public Container getContainer()
Copyright © 2000–2016 Apache Software Foundation. All rights reserved.