]> WPIA git - gigi.git/blob - lib/servlet-api/javax/servlet/http/HttpServletRequestWrapper.java
adding servlet api (from tomcat)
[gigi.git] / lib / servlet-api / javax / servlet / http / HttpServletRequestWrapper.java
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  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 package javax.servlet.http;
18
19 import java.io.IOException;
20 import java.util.Collection;
21 import java.util.Enumeration;
22
23 import javax.servlet.ServletException;
24 import javax.servlet.ServletRequestWrapper;
25
26 /**
27  * Provides a convenient implementation of the HttpServletRequest interface that
28  * can be subclassed by developers wishing to adapt the request to a Servlet.
29  * This class implements the Wrapper or Decorator pattern. Methods default to
30  * calling through to the wrapped request object.
31  *
32  * @see javax.servlet.http.HttpServletRequest
33  * @since v 2.3
34  */
35 public class HttpServletRequestWrapper extends ServletRequestWrapper implements
36         HttpServletRequest {
37
38     /**
39      * Constructs a request object wrapping the given request.
40      *
41      * @throws java.lang.IllegalArgumentException
42      *             if the request is null
43      */
44     public HttpServletRequestWrapper(HttpServletRequest request) {
45         super(request);
46     }
47
48     private HttpServletRequest _getHttpServletRequest() {
49         return (HttpServletRequest) super.getRequest();
50     }
51
52     /**
53      * The default behavior of this method is to return getAuthType() on the
54      * wrapped request object.
55      */
56     @Override
57     public String getAuthType() {
58         return this._getHttpServletRequest().getAuthType();
59     }
60
61     /**
62      * The default behavior of this method is to return getCookies() on the
63      * wrapped request object.
64      */
65     @Override
66     public Cookie[] getCookies() {
67         return this._getHttpServletRequest().getCookies();
68     }
69
70     /**
71      * The default behavior of this method is to return getDateHeader(String
72      * name) on the wrapped request object.
73      */
74     @Override
75     public long getDateHeader(String name) {
76         return this._getHttpServletRequest().getDateHeader(name);
77     }
78
79     /**
80      * The default behavior of this method is to return getHeader(String name)
81      * on the wrapped request object.
82      */
83     @Override
84     public String getHeader(String name) {
85         return this._getHttpServletRequest().getHeader(name);
86     }
87
88     /**
89      * The default behavior of this method is to return getHeaders(String name)
90      * on the wrapped request object.
91      */
92     @Override
93     public Enumeration<String> getHeaders(String name) {
94         return this._getHttpServletRequest().getHeaders(name);
95     }
96
97     /**
98      * The default behavior of this method is to return getHeaderNames() on the
99      * wrapped request object.
100      */
101     @Override
102     public Enumeration<String> getHeaderNames() {
103         return this._getHttpServletRequest().getHeaderNames();
104     }
105
106     /**
107      * The default behavior of this method is to return getIntHeader(String
108      * name) on the wrapped request object.
109      */
110     @Override
111     public int getIntHeader(String name) {
112         return this._getHttpServletRequest().getIntHeader(name);
113     }
114
115     /**
116      * The default behavior of this method is to return getMethod() on the
117      * wrapped request object.
118      */
119     @Override
120     public String getMethod() {
121         return this._getHttpServletRequest().getMethod();
122     }
123
124     /**
125      * The default behavior of this method is to return getPathInfo() on the
126      * wrapped request object.
127      */
128     @Override
129     public String getPathInfo() {
130         return this._getHttpServletRequest().getPathInfo();
131     }
132
133     /**
134      * The default behavior of this method is to return getPathTranslated() on
135      * the wrapped request object.
136      */
137     @Override
138     public String getPathTranslated() {
139         return this._getHttpServletRequest().getPathTranslated();
140     }
141
142     /**
143      * The default behavior of this method is to return getContextPath() on the
144      * wrapped request object.
145      */
146     @Override
147     public String getContextPath() {
148         return this._getHttpServletRequest().getContextPath();
149     }
150
151     /**
152      * The default behavior of this method is to return getQueryString() on the
153      * wrapped request object.
154      */
155     @Override
156     public String getQueryString() {
157         return this._getHttpServletRequest().getQueryString();
158     }
159
160     /**
161      * The default behavior of this method is to return getRemoteUser() on the
162      * wrapped request object.
163      */
164     @Override
165     public String getRemoteUser() {
166         return this._getHttpServletRequest().getRemoteUser();
167     }
168
169     /**
170      * The default behavior of this method is to return isUserInRole(String
171      * role) on the wrapped request object.
172      */
173     @Override
174     public boolean isUserInRole(String role) {
175         return this._getHttpServletRequest().isUserInRole(role);
176     }
177
178     /**
179      * The default behavior of this method is to return getUserPrincipal() on
180      * the wrapped request object.
181      */
182     @Override
183     public java.security.Principal getUserPrincipal() {
184         return this._getHttpServletRequest().getUserPrincipal();
185     }
186
187     /**
188      * The default behavior of this method is to return getRequestedSessionId()
189      * on the wrapped request object.
190      */
191     @Override
192     public String getRequestedSessionId() {
193         return this._getHttpServletRequest().getRequestedSessionId();
194     }
195
196     /**
197      * The default behavior of this method is to return getRequestURI() on the
198      * wrapped request object.
199      */
200     @Override
201     public String getRequestURI() {
202         return this._getHttpServletRequest().getRequestURI();
203     }
204
205     /**
206      * The default behavior of this method is to return getRequestURL() on the
207      * wrapped request object.
208      */
209     @Override
210     public StringBuffer getRequestURL() {
211         return this._getHttpServletRequest().getRequestURL();
212     }
213
214     /**
215      * The default behavior of this method is to return getServletPath() on the
216      * wrapped request object.
217      */
218     @Override
219     public String getServletPath() {
220         return this._getHttpServletRequest().getServletPath();
221     }
222
223     /**
224      * The default behavior of this method is to return getSession(boolean
225      * create) on the wrapped request object.
226      */
227     @Override
228     public HttpSession getSession(boolean create) {
229         return this._getHttpServletRequest().getSession(create);
230     }
231
232     /**
233      * The default behavior of this method is to return getSession() on the
234      * wrapped request object.
235      */
236     @Override
237     public HttpSession getSession() {
238         return this._getHttpServletRequest().getSession();
239     }
240
241     /**
242      * The default behavior of this method is to call changeSessionId() on the
243      * wrapped request object.
244      */
245     @Override
246     public String changeSessionId() {
247         return this._getHttpServletRequest().changeSessionId();
248     }
249
250     /**
251      * The default behavior of this method is to return
252      * isRequestedSessionIdValid() on the wrapped request object.
253      */
254     @Override
255     public boolean isRequestedSessionIdValid() {
256         return this._getHttpServletRequest().isRequestedSessionIdValid();
257     }
258
259     /**
260      * The default behavior of this method is to return
261      * isRequestedSessionIdFromCookie() on the wrapped request object.
262      */
263     @Override
264     public boolean isRequestedSessionIdFromCookie() {
265         return this._getHttpServletRequest().isRequestedSessionIdFromCookie();
266     }
267
268     /**
269      * The default behavior of this method is to return
270      * isRequestedSessionIdFromURL() on the wrapped request object.
271      */
272     @Override
273     public boolean isRequestedSessionIdFromURL() {
274         return this._getHttpServletRequest().isRequestedSessionIdFromURL();
275     }
276
277     /**
278      * The default behavior of this method is to return
279      * isRequestedSessionIdFromUrl() on the wrapped request object.
280      *
281      * @deprecated As of Version 3.0 of the Java Servlet API
282      */
283     @Override
284     @SuppressWarnings("dep-ann")
285     // Spec API does not use @Deprecated
286     public boolean isRequestedSessionIdFromUrl() {
287         return this._getHttpServletRequest().isRequestedSessionIdFromUrl();
288     }
289
290     /**
291      * {@inheritDoc}
292      * <p>
293      * The default behavior of this method is to return
294      * {@link HttpServletRequest#authenticate(HttpServletResponse)}
295      * on the wrapped request object.
296      *
297      * @since Servlet 3.0
298      */
299     @Override
300     public boolean authenticate(HttpServletResponse response)
301             throws IOException, ServletException {
302         return this._getHttpServletRequest().authenticate(response);
303     }
304
305     /**
306      * {@inheritDoc}
307      * <p>
308      * The default behavior of this method is to return
309      * {@link HttpServletRequest#login(String, String)}
310      * on the wrapped request object.
311      *
312      * @since Servlet 3.0
313      */
314     @Override
315     public void login(String username, String password) throws ServletException {
316         this._getHttpServletRequest().login(username, password);
317     }
318
319     /**
320      * {@inheritDoc}
321      * <p>
322      * The default behavior of this method is to return
323      * {@link HttpServletRequest#logout()}
324      * on the wrapped request object.
325      *
326      * @since Servlet 3.0
327      */
328     @Override
329     public void logout() throws ServletException {
330         this._getHttpServletRequest().logout();
331     }
332
333     /**
334      * {@inheritDoc}
335      * <p>
336      * The default behavior of this method is to return
337      * {@link HttpServletRequest#getParts()}
338      * on the wrapped request object.
339      *
340      * @since Servlet 3.0
341      */
342     @Override
343     public Collection<Part> getParts() throws IOException,
344             ServletException {
345         return this._getHttpServletRequest().getParts();
346     }
347
348     /**
349      * {@inheritDoc}
350      * <p>
351      * The default behavior of this method is to return
352      * {@link HttpServletRequest#getPart(String)}
353      * on the wrapped request object.
354      *
355      * @since Servlet 3.0
356      */
357     @Override
358     public Part getPart(String name) throws IOException,
359             ServletException {
360         return this._getHttpServletRequest().getPart(name);
361     }
362
363     /**
364      * {@inheritDoc}
365      * <p>
366      * The default behavior of this method is to return
367      * {@link HttpServletRequest#upgrade(Class)} on the wrapped request object.
368      *
369      * @since Servlet 3.1
370      */
371     @Override
372     public <T extends HttpUpgradeHandler> T upgrade(
373             Class<T> httpUpgradeHandlerClass) throws IOException, ServletException {
374         return this._getHttpServletRequest().upgrade(httpUpgradeHandlerClass);
375     }
376 }