org.apache.struts2.dispatcher
Class Dispatcher

java.lang.Object
  extended by org.apache.struts2.dispatcher.Dispatcher

public class Dispatcher
extends java.lang.Object

A utility class the actual dispatcher delegates most of its tasks to. Each instance of the primary dispatcher holds an instance of this dispatcher to be shared for all requests.

See Also:
FilterDispatcher, Jsr168Dispatcher

Nested Class Summary
 class Dispatcher.Locator
          Simple accessor for a static method
 
Constructor Summary
Dispatcher(javax.servlet.ServletContext servletContext)
          The constructor with its servlet context instance (optional)
 
Method Summary
static void addDispatcherListener(DispatcherListener l)
          Adds a dispatcher lifecycle listener
 void cleanup()
          Cleans up thread local variables
 java.util.Map<java.lang.String,java.lang.Object> createContextMap(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ActionMapping mapping, javax.servlet.ServletContext context)
          Creates a context map containing all the wrapped request objects
 java.util.HashMap<java.lang.String,java.lang.Object> createContextMap(java.util.Map requestMap, java.util.Map parameterMap, java.util.Map sessionMap, java.util.Map applicationMap, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext servletContext)
          Merges all application and servlet attributes into a single HashMap to represent the entire Action context.
 com.opensymphony.xwork2.config.ConfigurationManager getConfigurationManager()
          Gets the current configuration manager instance
static Dispatcher getInstance()
          Gets the current instance for this thread
 boolean isPortletSupportActive()
          Returns true, if portlet support is active, false otherwise.
 void prepare(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Prepares a request, including setting the encoding and locale
static void removeDispatcherListener(DispatcherListener l)
          Removes a dispatcher lifecycle listener
 void sendError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext ctx, int code, java.lang.Exception e)
          Sends an HTTP error response code.
 void serviceAction(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext context, ActionMapping mapping)
          Loads the action and executes it.
 void setConfigurationManager(com.opensymphony.xwork2.config.ConfigurationManager mgr)
          Sets the current configuration manager instance
static void setInstance(Dispatcher instance)
          Sets the dispatcher instance for this thread
static void setPortletSupportActive(boolean portletSupportActive)
          Set the flag that portlet support is active or not.
 javax.servlet.http.HttpServletRequest wrapRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext servletContext)
          Wraps and returns the given response or returns the original response object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Dispatcher

public Dispatcher(javax.servlet.ServletContext servletContext)
The constructor with its servlet context instance (optional)

Parameters:
servletContext - The servlet context
Method Detail

getInstance

public static Dispatcher getInstance()
Gets the current instance for this thread

Returns:
The dispatcher instance

setInstance

public static void setInstance(Dispatcher instance)
Sets the dispatcher instance for this thread

Parameters:
instance - The instance

addDispatcherListener

public static void addDispatcherListener(DispatcherListener l)
Adds a dispatcher lifecycle listener

Parameters:
l - The listener

removeDispatcherListener

public static void removeDispatcherListener(DispatcherListener l)
Removes a dispatcher lifecycle listener

Parameters:
l - The listener

cleanup

public void cleanup()
Cleans up thread local variables


serviceAction

public void serviceAction(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response,
                          javax.servlet.ServletContext context,
                          ActionMapping mapping)
                   throws javax.servlet.ServletException
Loads the action and executes it. This method first creates the action context from the given parameters then loads an ActionProxy from the given action name and namespace. After that, the action is executed and output channels throught the response object. Actions not found are sent back to the user via the sendError(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.ServletContext, 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:
javax.servlet.ServletException - when an unknown error occurs (not a 404, but typically something that would end up as a 5xx by the servlet container)

createContextMap

public java.util.Map<java.lang.String,java.lang.Object> createContextMap(javax.servlet.http.HttpServletRequest request,
                                                                         javax.servlet.http.HttpServletResponse response,
                                                                         ActionMapping mapping,
                                                                         javax.servlet.ServletContext context)
Creates a context map containing all the wrapped request objects

Parameters:
request - The servlet request
response - The servlet response
mapping - The action mapping
context - The servlet context
Returns:
A map of context objects

createContextMap

public java.util.HashMap<java.lang.String,java.lang.Object> createContextMap(java.util.Map requestMap,
                                                                             java.util.Map parameterMap,
                                                                             java.util.Map sessionMap,
                                                                             java.util.Map applicationMap,
                                                                             javax.servlet.http.HttpServletRequest request,
                                                                             javax.servlet.http.HttpServletResponse response,
                                                                             javax.servlet.ServletContext servletContext)
Merges all application and servlet attributes into a single HashMap to represent the entire Action context.

Parameters:
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.
servletContext - the ServletContext object.
Returns:
a HashMap representing the Action context.

prepare

public void prepare(javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response)
Prepares a request, including setting the encoding and locale

Parameters:
request - The request
response - The response

wrapRequest

public javax.servlet.http.HttpServletRequest wrapRequest(javax.servlet.http.HttpServletRequest request,
                                                         javax.servlet.ServletContext servletContext)
                                                  throws java.io.IOException
Wraps and returns the given response or returns the original response object. This is used to transparently handle 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 - you should look to that first before overriding this method to handle multipart data.

Parameters:
request - the HttpServletRequest object.
Returns:
a wrapped request or original request.
Throws:
java.io.IOException
See Also:
MultiPartRequestWrapper

sendError

public void sendError(javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response,
                      javax.servlet.ServletContext ctx,
                      int code,
                      java.lang.Exception e)
Sends an HTTP error response code.

Parameters:
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.

isPortletSupportActive

public boolean isPortletSupportActive()
Returns true, if portlet support is active, false otherwise.

Returns:
true, if portlet support is active, false otherwise.

setPortletSupportActive

public static void setPortletSupportActive(boolean portletSupportActive)
Set the flag that portlet support is active or not.

Parameters:
portletSupportActive - true or false

getConfigurationManager

public com.opensymphony.xwork2.config.ConfigurationManager getConfigurationManager()
Gets the current configuration manager instance

Returns:
The instance

setConfigurationManager

public void setConfigurationManager(com.opensymphony.xwork2.config.ConfigurationManager mgr)
Sets the current configuration manager instance

Parameters:
mgr - The configuration manager


Copyright © 2000-2006 Apache Software Foundation. All Rights Reserved.