KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > web > tomcat > security > HttpServletRequestValve


1 /*
2  * JBoss, the OpenSource WebOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.web.tomcat.security;
9
10 import java.io.IOException JavaDoc;
11
12 import javax.servlet.ServletException JavaDoc;
13
14 import org.apache.catalina.connector.Request;
15 import org.apache.catalina.connector.Response;
16 import org.apache.catalina.valves.ValveBase;
17
18 /**
19  * A Tomcat Valve that obtains the client's HttpServletRequest and saves it in a
20  * ThreadLocal variable. It allows the WebCallbackHandler to populate the
21  * HttpServletRequestCallback.
22  *
23  * @author Ricardo Arguello (ricardoarguello@users.sourceforge.net)
24  * @version $Revision: 1.1.2.1 $
25  */

26 public class HttpServletRequestValve extends ValveBase
27 {
28    /** ThreadLocal to save the HttpServletRequest. */
29    public static ThreadLocal JavaDoc httpRequest = new ThreadLocal JavaDoc();
30
31    /**
32     * Default constructor.
33     */

34    public HttpServletRequestValve()
35    {
36    }
37
38    /**
39     * @see org.apache.catalina.Valve#invoke(org.apache.catalina.connector.Request,
40     * org.apache.catalina.connector.Response)
41     */

42    public void invoke(Request request, Response response) throws IOException JavaDoc,
43          ServletException JavaDoc
44    {
45       try
46       {
47          // Set the ThreadLocal
48
httpRequest.set(request.getRequest());
49
50          // Perform the request
51
getNext().invoke(request, response);
52       }
53       finally
54       {
55          // Unset the ThreadLocal
56
httpRequest.set(null);
57       }
58    }
59 }
Popular Tags