java.lang.Object
org.apache.wicket.protocol.http.WicketFilter
- All Implemented Interfaces:
jakarta.servlet.Filter
- Direct Known Subclasses:
AbstractUpgradeFilter
,ReloadingWicketFilter
Filter for initiating handling of Wicket requests.
The advantage of a filter is that, unlike a servlet, it can choose not to process the request and let whatever is next in chain try. So when using a Wicket filter and a request comes in for foo.gif the filter can choose not to process it because it knows it is not a wicket-related request. Since the filter didn't process it, it falls on to the application server to try, and then it works."
- Author:
- Jonathan Locke, Timur Mehrvarz, Juergen Donnerstag, Igor Vaynberg (ivaynberg), Al Maw, jcompagner, Matej Knopp
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The name of the context parameter that specifies application factory classstatic final String
The name of the root path parameter that specifies the root dir of the app.static final String
Name of parameter used to express a comma separated list of paths that should be ignored -
Constructor Summary
ConstructorDescriptiondefault constructor, usually invoked through the servlet container by the web.xml configurationWicketFilter
(WebApplication application) constructor supporting programmatic setup of the filter -
Method Summary
Modifier and TypeMethodDescriptionprotected final String
checkIfRedirectRequired
(String requestURI, String contextPath) Try to determine as fast as possible if a redirect is necessaryvoid
destroy()
void
doFilter
(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) protected WebApplication
protected IWebApplicationFactory
Creates the web application factory instance.protected ClassLoader
jakarta.servlet.FilterConfig
Provide a standard getter for filterPath.protected String
getFilterPath
(jakarta.servlet.http.HttpServletRequest request) Either get the filterPath retrieved from web.xml, or if not found the old (1.3) way via a filter mapping param.protected String
getFilterPathFromAnnotation
(boolean isServlet) Stub method that lets subclasses configure filter path from annotations.protected String
getFilterPathFromConfig
(jakarta.servlet.FilterConfig filterConfig) protected String
getFilterPathFromWebXml
(boolean isServlet, jakarta.servlet.FilterConfig filterConfig) getRelativePath
(jakarta.servlet.http.HttpServletRequest request) Returns a relative path to the filter path and context root from an HttpServletRequest - use this to resolve a Wicket request.void
init
(boolean isServlet, jakarta.servlet.FilterConfig filterConfig) Servlets and Filters are treated essentially the same with Wicket.final void
init
(jakarta.servlet.FilterConfig filterConfig) If you do have a need to subclass, you may subclassinit(boolean, FilterConfig)
protected boolean
processRequestCycle
(RequestCycle requestCycle, WebResponse webResponse, jakarta.servlet.http.HttpServletRequest httpServletRequest, jakarta.servlet.http.HttpServletResponse httpServletResponse, jakarta.servlet.FilterChain chain) Process the request cyclefinal void
setFilterPath
(String filterPath) Sets the filter path instead of reading it from web.xml.
-
Field Details
-
FILTER_MAPPING_PARAM
The name of the root path parameter that specifies the root dir of the app.- See Also:
-
APP_FACT_PARAM
The name of the context parameter that specifies application factory class- See Also:
-
IGNORE_PATHS_PARAM
Name of parameter used to express a comma separated list of paths that should be ignored- See Also:
-
-
Constructor Details
-
WicketFilter
public WicketFilter()default constructor, usually invoked through the servlet container by the web.xml configuration -
WicketFilter
constructor supporting programmatic setup of the filter this can be useful for programmatically creating and appending the wicket filter to the servlet context using servlet 3 features.- Parameters:
application
- web application
-
-
Method Details
-
getClassLoader
- Returns:
- The class loader
-
processRequestCycle
protected boolean processRequestCycle(RequestCycle requestCycle, WebResponse webResponse, jakarta.servlet.http.HttpServletRequest httpServletRequest, jakarta.servlet.http.HttpServletResponse httpServletResponse, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException Process the request cycle- Parameters:
requestCycle
-webResponse
-httpServletRequest
-httpServletResponse
-chain
-- Returns:
- false, if the request could not be processed
- Throws:
IOException
jakarta.servlet.ServletException
-
doFilter
public void doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException - Specified by:
doFilter
in interfacejakarta.servlet.Filter
- Throws:
IOException
jakarta.servlet.ServletException
- See Also:
-
Filter.doFilter(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse, jakarta.servlet.FilterChain)
-
getApplicationFactory
Creates the web application factory instance. If no APP_FACT_PARAM is specified in web.xml ContextParamWebApplicationFactory will be used by default.- Returns:
- application factory instance
- See Also:
-
init
public final void init(jakarta.servlet.FilterConfig filterConfig) throws jakarta.servlet.ServletException If you do have a need to subclass, you may subclassinit(boolean, FilterConfig)
- Specified by:
init
in interfacejakarta.servlet.Filter
- Throws:
jakarta.servlet.ServletException
- See Also:
-
Filter.init(jakarta.servlet.FilterConfig)
-
init
public void init(boolean isServlet, jakarta.servlet.FilterConfig filterConfig) throws jakarta.servlet.ServletException Servlets and Filters are treated essentially the same with Wicket. This is the entry point for both of them.- Parameters:
isServlet
- True if Servlet, false if FilterfilterConfig
-- Throws:
jakarta.servlet.ServletException
- See Also:
-
getFilterPathFromAnnotation
Stub method that lets subclasses configure filter path from annotations.- Parameters:
isServlet
-- Returns:
- Filter path from annotation
-
getFilterPathFromWebXml
protected String getFilterPathFromWebXml(boolean isServlet, jakarta.servlet.FilterConfig filterConfig) - Parameters:
isServlet
-filterConfig
-- Returns:
- filter path from web.xml
-
getFilterConfig
- Returns:
- filter config
-
getFilterPath
Either get the filterPath retrieved from web.xml, or if not found the old (1.3) way via a filter mapping param.- Parameters:
request
-- Returns:
- filterPath
-
getFilterPath
Provide a standard getter for filterPath.- Returns:
- The configured filterPath.
-
getFilterPathFromConfig
- Parameters:
filterConfig
-- Returns:
- filter path
-
destroy
- Specified by:
destroy
in interfacejakarta.servlet.Filter
- See Also:
-
Filter.destroy()
-
checkIfRedirectRequired
Try to determine as fast as possible if a redirect is necessary- Parameters:
requestURI
-contextPath
-- Returns:
- null, if no redirect is necessary. Else the redirect URL
-
setFilterPath
Sets the filter path instead of reading it from web.xml. Please note that you must subclass WicketFilter.init(FilterConfig) and set your filter path before you call super.init(filterConfig).- Parameters:
filterPath
-
-
getRelativePath
Returns a relative path to the filter path and context root from an HttpServletRequest - use this to resolve a Wicket request.- Parameters:
request
-- Returns:
- Path requested, minus query string, context path, and filterPath. Relative, no leading '/'.
-
getApplication
-