org.apache.wicket.protocol.http
Class WicketFilter

java.lang.Object
  extended by org.apache.wicket.protocol.http.WicketFilter
All Implemented Interfaces:
javax.servlet.Filter
Direct Known Subclasses:
ReloadingWicketFilter

public class WicketFilter
extends java.lang.Object
implements javax.servlet.Filter

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:
for documentation

Field Summary
static java.lang.String APP_FACT_PARAM
          The name of the context parameter that specifies application factory class
static java.lang.String FILTER_MAPPING_PARAM
          The name of the root path parameter that specifies the root dir of the app.
static java.lang.String IGNORE_PATHS_PARAM
          Name of parameter used to express a comma separated list of paths that should be ignored
 
Constructor Summary
WicketFilter()
           
 
Method Summary
protected  java.lang.String checkIfRedirectRequired(java.lang.String requestURI, java.lang.String contextPath)
          Try to determine as fast as possible if a redirect is necessary
 void destroy()
           
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
           
protected  IWebApplicationFactory getApplicationFactory()
          Creates the web application factory instance.
protected  java.lang.ClassLoader getClassLoader()
           
 javax.servlet.FilterConfig getFilterConfig()
           
protected  java.lang.String getFilterPath(javax.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  java.lang.String getFilterPathFromAnnotation(boolean isServlet)
          Stub method that lets subclasses configure filter path from annotations.
protected  java.lang.String getFilterPathFromConfig(javax.servlet.FilterConfig filterConfig)
           
protected  java.lang.String getFilterPathFromWebXml(boolean isServlet, javax.servlet.FilterConfig filterConfig)
           
 java.lang.String getRelativePath(javax.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, javax.servlet.FilterConfig filterConfig)
          Servlets and Filters are treated essentially the same with Wicket.
 void init(javax.servlet.FilterConfig filterConfig)
          If you do have a need to subclass, you may subclass init(boolean, FilterConfig)
 void setFilterPath(java.lang.String filterPath)
          Sets the filter path instead of reading it from web.xml.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILTER_MAPPING_PARAM

public static final java.lang.String FILTER_MAPPING_PARAM
The name of the root path parameter that specifies the root dir of the app.

See Also:
Constant Field Values

APP_FACT_PARAM

public static final java.lang.String APP_FACT_PARAM
The name of the context parameter that specifies application factory class

See Also:
Constant Field Values

IGNORE_PATHS_PARAM

public static final java.lang.String IGNORE_PATHS_PARAM
Name of parameter used to express a comma separated list of paths that should be ignored

See Also:
Constant Field Values
Constructor Detail

WicketFilter

public WicketFilter()
Method Detail

getClassLoader

protected java.lang.ClassLoader getClassLoader()
Returns:
The class loader

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:
doFilter in interface javax.servlet.Filter
Throws:
java.io.IOException
javax.servlet.ServletException
See Also:
Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)

getApplicationFactory

protected IWebApplicationFactory 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:
ContextParamWebApplicationFactory

init

public final void init(javax.servlet.FilterConfig filterConfig)
                throws javax.servlet.ServletException
If you do have a need to subclass, you may subclass init(boolean, FilterConfig)

Specified by:
init in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException
See Also:
Filter.init(javax.servlet.FilterConfig)

init

public void init(boolean isServlet,
                 javax.servlet.FilterConfig filterConfig)
          throws javax.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 Filter
filterConfig -
Throws:
javax.servlet.ServletException
See Also:
init(FilterConfig)

getFilterPathFromAnnotation

protected java.lang.String getFilterPathFromAnnotation(boolean isServlet)
Stub method that lets subclasses configure filter path from annotations.

Parameters:
isServlet -
Returns:
Filter path from annotation

getFilterPathFromWebXml

protected java.lang.String getFilterPathFromWebXml(boolean isServlet,
                                                   javax.servlet.FilterConfig filterConfig)
Parameters:
isServlet -
filterConfig -
Returns:
filter path from web.xml

getFilterConfig

public javax.servlet.FilterConfig getFilterConfig()
Returns:
filter config

getFilterPath

protected java.lang.String getFilterPath(javax.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.

Parameters:
request -
Returns:
filterPath

getFilterPathFromConfig

protected java.lang.String getFilterPathFromConfig(javax.servlet.FilterConfig filterConfig)
Parameters:
filterConfig -
Returns:
filter path

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Filter
See Also:
Filter.destroy()

checkIfRedirectRequired

protected final java.lang.String checkIfRedirectRequired(java.lang.String requestURI,
                                                         java.lang.String contextPath)
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

public final void setFilterPath(java.lang.String filterPath)
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

public java.lang.String getRelativePath(javax.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.

Parameters:
request -
Returns:
Path requested, minus query string, context path, and filterPath. Relative, no leading '/'.


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