KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > filters > PersistenceSessionFilter


1 package org.roller.presentation.filters;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.servlet.Filter JavaDoc;
6 import javax.servlet.FilterChain JavaDoc;
7 import javax.servlet.FilterConfig JavaDoc;
8 import javax.servlet.ServletException JavaDoc;
9 import javax.servlet.ServletRequest JavaDoc;
10 import javax.servlet.ServletResponse JavaDoc;
11 import javax.servlet.http.HttpServletRequest JavaDoc;
12 import javax.servlet.http.HttpServletResponse JavaDoc;
13
14 import org.apache.commons.logging.Log;
15 import org.apache.commons.logging.LogFactory;
16 import org.roller.RollerException;
17 import org.roller.model.Roller;
18 import org.roller.presentation.RollerContext;
19
20 /**
21  * Sole responsibility is to ensure that each request's Roller
22  * persistence session is released at end of the request.
23  * @web.filter name="PersistenceSessionFilter"
24  * @author David M. Johnson
25  */

26 public class PersistenceSessionFilter implements Filter JavaDoc
27 {
28     private static Log mLogger =
29         LogFactory.getFactory().getInstance(RequestFilter.class);
30
31     /**
32      * destroy
33      */

34     public void destroy()
35     {
36     }
37
38     /**
39      * Release Roller persistence session at end of request processing.
40      */

41     public void doFilter(
42         ServletRequest JavaDoc req, ServletResponse JavaDoc res, FilterChain JavaDoc chain)
43         throws IOException JavaDoc, ServletException JavaDoc
44     {
45         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc)req;
46         HttpServletResponse JavaDoc response = (HttpServletResponse JavaDoc)res;
47         if (mLogger.isDebugEnabled())
48         {
49             mLogger.debug("Entered PersistenceSessionFilter");
50         }
51         Roller roller = RollerContext.getRoller((HttpServletRequest JavaDoc)request);
52         try
53         {
54             chain.doFilter(request, response);
55         }
56         finally
57         {
58             roller.release();
59         }
60         if (mLogger.isDebugEnabled())
61         {
62             mLogger.debug("Exiting PersistenceSessionFilter");
63         }
64     }
65
66     /**
67      * init
68      */

69     public void init(FilterConfig JavaDoc filterConfig) throws ServletException JavaDoc
70     {
71     }
72 }
73
74
Popular Tags