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 Object
implements javax.servlet.Filter

Filter for initiating handling of Wicket requests.

For 1.3 and onward, what we do is instead of using a servlet, use a filter.

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

Field Summary
static String APP_FACT_PARAM
          The name of the context parameter that specifies application factory class
static String FILTER_MAPPING_PARAM
          The name of the root path parameter that specifies the root dir of the app.
static String FILTER_PATH_ATTR
           
static 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  void createRequestContext(WebRequest request, WebResponse response)
           
 void destroy()
          Servlet cleanup.
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          As per Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain), is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain.
 boolean doGet(javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse)
          Handles servlet page requests, delegating to the wicket RequestCycle system.
protected  IWebApplicationFactory getApplicationFactory()
          Creates the web application factory instance.
protected  ClassLoader getClassLoader()
           
 javax.servlet.FilterConfig getFilterConfig()
           
protected  String getFilterPath(javax.servlet.http.HttpServletRequest request)
           
protected  long getLastModified(javax.servlet.http.HttpServletRequest servletRequest)
          Gets the last modified time stamp for the given request if the request is for a resource.
 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.
protected  WebApplication getWebApplication()
          Gets webApplication managed by this filter
 void init(javax.servlet.FilterConfig filterConfig)
          As per Filter.init(FilterConfig), is called by the web container to indicate to a filter that it is being placed into service.
protected  boolean isPortletContextAvailable(javax.servlet.FilterConfig config)
          Tries to find if a PortletContext is available.
protected  WicketFilterPortletContext newWicketFilterPortletContext()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APP_FACT_PARAM

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

See Also:
Constant Field Values

FILTER_MAPPING_PARAM

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

See Also:
Constant Field Values

FILTER_PATH_ATTR

public static final String FILTER_PATH_ATTR
See Also:
Constant Field Values

IGNORE_PATHS_PARAM

public static final 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

destroy

public void destroy()
Servlet cleanup.

Specified by:
destroy in interface javax.servlet.Filter

getWebApplication

protected WebApplication getWebApplication()
Gets webApplication managed by this filter

Returns:
webApplication

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws IOException,
                     javax.servlet.ServletException
As per Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain), is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. The FilterChain passed in to this method allows the Filter to pass on the request and response to the next entity in the chain.

Delegates to doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) for actual response rendering.

doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) goes through a series of steps of steps to process a request;

  1. If running in a portlet context, sets up the WicketFilterPortletContext retrieving the portlet specific (PortletServletRequestWrapper and PortletServletResponseWrapper) wrapped request and response objects.
  2. Otherwise retrieves standard HttpServletRequest and HttpServletResponse objects.
  3. Passes on requests down the filter chain if configured as a portlet _only_ filter but not running in a portlet context. USE CASE IS WHAT?
  4. Checks against registered ignore paths, and passes the request on down the chain if a match is found.
  5. Pass the request to underling servlet style doGet(HttpServletRequest, HttpServletResponse) to attempt actually rendering the response Wicket style.
  6. Potentially respond with "not-modified" for resource type requests
  7. Finally pass on the request if we didn't handle it

Specified by:
doFilter in interface javax.servlet.Filter
Throws:
IOException
javax.servlet.ServletException
See Also:
WicketFilterPortletContext, PortletServletRequestWrapper, PortletServletResponseWrapper, Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)

doGet

public boolean doGet(javax.servlet.http.HttpServletRequest servletRequest,
                     javax.servlet.http.HttpServletResponse servletResponse)
              throws javax.servlet.ServletException,
                     IOException
Handles servlet page requests, delegating to the wicket RequestCycle system.
  1. Checks for the an effective home page request and redirects appropriately.
  2. Check for REDIRECT_TO_BUFFER case and redirect to a buffered response if one exists.
  3. Otherwise begins the RequestCycle processing.

Parameters:
servletRequest - Servlet request object
servletResponse - Servlet response object
Returns:
true if the request was handled by wicket, false otherwise
Throws:
javax.servlet.ServletException - Thrown if something goes wrong during request handling
IOException
See Also:
RequestCycle

getFilterConfig

public javax.servlet.FilterConfig getFilterConfig()
Returns:
The filter config of this WicketFilter

getRelativePath

public 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 '/'.

init

public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
As per Filter.init(FilterConfig), is called by the web container to indicate to a filter that it is being placed into service. init(FilterConfig) goes through a series of steps of steps to initialise;
  1. Sets up ignore paths
  2. Records class loaders
  3. Finds the filter's path - filterPath
  4. Sets up the IWebApplicationFactory and WebApplication for this filter, including it's initialisation.
  5. Initialise WebApplication request listeners.
  6. Log start of Application
  7. Detect if running in a Portlet context and if so intialise the WicketFilterPortletContext

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

isPortletContextAvailable

protected boolean isPortletContextAvailable(javax.servlet.FilterConfig config)
                                     throws javax.servlet.ServletException
Tries to find if a PortletContext is available. Searches for the 'detect portlet context' flag in various places and if true, tries to load the PortletContext.

Parameters:
config - the FilterConfig object
Returns:
true if PortletContext was successfully loaded
Throws:
javax.servlet.ServletException - on IO errors

newWicketFilterPortletContext

protected WicketFilterPortletContext newWicketFilterPortletContext()

createRequestContext

protected void createRequestContext(WebRequest request,
                                    WebResponse response)

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

getClassLoader

protected ClassLoader getClassLoader()
Returns:
The class loader

getFilterPath

protected String getFilterPath(javax.servlet.http.HttpServletRequest request)

getLastModified

protected long getLastModified(javax.servlet.http.HttpServletRequest servletRequest)
Gets the last modified time stamp for the given request if the request is for a resource.

Parameters:
servletRequest -
Returns:
The last modified time stamp


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