KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > util > HttpRequestManager


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.util;
8
9
10 import javax.servlet.http.HttpServletRequest JavaDoc;
11
12
13 /**
14  * <p>
15  * This class is a singleton used to store HttpServletRequest
16  * objects in a thread local. This allows the use of the
17  * HttpServletRequest from any code executing in the same
18  * thread scope.
19  * </p>
20  *
21  * <p>
22  * This classes use depends on use of the {@link
23  * RequestManagerFilter RequestManagerFilter} as a filter in
24  * the web application. If this filter does not exist, then
25  * this class will need to be used manually in order to
26  * store the request object in the thread local
27  * </p>
28  *
29  * @author Brian Pontarelli
30  * @since 1.0
31  * @version 2.0
32  */

33 public class HttpRequestManager {
34     
35     /**
36      * The thread local storage
37      */

38     private static ThreadLocal JavaDoc container = new ThreadLocal JavaDoc();
39         
40
41     /**
42      * Creates new HTTPRequestManager
43      */

44     private HttpRequestManager() {
45         // singleton
46
}
47
48     /**
49      * Retrieves the request from the ThreadLocal. If the request was never set
50      * into the ThreadLocal, this will return null
51      *
52      * @return This thread's HttpServletRequest or null if it was never set
53      */

54     public static HttpServletRequest JavaDoc getRequest() {
55         return (HttpServletRequest JavaDoc) container.get();
56     }
57     
58     /**
59      * Stores the request in the ThreadLocal. This must be called once (and only
60      * once) prior calling the getRequest method.
61      *
62      * @param request The HttpServletRequest to store in the ThreadLocal
63      */

64     public static void storeRequest(HttpServletRequest JavaDoc request) {
65         container.set(request);
66     }
67 }
Popular Tags