|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.struts2.dispatcher.FilterDispatcher
public class FilterDispatcher
Master filter for Struts that handles four distinct responsibilities:
ActionContext
(see note)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 Struts, such as JavaScript
files, CSS files, etc. It works by looking for requests to /struts/*, and then mapping the value after "/struts/"
to common packages in Struts and, optionally, in your class path. By default, the following packages are
automatically searched:
This filter supports the following init-params:
ConfigurationProvider
interface that should be used for building the Configuration
.Dispatcher
, the createDispatcher()
method could be overriden by
the subclass.
ActionMapper
,
ActionContextCleanUp
Field Summary | |
---|---|
private static ActionMapper |
actionMapper
Provide ActionMapper instance, set by injection. |
protected Dispatcher |
dispatcher
Expose Dispatcher instance to subclass. |
private static String |
encoding
Store state of StrutsConstants.STRUTS_I18N_ENCODING setting. |
private FilterConfig |
filterConfig
Provide FilterConfig instance, set on init. |
private Calendar |
lastModifiedCal
Provide a formatted date for setting heading information when caching static content. |
private static Log |
LOG
Provide a logging instance. |
private String[] |
pathPrefixes
Store set of path prefixes to use with static resources. |
private static boolean |
serveStatic
Store state of StrutsConstants.STRUTS_SERVE_STATIC_CONTENT setting. |
private static boolean |
serveStaticBrowserCache
Store state of StrutsConstants.STRUTS_SERVE_STATIC_BROWSER_CACHE setting. |
Fields inherited from interface org.apache.struts2.StrutsStatics |
---|
HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_PORTLET_CONTEXT |
Constructor Summary | |
---|---|
FilterDispatcher()
|
Method Summary | |
---|---|
protected void |
copy(InputStream input,
OutputStream output)
Copy bytes from the input stream to the output stream. |
protected Dispatcher |
createDispatcher(FilterConfig filterConfig)
Create a default Dispatcher that subclasses can override
with a custom Dispatcher, if needed. |
void |
destroy()
Calls dispatcher.cleanup, which in turn releases local threads and destroys any DispatchListeners. |
void |
doFilter(ServletRequest req,
ServletResponse res,
FilterChain chain)
Process an action or handle a request a static resource. |
protected InputStream |
findInputStream(String name,
String packagePrefix)
Look for a static resource in the classpath. |
protected void |
findStaticResource(String name,
HttpServletRequest request,
HttpServletResponse response)
Locate a static resource and copy directly to the response, setting the appropriate caching headers. |
protected String |
getContentType(String name)
Determine the content type for the resource name. |
protected FilterConfig |
getFilterConfig()
Expose the FilterConfig instance. |
protected ServletContext |
getServletContext()
Provide a workaround for some versions of WebLogic. |
void |
init(FilterConfig filterConfig)
Initializes the filter by creating a default dispatcher and setting the default packages for static resources. |
protected String[] |
parse(String packages)
Create a string array from a comma-delimited list of packages. |
protected HttpServletRequest |
prepareDispatcherAndWrapRequest(HttpServletRequest request,
HttpServletResponse response)
Wrap and return the given request, if needed, so as to to transparently handle multipart data as a wrapped class around the given request. |
static void |
setActionMapper(ActionMapper mapper)
Modify ActionMapper instance. |
static void |
setEncoding(String val)
Modify state of StrutsConstants.STRUTS_I18N_ENCODING setting. |
static void |
setServeStaticBrowserCache(String val)
Modify state of StrutsConstants.STRUTS_SERVE_STATIC_BROWSER_CACHE setting. |
static void |
setServeStaticContent(String val)
Modify state of StrutsConstants.STRUTS_SERVE_STATIC_CONTENT setting. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final Log LOG
private String[] pathPrefixes
private final Calendar lastModifiedCal
private static boolean serveStatic
private static boolean serveStaticBrowserCache
private static String encoding
private static ActionMapper actionMapper
private FilterConfig filterConfig
protected Dispatcher dispatcher
Constructor Detail |
---|
public FilterDispatcher()
Method Detail |
---|
public void init(FilterConfig filterConfig) throws ServletException
init
in interface Filter
filterConfig
- The filter configuration
ServletException
public void destroy()
destroy
in interface Filter
Filter.destroy()
protected Dispatcher createDispatcher(FilterConfig filterConfig)
Dispatcher
that subclasses can override
with a custom Dispatcher, if needed.
filterConfig
- Our FilterConfig
public static void setServeStaticContent(String val)
val
- New settingpublic static void setServeStaticBrowserCache(String val)
val
- New settingpublic static void setEncoding(String val)
val
- New settingpublic static void setActionMapper(ActionMapper mapper)
mapper
- New instanceprotected ServletContext getServletContext()
protected FilterConfig getFilterConfig()
protected HttpServletRequest prepareDispatcherAndWrapRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException
request
- Our ServletRequest objectresponse
- Our ServerResponse object
ServletException
- on any errorprotected String[] parse(String packages)
packages
- A comma-delimited String listing packages
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException
doFilter
in interface Filter
IOException
ServletException
Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
protected void findStaticResource(String name, HttpServletRequest request, HttpServletResponse response) throws IOException
name
- The resource namerequest
- The requestresponse
- The response
IOException
- If anything goes wrongprotected String getContentType(String name)
name
- The resource name
protected void copy(InputStream input, OutputStream output) throws IOException
input
- The input streamoutput
- The output stream
IOException
- If anything goes wrongprotected InputStream findInputStream(String name, String packagePrefix) throws IOException
name
- The resource namepackagePrefix
- The package prefix to use to locate the resource
IOException
- If there is a problem locating the resource
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |