001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *  http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    
020    package javax.servlet.http;
021    
022    import javax.servlet.ServletRequestWrapper;
023    import javax.servlet.ServletException;
024    
025    import java.util.Enumeration;
026    import java.util.Collection;
027    import java.io.IOException;
028    
029    /**
030     * Provides a convenient implementation of the HttpServletRequest interface that
031     * can be subclassed by developers wishing to adapt the request to a Servlet.
032     * This class implements the Wrapper or Decorator pattern. Methods default to
033     * calling through to the wrapped request object.
034     *
035     * @version $Rev: 831066 $ $Date: 2009-10-29 15:19:48 -0400 (Thu, 29 Oct 2009) $
036     * @since v 2.3
037     * @see javax.servlet.http.HttpServletRequest
038     */
039    
040    
041    public class HttpServletRequestWrapper extends ServletRequestWrapper implements HttpServletRequest {
042    
043        /**
044         * Constructs a request object wrapping the given request.
045         *
046         * @param request request to wrap
047         * @throws java.lang.IllegalArgumentException
048         *          if the request is null
049         */
050        public HttpServletRequestWrapper(HttpServletRequest request) {
051            super(request);
052        }
053    
054        private HttpServletRequest getHttpServletRequest() {
055            return (HttpServletRequest) super.getRequest();
056        }
057    
058        public boolean authenticate(HttpServletResponse response) throws IOException, ServletException {
059            return getHttpServletRequest().authenticate(response);
060        }
061    
062        /**
063         * The default behavior of this method is to return getAuthType()
064         * on the wrapped request object.
065         */
066        public String getAuthType() {
067            return getHttpServletRequest().getAuthType();
068        }
069    
070        /**
071         * The default behavior of this method is to return getCookies()
072         * on the wrapped request object.
073         */
074        public Cookie[] getCookies() {
075            return getHttpServletRequest().getCookies();
076        }
077    
078        /**
079         * The default behavior of this method is to return getDateHeader(String name)
080         * on the wrapped request object.
081         */
082        public long getDateHeader(String name) {
083            return getHttpServletRequest().getDateHeader(name);
084        }
085    
086        /**
087         * The default behavior of this method is to return getHeader(String name)
088         * on the wrapped request object.
089         */
090        public String getHeader(String name) {
091            return getHttpServletRequest().getHeader(name);
092        }
093    
094        /**
095         * The default behavior of this method is to return getHeaders(String name)
096         * on the wrapped request object.
097         */
098        public Enumeration<String> getHeaders(String name) {
099            return getHttpServletRequest().getHeaders(name);
100        }
101    
102        /**
103         * The default behavior of this method is to return getHeaderNames()
104         * on the wrapped request object.
105         */
106    
107        public Enumeration<String> getHeaderNames() {
108            return getHttpServletRequest().getHeaderNames();
109        }
110    
111        /**
112         * The default behavior of this method is to return getIntHeader(String name)
113         * on the wrapped request object.
114         */
115    
116        public int getIntHeader(String name) {
117            return getHttpServletRequest().getIntHeader(name);
118        }
119    
120        /**
121         * The default behavior of this method is to return getMethod()
122         * on the wrapped request object.
123         */
124        public String getMethod() {
125            return getHttpServletRequest().getMethod();
126        }
127    
128        public Part getPart(String name) throws IOException, ServletException {
129            return getHttpServletRequest().getPart(name);
130        }
131    
132        public Collection<Part> getParts() throws IOException, ServletException {
133            return getHttpServletRequest().getParts();
134        }
135    
136        /**
137         * The default behavior of this method is to return getPathInfo()
138         * on the wrapped request object.
139         */
140        public String getPathInfo() {
141            return getHttpServletRequest().getPathInfo();
142        }
143    
144        /**
145         * The default behavior of this method is to return getPathTranslated()
146         * on the wrapped request object.
147         */
148    
149        public String getPathTranslated() {
150            return getHttpServletRequest().getPathTranslated();
151        }
152    
153        /**
154         * The default behavior of this method is to return getContextPath()
155         * on the wrapped request object.
156         */
157        public String getContextPath() {
158            return getHttpServletRequest().getContextPath();
159        }
160    
161        /**
162         * The default behavior of this method is to return getQueryString()
163         * on the wrapped request object.
164         */
165        public String getQueryString() {
166            return getHttpServletRequest().getQueryString();
167        }
168    
169        /**
170         * The default behavior of this method is to return getRemoteUser()
171         * on the wrapped request object.
172         */
173        public String getRemoteUser() {
174            return getHttpServletRequest().getRemoteUser();
175        }
176    
177        /**
178         * The default behavior of this method is to return isUserInRole(String role)
179         * on the wrapped request object.
180         */
181        public boolean isUserInRole(String role) {
182            return getHttpServletRequest().isUserInRole(role);
183        }
184    
185        public void login(String username, String password) throws ServletException {
186            getHttpServletRequest().login(username, password);
187        }
188    
189        public void logout() throws ServletException {
190            getHttpServletRequest().logout();
191        }
192    
193        /**
194         * The default behavior of this method is to return getUserPrincipal()
195         * on the wrapped request object.
196         */
197        public java.security.Principal getUserPrincipal() {
198            return getHttpServletRequest().getUserPrincipal();
199        }
200    
201        /**
202         * The default behavior of this method is to return getRequestedSessionId()
203         * on the wrapped request object.
204         */
205        public String getRequestedSessionId() {
206            return getHttpServletRequest().getRequestedSessionId();
207        }
208    
209        /**
210         * The default behavior of this method is to return getRequestURI()
211         * on the wrapped request object.
212         */
213        public String getRequestURI() {
214            return getHttpServletRequest().getRequestURI();
215        }
216    
217        /**
218         * The default behavior of this method is to return getRequestURL()
219         * on the wrapped request object.
220         */
221        public StringBuffer getRequestURL() {
222            return getHttpServletRequest().getRequestURL();
223        }
224    
225        /**
226         * The default behavior of this method is to return getServletPath()
227         * on the wrapped request object.
228         */
229        public String getServletPath() {
230            return getHttpServletRequest().getServletPath();
231        }
232    
233        /**
234         * The default behavior of this method is to return getSession(boolean create)
235         * on the wrapped request object.
236         */
237        public HttpSession getSession(boolean create) {
238            return getHttpServletRequest().getSession(create);
239        }
240    
241        /**
242         * The default behavior of this method is to return getSession()
243         * on the wrapped request object.
244         */
245        public HttpSession getSession() {
246            return getHttpServletRequest().getSession();
247        }
248    
249        /**
250         * The default behavior of this method is to return isRequestedSessionIdValid()
251         * on the wrapped request object.
252         */
253    
254        public boolean isRequestedSessionIdValid() {
255            return getHttpServletRequest().isRequestedSessionIdValid();
256        }
257    
258        /**
259         * The default behavior of this method is to return isRequestedSessionIdFromCookie()
260         * on the wrapped request object.
261         */
262        public boolean isRequestedSessionIdFromCookie() {
263            return getHttpServletRequest().isRequestedSessionIdFromCookie();
264        }
265    
266        /**
267         * The default behavior of this method is to return isRequestedSessionIdFromURL()
268         * on the wrapped request object.
269         */
270        public boolean isRequestedSessionIdFromURL() {
271            return getHttpServletRequest().isRequestedSessionIdFromURL();
272        }
273    
274        /**
275         * The default behavior of this method is to return isRequestedSessionIdFromUrl()
276         * on the wrapped request object.
277         */
278        public boolean isRequestedSessionIdFromUrl() {
279            return getHttpServletRequest().isRequestedSessionIdFromUrl();
280        }
281    
282    }