KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > servlet > HttpRequestService


1 package org.apache.beehive.controls.runtime.servlet;
2 /*
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * $Header:$
18  */

19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.http.HttpServletRequestWrapper JavaDoc;
22 import javax.servlet.ServletRequest JavaDoc;
23
24 /**
25  * This class is the contextual service implementation for javax.servlet.http.HttpServletRequest.
26  * It acts as an intermediary between the client and the HttpServletRequest instance held by the
27  * associated ServletBeanContext. It validates that attempt to access the HttpServletRequest
28  * only occur during the servlet request processing lifecycle, then delegates to the underlying
29  * HttpServletRequest instance for actual services.
30  */

31 /* package */ class HttpRequestService extends ServletRequestService implements HttpServletRequest JavaDoc
32 {
33     /**
34      * This static helper class derives from javax.servlet.HttpServletRequestWrapper and can
35      * be used to wrap a HttpServletRequestService instance in cases where the client expects
36      * to be able to use the standard wrapper interfaces to unwrap requests.
37      */

38     private static class Wrapper extends HttpServletRequestWrapper JavaDoc
39     {
40         Wrapper(HttpRequestService requestService)
41         {
42             super(requestService);
43             _requestService = requestService;
44         }
45
46         /**
47          * Overrides the default HttpServletRequestWrapper.getRequest implementation. Rather
48          * than just returning the request passed into the constructor (i.e. the request
49          * service), it will go unwrap step further and return the current (active) http
50          * request.
51          */

52         public HttpServletRequest JavaDoc getRequest()
53         {
54             return _requestService.getHttpServletRequest();
55         }
56
57         HttpRequestService _requestService;
58     }
59     
60     /* package */ HttpRequestService(ServletBeanContext beanContext)
61     {
62         super(beanContext);
63     }
64
65     final protected HttpServletRequest JavaDoc getHttpServletRequest()
66     {
67         ServletRequest JavaDoc servletRequest = getServletBeanContext().getServletRequest();
68         if (! (servletRequest instanceof HttpServletRequest JavaDoc))
69             throw new IllegalStateException JavaDoc("Current request is not an HttpServletRequest");
70         return (HttpServletRequest JavaDoc)servletRequest;
71     }
72
73     /**
74      * This method returns a HttpServletRequestWrapper instance that wraps the request service.
75      * This is useful in instances where there is code that uses the wrapper interfaces to
76      * unwrap requests to get to the 'root' request.
77      */

78     /* package */ HttpServletRequestWrapper JavaDoc getHttpRequestWrapper()
79     {
80         return new Wrapper JavaDoc(this);
81     }
82
83     public java.lang.String JavaDoc getAuthType()
84     {
85         return getHttpServletRequest().getAuthType();
86     }
87
88     public javax.servlet.http.Cookie JavaDoc[] getCookies()
89     {
90         return getHttpServletRequest().getCookies();
91     }
92
93     public long getDateHeader(java.lang.String JavaDoc name)
94     {
95         return getHttpServletRequest().getDateHeader(name);
96     }
97
98     public java.lang.String JavaDoc getHeader(java.lang.String JavaDoc name)
99     {
100         return getHttpServletRequest().getHeader(name);
101     }
102
103     public java.util.Enumeration JavaDoc getHeaders(java.lang.String JavaDoc name)
104     {
105         return getHttpServletRequest().getHeaders(name);
106     }
107
108     public java.util.Enumeration JavaDoc getHeaderNames()
109     {
110         return getHttpServletRequest().getHeaderNames();
111     }
112
113     public int getIntHeader(java.lang.String JavaDoc name)
114     {
115         return getHttpServletRequest().getIntHeader(name);
116     }
117
118     public java.lang.String JavaDoc getMethod()
119     {
120         return getHttpServletRequest().getMethod();
121     }
122
123     public java.lang.String JavaDoc getPathInfo()
124     {
125         return getHttpServletRequest().getPathInfo();
126     }
127
128     public java.lang.String JavaDoc getPathTranslated()
129     {
130         return getHttpServletRequest().getPathTranslated();
131     }
132
133     public java.lang.String JavaDoc getContextPath()
134     {
135         return getHttpServletRequest().getContextPath();
136     }
137
138     public java.lang.String JavaDoc getQueryString()
139     {
140         return getHttpServletRequest().getQueryString();
141     }
142
143     public java.lang.String JavaDoc getRemoteUser()
144     {
145         return getHttpServletRequest().getRemoteUser();
146     }
147
148     public boolean isUserInRole(java.lang.String JavaDoc role)
149     {
150         return getHttpServletRequest().isUserInRole(role);
151     }
152
153     public java.security.Principal JavaDoc getUserPrincipal()
154     {
155         return getHttpServletRequest().getUserPrincipal();
156     }
157
158     public java.lang.String JavaDoc getRequestedSessionId()
159     {
160         return getHttpServletRequest().getRequestedSessionId();
161     }
162
163     public java.lang.String JavaDoc getRequestURI()
164     {
165         return getHttpServletRequest().getRequestURI();
166     }
167
168     public java.lang.StringBuffer JavaDoc getRequestURL()
169     {
170         return getHttpServletRequest().getRequestURL();
171     }
172
173     public java.lang.String JavaDoc getServletPath()
174     {
175         return getHttpServletRequest().getServletPath();
176     }
177
178     public javax.servlet.http.HttpSession JavaDoc getSession(boolean create)
179     {
180         return getHttpServletRequest().getSession(create);
181     }
182
183     public javax.servlet.http.HttpSession JavaDoc getSession()
184     {
185         return getHttpServletRequest().getSession();
186     }
187
188     public boolean isRequestedSessionIdValid()
189     {
190         return getHttpServletRequest().isRequestedSessionIdValid();
191     }
192
193     public boolean isRequestedSessionIdFromCookie()
194     {
195         return getHttpServletRequest().isRequestedSessionIdFromCookie();
196     }
197
198     public boolean isRequestedSessionIdFromURL()
199     {
200         return getHttpServletRequest().isRequestedSessionIdFromURL();
201     }
202
203     public boolean isRequestedSessionIdFromUrl()
204     {
205         return getHttpServletRequest().isRequestedSessionIdFromUrl();
206     }
207 }
208
Popular Tags