Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.cayenne.conf
Class WebApplicationContextFilter

    java.lang.Object
      org.apache.cayenne.conf.WebApplicationContextFilter

All Implemented Interfaces:
  javax.servlet.Filter

    public class WebApplicationContextFilter

extends java.lang.Object
implements javax.servlet.Filter

`WebApplicationContextFilter` is another helper class to help integrate Cayenne with web applications. The implementation is similar to `org.apache.cayenne.conf.WebApplicationContextProvider` however it allows for integration with containers that support version 2.3 of the servlet specification for example Tomcat 4.x. via the usage of filers.

Whenever this filter is processed it attempts bind a `DataContext` to the thread. It retrieves the `DataContext` via the `BasicServletConfiguration.getDefaultDataContext()` and binds it to the thread using `DataContext.bindThreadDataContext()` method. If the session has not been created this filter will also create a new session.

During initialization (init() method) this filter initializes the `BasicServletConfiguration` with the servlet context via the initializeConfiguration() method

This filter can be installed in the web container as a "filter" as follows:

              <filter>
                  <filter-name>WebApplicationContextFilter</filter-name>
                  <filter-class>org.apache.cayenne.conf.WebApplicationContextFilter</filter-class>
             </filter>

Then the mapping needs to be created to direct all or some requests to be processed by the filter as follows:

             <filter-mapping>
                  <filter-name>WebApplicationContextFilter</filter-name>
                  <url-pattern>/*</url-pattern>
              </filter-mapping>

The above example the filter would be applied to all the servlets and static content pages in the Web application, because every request URI matches the '/*' URL pattern. The problem with this mapping however is the fact that this filter will run for every request made, whether for images and/or static content and dynamic content request. This maybe detrimental to performance. Hence the mapping url patter should be set accordingly.

Author:
  Gary Jarrel

Constructor Summary
`WebApplicationContextFilter()`

Method Summary
`void` | `destroy()` Does nothing.
`void` | `doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)` Retrieves the `DataContext` bound to the `HttpSession` via `BasicServletConfiguration.`
`void` | `init(javax.servlet.FilterConfig config)` Initializes the `BasicServletConfiguration` via the initializeConfiguration() method.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### WebApplicationContextFilter

    public WebApplicationContextFilter()

Method Detail

### destroy

    public void destroy()

  Does nothing. As per the servlet specification, gets called by the container when the filter is taken out of service.

  Specified by:
    `destroy` in interface `javax.servlet.Filter`

### init

    public void init(javax.servlet.FilterConfig config)
              throws javax.servlet.ServletException

  Initializes the `BasicServletConfiguration` via the initializeConfiguration() method. Also saves the FilterConfing to a private local variable for possible later access. This method is part of the `Filter` interface and is called by the container when the filter is placed into service.

  Specified by:
    `init` in interface `javax.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

  Retrieves the `DataContext` bound to the `HttpSession` via `BasicServletConfiguration. getDefaultContext()`, and binds it to the current thread.

  Specified by:
    `doFilter` in interface `javax.servlet.Filter`
  Throws:
    `java.io.IOException`
    `javax.servlet.ServletException`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2006 Apache.org All Rights Reserved.