Class TryFilesFilter
- java.lang.Object
-
- org.eclipse.jetty.fcgi.server.proxy.TryFilesFilter
-
- All Implemented Interfaces:
javax.servlet.Filter
public class TryFilesFilter extends java.lang.Object implements javax.servlet.FilterInspired by nginx's try_files functionality.This filter accepts the
filesinit-param as a list of space-separated file URIs. The special token$pathrepresents the current request URL's path (the portion after the context path).Typical example of how this filter can be configured is the following:
<filter> <filter-name>try_files</filter-name> <filter-class>org.eclipse.jetty.fcgi.server.proxy.TryFilesFilter</filter-class> <init-param> <param-name>files</param-name> <param-value>maintenance.html $path index.php?p=$path</param-value> </init-param> </filter>For a request such as/context/path/to/resource.ext, this filter will try to serve the/maintenance.htmlfile if it finds it; failing that, it will try to serve the/path/to/resource.extfile if it finds it; failing that it will forward the request toindex.php?p=/path/to/resource.ext. The last file URI specified in the list is therefore the "fallback" to which the request is forwarded to in case no previous files can be found.The files are resolved using
ServletContext.getResource(String)to make sure that only files visible to the application are served.- See Also:
FastCGIProxyServlet
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFILES_INIT_PARAM
-
Constructor Summary
Constructors Constructor Description TryFilesFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)protected voidfallback(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain, java.lang.String fallback)voidinit(javax.servlet.FilterConfig config)
-
-
-
Field Detail
-
FILES_INIT_PARAM
public static final java.lang.String FILES_INIT_PARAM
- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init(javax.servlet.FilterConfig config) throws javax.servlet.ServletException- Specified by:
initin interfacejavax.servlet.Filter- Throws:
javax.servlet.ServletException
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException- Specified by:
doFilterin interfacejavax.servlet.Filter- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
fallback
protected void fallback(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain, java.lang.String fallback) throws java.io.IOException, javax.servlet.ServletException- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
destroy
public void destroy()
- Specified by:
destroyin interfacejavax.servlet.Filter
-
-