1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package javax.servlet.http;
21  
22  import javax.servlet.ServletRequestWrapper;
23  import java.util.Enumeration;
24  
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   *
33   * @see 	javax.servlet.http.HttpServletRequest
34    * @since	v 2.3
35   *
36   */
37  
38  
39  public class HttpServletRequestWrapper extends ServletRequestWrapper implements HttpServletRequest {
40  
41  	/** 
42  	* Constructs a request object wrapping the given request.
43  	* @throws java.lang.IllegalArgumentException if the request is null
44  	*/
45      public HttpServletRequestWrapper(HttpServletRequest request) {
46  	    super(request);
47      }
48      
49      private HttpServletRequest _getHttpServletRequest() {
50  	return (HttpServletRequest) super.getRequest();
51      }
52  
53      /**
54       * The default behavior of this method is to return getAuthType()
55       * on the wrapped request object.
56       */
57  
58      public String getAuthType() {
59  	return this._getHttpServletRequest().getAuthType();
60      }
61     
62      /**
63       * The default behavior of this method is to return getCookies()
64       * on the wrapped request object.
65       */
66      public Cookie[] getCookies() {
67  	return this._getHttpServletRequest().getCookies();
68      }
69  
70      /**
71       * The default behavior of this method is to return getDateHeader(String name)
72       * on the wrapped request object.
73       */
74      public long getDateHeader(String name) {
75  	return this._getHttpServletRequest().getDateHeader(name);
76      }
77          	
78      /**
79       * The default behavior of this method is to return getHeader(String name)
80       * on the wrapped request object.
81       */
82      public String getHeader(String name) {
83  	return this._getHttpServletRequest().getHeader(name);
84      }
85      
86      /**
87       * The default behavior of this method is to return getHeaders(String name)
88       * on the wrapped request object.
89       */
90      public Enumeration getHeaders(String name) {
91  	return this._getHttpServletRequest().getHeaders(name);
92      }  
93  
94      /**
95       * The default behavior of this method is to return getHeaderNames()
96       * on the wrapped request object.
97       */
98    
99      public Enumeration getHeaderNames() {
100 	return this._getHttpServletRequest().getHeaderNames();
101     }
102     
103     /**
104      * The default behavior of this method is to return getIntHeader(String name)
105      * on the wrapped request object.
106      */
107 
108      public int getIntHeader(String name) {
109 	return this._getHttpServletRequest().getIntHeader(name);
110     }
111     
112     /**
113      * The default behavior of this method is to return getMethod()
114      * on the wrapped request object.
115      */
116     public String getMethod() {
117 	return this._getHttpServletRequest().getMethod();
118     }
119     
120     /**
121      * The default behavior of this method is to return getPathInfo()
122      * on the wrapped request object.
123      */
124     public String getPathInfo() {
125 	return this._getHttpServletRequest().getPathInfo();
126     }
127 
128     /**
129      * The default behavior of this method is to return getPathTranslated()
130      * on the wrapped request object.
131      */
132 
133      public String getPathTranslated() {
134 	return this._getHttpServletRequest().getPathTranslated();
135     }
136 
137     /**
138      * The default behavior of this method is to return getContextPath()
139      * on the wrapped request object.
140      */
141     public String getContextPath() {
142 	return this._getHttpServletRequest().getContextPath();
143     }
144     
145     /**
146      * The default behavior of this method is to return getQueryString()
147      * on the wrapped request object.
148      */
149     public String getQueryString() {
150 	return this._getHttpServletRequest().getQueryString();
151     }
152     
153     /**
154      * The default behavior of this method is to return getRemoteUser()
155      * on the wrapped request object.
156      */
157     public String getRemoteUser() {
158 	return this._getHttpServletRequest().getRemoteUser();
159     }
160     
161  
162     /**
163      * The default behavior of this method is to return isUserInRole(String role)
164      * on the wrapped request object.
165      */
166     public boolean isUserInRole(String role) {
167 	return this._getHttpServletRequest().isUserInRole(role);
168     }
169     
170     
171     
172     /**
173      * The default behavior of this method is to return getUserPrincipal()
174      * on the wrapped request object.
175      */
176     public java.security.Principal getUserPrincipal() {
177 	return this._getHttpServletRequest().getUserPrincipal();
178     }
179     
180    
181     /**
182      * The default behavior of this method is to return getRequestedSessionId()
183      * on the wrapped request object.
184      */
185     public String getRequestedSessionId() {
186 	return this._getHttpServletRequest().getRequestedSessionId();
187     }
188     
189     /**
190      * The default behavior of this method is to return getRequestURI()
191      * on the wrapped request object.
192      */
193     public String getRequestURI() {
194 	return this._getHttpServletRequest().getRequestURI();
195     }
196 	/**
197      * The default behavior of this method is to return getRequestURL()
198      * on the wrapped request object.
199      */
200     public StringBuffer getRequestURL() {
201 	return this._getHttpServletRequest().getRequestURL();
202     }
203 	
204     
205     /**
206      * The default behavior of this method is to return getServletPath()
207      * on the wrapped request object.
208      */
209     public String getServletPath() {
210 	return this._getHttpServletRequest().getServletPath();
211     }
212     
213     
214     /**
215      * The default behavior of this method is to return getSession(boolean create)
216      * on the wrapped request object.
217      */
218     public HttpSession getSession(boolean create) {
219 	return this._getHttpServletRequest().getSession(create);
220     }
221     
222     /**
223      * The default behavior of this method is to return getSession()
224      * on the wrapped request object.
225      */
226     public HttpSession getSession() {
227 	return this._getHttpServletRequest().getSession();
228     }
229     
230     /**
231      * The default behavior of this method is to return isRequestedSessionIdValid()
232      * on the wrapped request object.
233      */ 
234 
235     public boolean isRequestedSessionIdValid() {
236 	return this._getHttpServletRequest().isRequestedSessionIdValid();
237     }
238      
239     
240     /**
241      * The default behavior of this method is to return isRequestedSessionIdFromCookie()
242      * on the wrapped request object.
243      */
244     public boolean isRequestedSessionIdFromCookie() {
245 	return this._getHttpServletRequest().isRequestedSessionIdFromCookie();
246     }
247     
248     	  /**
249      * The default behavior of this method is to return isRequestedSessionIdFromURL()
250      * on the wrapped request object.
251      */ 
252     public boolean isRequestedSessionIdFromURL() {
253 	return this._getHttpServletRequest().isRequestedSessionIdFromURL();
254     }
255     
256     /**
257      * The default behavior of this method is to return isRequestedSessionIdFromUrl()
258      * on the wrapped request object.
259      */
260     public boolean isRequestedSessionIdFromUrl() {
261 	return this._getHttpServletRequest().isRequestedSessionIdFromUrl();
262     }
263 
264 
265     
266 }