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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package javax.servlet.http;
19 import java.io.IOException;
20 import java.util.Collection;
21 import java.util.Enumeration;
23 import javax.servlet.ServletException;
24 import javax.servlet.ServletRequestWrapper;
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.
32 * @see javax.servlet.http.HttpServletRequest
35 public class HttpServletRequestWrapper extends ServletRequestWrapper implements
39 * Constructs a request object wrapping the given request.
41 * @throws java.lang.IllegalArgumentException
42 * if the request is null
44 public HttpServletRequestWrapper(HttpServletRequest request) {
48 private HttpServletRequest _getHttpServletRequest() {
49 return (HttpServletRequest) super.getRequest();
53 * The default behavior of this method is to return getAuthType() on the
54 * wrapped request object.
57 public String getAuthType() {
58 return this._getHttpServletRequest().getAuthType();
62 * The default behavior of this method is to return getCookies() on the
63 * wrapped request object.
66 public Cookie[] getCookies() {
67 return this._getHttpServletRequest().getCookies();
71 * The default behavior of this method is to return getDateHeader(String
72 * name) on the wrapped request object.
75 public long getDateHeader(String name) {
76 return this._getHttpServletRequest().getDateHeader(name);
80 * The default behavior of this method is to return getHeader(String name)
81 * on the wrapped request object.
84 public String getHeader(String name) {
85 return this._getHttpServletRequest().getHeader(name);
89 * The default behavior of this method is to return getHeaders(String name)
90 * on the wrapped request object.
93 public Enumeration<String> getHeaders(String name) {
94 return this._getHttpServletRequest().getHeaders(name);
98 * The default behavior of this method is to return getHeaderNames() on the
99 * wrapped request object.
102 public Enumeration<String> getHeaderNames() {
103 return this._getHttpServletRequest().getHeaderNames();
107 * The default behavior of this method is to return getIntHeader(String
108 * name) on the wrapped request object.
111 public int getIntHeader(String name) {
112 return this._getHttpServletRequest().getIntHeader(name);
116 * The default behavior of this method is to return getMethod() on the
117 * wrapped request object.
120 public String getMethod() {
121 return this._getHttpServletRequest().getMethod();
125 * The default behavior of this method is to return getPathInfo() on the
126 * wrapped request object.
129 public String getPathInfo() {
130 return this._getHttpServletRequest().getPathInfo();
134 * The default behavior of this method is to return getPathTranslated() on
135 * the wrapped request object.
138 public String getPathTranslated() {
139 return this._getHttpServletRequest().getPathTranslated();
143 * The default behavior of this method is to return getContextPath() on the
144 * wrapped request object.
147 public String getContextPath() {
148 return this._getHttpServletRequest().getContextPath();
152 * The default behavior of this method is to return getQueryString() on the
153 * wrapped request object.
156 public String getQueryString() {
157 return this._getHttpServletRequest().getQueryString();
161 * The default behavior of this method is to return getRemoteUser() on the
162 * wrapped request object.
165 public String getRemoteUser() {
166 return this._getHttpServletRequest().getRemoteUser();
170 * The default behavior of this method is to return isUserInRole(String
171 * role) on the wrapped request object.
174 public boolean isUserInRole(String role) {
175 return this._getHttpServletRequest().isUserInRole(role);
179 * The default behavior of this method is to return getUserPrincipal() on
180 * the wrapped request object.
183 public java.security.Principal getUserPrincipal() {
184 return this._getHttpServletRequest().getUserPrincipal();
188 * The default behavior of this method is to return getRequestedSessionId()
189 * on the wrapped request object.
192 public String getRequestedSessionId() {
193 return this._getHttpServletRequest().getRequestedSessionId();
197 * The default behavior of this method is to return getRequestURI() on the
198 * wrapped request object.
201 public String getRequestURI() {
202 return this._getHttpServletRequest().getRequestURI();
206 * The default behavior of this method is to return getRequestURL() on the
207 * wrapped request object.
210 public StringBuffer getRequestURL() {
211 return this._getHttpServletRequest().getRequestURL();
215 * The default behavior of this method is to return getServletPath() on the
216 * wrapped request object.
219 public String getServletPath() {
220 return this._getHttpServletRequest().getServletPath();
224 * The default behavior of this method is to return getSession(boolean
225 * create) on the wrapped request object.
228 public HttpSession getSession(boolean create) {
229 return this._getHttpServletRequest().getSession(create);
233 * The default behavior of this method is to return getSession() on the
234 * wrapped request object.
237 public HttpSession getSession() {
238 return this._getHttpServletRequest().getSession();
242 * The default behavior of this method is to call changeSessionId() on the
243 * wrapped request object.
246 public String changeSessionId() {
247 return this._getHttpServletRequest().changeSessionId();
251 * The default behavior of this method is to return
252 * isRequestedSessionIdValid() on the wrapped request object.
255 public boolean isRequestedSessionIdValid() {
256 return this._getHttpServletRequest().isRequestedSessionIdValid();
260 * The default behavior of this method is to return
261 * isRequestedSessionIdFromCookie() on the wrapped request object.
264 public boolean isRequestedSessionIdFromCookie() {
265 return this._getHttpServletRequest().isRequestedSessionIdFromCookie();
269 * The default behavior of this method is to return
270 * isRequestedSessionIdFromURL() on the wrapped request object.
273 public boolean isRequestedSessionIdFromURL() {
274 return this._getHttpServletRequest().isRequestedSessionIdFromURL();
278 * The default behavior of this method is to return
279 * isRequestedSessionIdFromUrl() on the wrapped request object.
281 * @deprecated As of Version 3.0 of the Java Servlet API
284 @SuppressWarnings("dep-ann")
285 // Spec API does not use @Deprecated
286 public boolean isRequestedSessionIdFromUrl() {
287 return this._getHttpServletRequest().isRequestedSessionIdFromUrl();
293 * The default behavior of this method is to return
294 * {@link HttpServletRequest#authenticate(HttpServletResponse)}
295 * on the wrapped request object.
300 public boolean authenticate(HttpServletResponse response)
301 throws IOException, ServletException {
302 return this._getHttpServletRequest().authenticate(response);
308 * The default behavior of this method is to return
309 * {@link HttpServletRequest#login(String, String)}
310 * on the wrapped request object.
315 public void login(String username, String password) throws ServletException {
316 this._getHttpServletRequest().login(username, password);
322 * The default behavior of this method is to return
323 * {@link HttpServletRequest#logout()}
324 * on the wrapped request object.
329 public void logout() throws ServletException {
330 this._getHttpServletRequest().logout();
336 * The default behavior of this method is to return
337 * {@link HttpServletRequest#getParts()}
338 * on the wrapped request object.
343 public Collection<Part> getParts() throws IOException,
345 return this._getHttpServletRequest().getParts();
351 * The default behavior of this method is to return
352 * {@link HttpServletRequest#getPart(String)}
353 * on the wrapped request object.
358 public Part getPart(String name) throws IOException,
360 return this._getHttpServletRequest().getPart(name);
366 * The default behavior of this method is to return
367 * {@link HttpServletRequest#upgrade(Class)} on the wrapped request object.
372 public <T extends HttpUpgradeHandler> T upgrade(
373 Class<T> httpUpgradeHandlerClass) throws IOException, ServletException {
374 return this._getHttpServletRequest().upgrade(httpUpgradeHandlerClass);