|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.cayenne.conf.WebApplicationContextFilter
public class WebApplicationContextFilter
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.
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 |
---|
public WebApplicationContextFilter()
Method Detail |
---|
public void destroy()
destroy
in interface javax.servlet.Filter
public void init(javax.servlet.FilterConfig config) throws javax.servlet.ServletException
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.
init
in interface javax.servlet.Filter
javax.servlet.ServletException
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException
DataContext
bound to the HttpSession
via BasicServletConfiguration.
getDefaultContext()
, and binds it to
the current thread.
doFilter
in interface javax.servlet.Filter
java.io.IOException
javax.servlet.ServletException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |