com.opensymphony.webwork.dispatcher
Class FilterDispatcher
java.lang.Object
com.opensymphony.webwork.dispatcher.FilterDispatcher
- All Implemented Interfaces:
- WebWorkStatics, Filter
- Direct Known Subclasses:
- FilterDispatcherCompatWeblogic61, PicoFilterDispatcher
public class FilterDispatcher
- extends Object
- implements Filter, WebWorkStatics
Master filter for WebWork that handles four distinct responsibilities:
- Executing actions
- Cleaning up the
ActionContext
(see note)
- Serving static content
- Kicking off XWork's IoC for the request lifecycle
IMPORTANT: this filter must be mapped to all requests. Unless you know exactly what you are doing, always
map to this URL pattern: /*
Executing actions
This filter executes actions by consulting the ActionMapper
and determining if the requested URL should
invoke an action. If the mapper indicates it should, the rest of the filter chain is stopped and the action is
invoked. This is important, as it means that filters like the SiteMesh filter must be placed before this
filter or they will not be able to decorate the output of actions.
Cleaning up the ActionContext
This filter will also automatically clean up the ActionContext
for you, ensuring that no memory leaks
take place. However, this can sometimes cause problems integrating with other products like SiteMesh. See ActionContextCleanUp
for more information on how to deal with this.
Serving static content
This filter also serves common static content needed when using various parts of WebWork, such as JavaScript
files, CSS files, etc. It works by looking for requests to /webwork/*, and then mapping the value after "/webwork/"
to common packages in WebWork and, optionally, in your class path. By default, the following packages are
automatically searched:
- com.opensymphony.webwork.static
- template
This means that you can simply request /webwork/xhtml/styles.css and the XHTML UI theme's default stylesheet
will be returned. Likewise, many of the AJAX UI components require various JavaScript files, which are found in the
com.opensymphony.webwork.static package. If you wish to add additional packages to be searched, you can add a comma
separated (space, tab and new line will do as well) list in the filter init parameter named "packages". Be
careful, however, to expose any packages that may have sensitive information, such as properties file with
database access credentials.
Kicking off XWork's IoC for the request lifecycle
This filter also kicks off the XWork IoC request scope, provided that you are using XWork's IoC. All you have to
do to get started with XWork's IoC is add a components.xml file to WEB-INF/classes and properly set up the LifecycleListener
in web.xml. See the IoC docs for more information.
- Since:
- 2.2
- Author:
- Patrick Lightbody, tm_jee
- See Also:
LifecycleListener
,
ActionMapper
,
ActionContextCleanUp
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
filterConfig
protected FilterConfig filterConfig
pathPrefixes
protected String[] pathPrefixes
FilterDispatcher
public FilterDispatcher()
getFilterConfig
public FilterConfig getFilterConfig()
destroy
public void destroy()
- Specified by:
destroy
in interface Filter
init
public void init(FilterConfig filterConfig)
throws ServletException
- Specified by:
init
in interface Filter
- Throws:
ServletException
parse
protected String[] parse(String packages)
doFilter
public void doFilter(ServletRequest req,
ServletResponse res,
FilterChain chain)
throws IOException,
ServletException
- Specified by:
doFilter
in interface Filter
- Throws:
IOException
ServletException
afterActionInvocation
protected void afterActionInvocation(HttpServletRequest request,
Object o,
Object o1)
beforeActionInvocation
protected Object beforeActionInvocation(HttpServletRequest request,
ServletContext servletContext)
setupContainer
protected void setupContainer(HttpServletRequest request)
getServletContext
protected ServletContext getServletContext(HttpSession session)
- Servlet 2.3 specifies that the servlet context can be retrieved from the session. Unfortunately, some versions of
WebLogic can only retrieve the servlet context from the filter config. Hence, this method enables subclasses to
retrieve the servlet context from other sources.
- Parameters:
session
- the HTTP session where, in Servlet 2.3, the servlet context can be retrieved
- Returns:
- the servlet context.
findStaticResource
protected void findStaticResource(String name,
HttpServletResponse response)
throws IOException
- Throws:
IOException
copy
protected void copy(InputStream input,
OutputStream output)
throws IOException
- Throws:
IOException
findInputStream
protected InputStream findInputStream(String name,
String packagePrefix)
throws IOException
- Throws:
IOException
checkUrl
protected boolean checkUrl(URL url,
String rawResourcePath)
- handle .. chars here and other URL hacks
createComponentManager
protected DefaultComponentManager createComponentManager()
- Returns a new DefaultComponentManager instance. This method is useful for developers wishing to subclass
this class and provide a different implementation of DefaultComponentManager.
- Returns:
- a new DefaultComponentManager instance.