e.g. Calendar Search Help
You must enter a value before pressing Search
tomcat

Class: org.apache.catalina.connector.RequestFacade   ©

 OK to copy?
001 /*
002  * Copyright 1999,2004 The Apache Software Foundation.
003  * 
004  * Licensed under the Apache License, Version 2.0 (the "License");
005  * you may not use this file except in compliance with the License.
006  * You may obtain a copy of the License at
007  * 
008  *      http://www.apache.org/licenses/LICENSE-2.0
009  * 
010  * Unless required by applicable law or agreed to in writing, software
011  * distributed under the License is distributed on an "AS IS" BASIS,
012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013  * See the License for the specific language governing permissions and
014  * limitations under the License.
015  */
016 
017 
018 package org.apache.catalina.connector;
019 
020 import java.io.BufferedReader;
021 import java.io.IOException;
022 import java.security.AccessController;
023 import java.security.PrivilegedAction;
024 import java.util.Enumeration;
025 import java.util.Locale;
026 import java.util.Map;
027 
028 import javax.servlet.RequestDispatcher;
029 import javax.servlet.ServletInputStream;
030 import javax.servlet.http.Cookie;
031 import javax.servlet.http.HttpServletRequest;
032 import javax.servlet.http.HttpSession;
033 
034 
035 /**
036  * Facade class that wraps a Coyote request object.  
037  * All methods are delegated to the wrapped request.
038  *
039  * @author Craig R. McClanahan
040  * @author Remy Maucherat
041  * @author Jean-Francois Arcand
042  * @version $Revision: 1.5 $ $Date: 2004/06/23 08:24:57 $
043  */
044 
045 
046 public class RequestFacade 
047     implements HttpServletRequest {
048         
049         
050     // ----------------------------------------------------------- DoPrivileged
051     
052     private final class GetAttributePrivilegedAction implements PrivilegedAction{
053         
054         public Object run() {
055             return request.getAttributeNames();
056         }            
057     }
058      
059     
060     private final class GetParameterMapPrivilegedAction implements PrivilegedAction{
061         
062         public Object run() {
063             return request.getParameterMap();
064         }        
065     }    
066     
067     
068     private final class GetRequestDispatcherPrivilegedAction implements PrivilegedAction{
069         private String path;
070         public GetRequestDispatcherPrivilegedAction(String path){
071             this.path = path;
072         }
073         
074         public Object run() {   
075             return request.getRequestDispatcher(path);
076        }           
077     }    
078     
079     
080     private final class GetParameterPrivilegedAction implements PrivilegedAction{
081         public String name;
082         public GetParameterPrivilegedAction(String name){
083             this.name = name;
084         }
085         public Object run() {       
086             return request.getParameter(name);
087         }           
088     }    
089     
090      
091     private final class GetParameterNamesPrivilegedAction implements PrivilegedAction{
092         
093         public Object run() {          
094             return request.getParameterNames();
095         }           
096     } 
097     
098     
099     private final class GetParameterValuePrivilegedAction implements PrivilegedAction{
100         public String name;
101         public GetParameterValuePrivilegedAction(String name){
102             this.name = name;
103         }
104         public Object run() {       
105             return request.getParameterValues(name);
106         }           
107     }    
108   
109     
110     private final class GetCookiesPrivilegedAction implements PrivilegedAction{
111         
112        public Object run() {       
113             return request.getCookies();
114         }           
115     }      
116     
117     
118     private final class GetCharacterEncodingPrivilegedAction implements PrivilegedAction{
119         
120         public Object run() {       
121             return request.getCharacterEncoding();
122         }           
123     }   
124         
125     
126     private final class GetHeadersPrivilegedAction implements PrivilegedAction{
127         private String name;
128         public GetHeadersPrivilegedAction(String name){
129             this.name = name;
130         }
131         
132         public Object run() {       
133             return request.getHeaders(name);
134         }           
135     }    
136         
137     
138     private final class GetHeaderNamesPrivilegedAction implements PrivilegedAction{
139 
140         public Object run() {       
Rate141             return request.getHeaderNames();
142         }           
143     }  
144             
145     
146     private final class GetLocalePrivilegedAction implements PrivilegedAction{
147 
148         public Object run() {       
149             return request.getLocale();
150         }           
151     }    
152             
153     
154     private final class GetLocalesPrivilegedAction implements PrivilegedAction{
155 
156         public Object run() {       
157             return request.getLocales();
158         }           
159     }    
160     
161     private final class GetSessionPrivilegedAction implements PrivilegedAction{
162         private boolean create;
163         
164         public GetSessionPrivilegedAction(boolean create){
165             this.create = create;
166         }
167                 
168         public Object run() {  
169             return request.getSession(create);
170         }           
171     }      
172     // ----------------------------------------------------------- Constructors
173 
174 
175     /**
176      * Construct a wrapper for the specified request.
177      *
178      * @param request The request to be wrapped
179      */
180     public RequestFacade(Request request) {
181 
182         this.request = request;
183 
184     }
185 
186 
187     // ----------------------------------------------------- Instance Variables
188 
189 
190     /**
191      * The wrapped request.
192      */
193     protected Request request = null;
194 
195 
196     // --------------------------------------------------------- Public Methods
197 
198 
199     /**
200      * Clear facade.
201      */
202     public void clear() {
203         request = null;
204     }
205 
206 
207     // ------------------------------------------------- ServletRequest Methods
208 
209 
210     public Object getAttribute(String name) {
211         return request.getAttribute(name);
212     }
213 
214 
215     public Enumeration getAttributeNames() {
216         if (System.getSecurityManager() != null){
217             return (Enumeration)AccessController.doPrivileged(
218                 new GetAttributePrivilegedAction());        
219         } else {
220             return request.getAttributeNames();
221         }
222     }
223 
224 
225     public String getCharacterEncoding() {
226         if (System.getSecurityManager() != null){
227             return (String)AccessController.doPrivileged(
228                 new GetCharacterEncodingPrivilegedAction());
229         } else {
230             return request.getCharacterEncoding();
231         }         
232     }
233 
234 
235     public void setCharacterEncoding(String env)
236         throws java.io.UnsupportedEncodingException {
237         request.setCharacterEncoding(env);
238     }
239 
240 
241     public int getContentLength() {
242         return request.getContentLength();
243     }
244 
245 
246     public String getContentType() {
247         return request.getContentType();
248     }
249 
250 
251     public ServletInputStream getInputStream()
252         throws IOException {
253         return request.getInputStream();
254     }
255 
256 
257     public String getParameter(String name) {
258         if (System.getSecurityManager() != null){
259             return (String)AccessController.doPrivileged(
260                 new GetParameterPrivilegedAction(name));
261         } else {
262             return request.getParameter(name);
263         }
264     }
265 
266 
267     public Enumeration getParameterNames() {
268         if (System.getSecurityManager() != null){
269             return (Enumeration)AccessController.doPrivileged(
270                 new GetParameterNamesPrivilegedAction());
271         } else {
272             return request.getParameterNames();
273         }
274     }
275 
276 
277     public String[] getParameterValues(String name) {
278 
279         String[] ret = null;
280 
281         /*
282          * Clone the returned array only if there is a security manager
283          * in place, so that performance won't suffer in the nonsecure case
284          */
285         if (System.getSecurityManager() != null){
286             ret = (String[]) AccessController.doPrivileged(
287                 new GetParameterValuePrivilegedAction(name));
288             if (ret != null) {
289                 ret = (String[]) ret.clone();
290             }
291         } else {
292             ret = request.getParameterValues(name);
293         }
294 
295         return ret;
296     }
297 
298 
299     public Map getParameterMap() {
300         if (System.getSecurityManager() != null){
301             return (Map)AccessController.doPrivileged(
302                 new GetParameterMapPrivilegedAction());        
303         } else {
304             return request.getParameterMap();
305         }
306     }
307 
308 
309     public String getProtocol() {
310         return request.getProtocol();
311     }
312 
313 
314     public String getScheme() {
315         return request.getScheme();
316     }
317 
318 
319     public String getServerName() {
320         return request.getServerName();
321     }
322 
323 
324     public int getServerPort() {
325         return request.getServerPort();
326     }
327 
328 
329     public BufferedReader getReader()
330         throws IOException {
331         return request.getReader();
332     }
333 
334 
335     public String getRemoteAddr() {
336         return request.getRemoteAddr();
337     }
338 
339 
340     public String getRemoteHost() {
341         return request.getRemoteHost();
342     }
343 
344 
345     public void setAttribute(String name, Object o) {
346         request.setAttribute(name, o);
347     }
348 
349 
350     public void removeAttribute(String name) {
351         request.removeAttribute(name);
352     }
353 
354 
355     public Locale getLocale() {
356         if (System.getSecurityManager() != null){
357             return (Locale)AccessController.doPrivileged(
358                 new GetLocalePrivilegedAction());
359         } else {
360             return request.getLocale();
361         }        
362     }
363 
364 
365     public Enumeration getLocales() {
366         if (System.getSecurityManager() != null){
367             return (Enumeration)AccessController.doPrivileged(
368                 new GetLocalesPrivilegedAction());
369         } else {
370             return request.getLocales();
371         }        
372     }
373 
374 
375     public boolean isSecure() {
376         return request.isSecure();
377     }
378 
379 
380     public RequestDispatcher getRequestDispatcher(String path) {
381         if (System.getSecurityManager() != null){
382             return (RequestDispatcher)AccessController.doPrivileged(
383                 new GetRequestDispatcherPrivilegedAction(path));
384         } else {
385             return request.getRequestDispatcher(path);
386         }
387     }
388 
389 
390     public String getRealPath(String path) {
391         return request.getRealPath(path);
392     }
393 
394 
395     public String getAuthType() {
396         return request.getAuthType();
397     }
398 
399 
400     public Cookie[] getCookies() {
401 
402         Cookie[] ret = null;
403 
404         /*
405          * Clone the returned array only if there is a security manager
406          * in place, so that performance won't suffer in the nonsecure case
407          */
408         if (System.getSecurityManager() != null){
409             ret = (Cookie[])AccessController.doPrivileged(
410                 new GetCookiesPrivilegedAction());
411             if (ret != null) {
412                 ret = (Cookie[]) ret.clone();
413             }
414         } else {
415             ret = request.getCookies();
416         }
417 
418         return ret;
419     }
420 
421 
422     public long getDateHeader(String name) {
423         return request.getDateHeader(name);
424     }
425 
426 
427     public String getHeader(String name) {
428         return request.getHeader(name);
429     }
430 
431 
432     public Enumeration getHeaders(String name) {
433         if (System.getSecurityManager() != null){
434             return (Enumeration)AccessController.doPrivileged(
435                 new GetHeadersPrivilegedAction(name));
436         } else {
437             return request.getHeaders(name);
438         }         
439     }
440 
441 
442     public Enumeration getHeaderNames() {
443         if (System.getSecurityManager() != null){
444             return (Enumeration)AccessController.doPrivileged(
445                 new GetHeaderNamesPrivilegedAction());
446         } else {
Rate447             return request.getHeaderNames();
448         }             
449     }
450 
451 
452     public int getIntHeader(String name) {
453         return request.getIntHeader(name);
454     }
455 
456 
457     public String getMethod() {
458         return request.getMethod();
459     }
460 
461 
462     public String getPathInfo() {
463         return request.getPathInfo();
464     }
465 
466 
467     public String getPathTranslated() {
468         return request.getPathTranslated();
469     }
470 
471 
472     public String getContextPath() {
473         return request.getContextPath();
474     }
475 
476 
477     public String getQueryString() {
478         return request.getQueryString();
479     }
480 
481 
482     public String getRemoteUser() {
483         return request.getRemoteUser();
484     }
485 
486 
487     public boolean isUserInRole(String role) {
488         return request.isUserInRole(role);
489     }
490 
491 
492     public java.security.Principal getUserPrincipal() {
493         return request.getUserPrincipal();
494     }
495 
496 
497     public String getRequestedSessionId() {
498         return request.getRequestedSessionId();
499     }
500 
501 
502     public String getRequestURI() {
503         return request.getRequestURI();
504     }
505 
506 
507     public StringBuffer getRequestURL() {
508         return request.getRequestURL();
509     }
510 
511 
512     public String getServletPath() {
513         return request.getServletPath();
514     }
515 
516 
517     public HttpSession getSession(boolean create) {
518 
519         if (System.getSecurityManager() != null){
520             return (HttpSession)AccessController.
521                 doPrivileged(new GetSessionPrivilegedAction(create));
522         } else {
523             return request.getSession(create);
524         }
525     }
526 
527     public HttpSession getSession() {
528         return getSession(true);
529     }
530 
531 
532     public boolean isRequestedSessionIdValid() {
533         return request.isRequestedSessionIdValid();
534     }
535 
536 
537     public boolean isRequestedSessionIdFromCookie() {
538         return request.isRequestedSessionIdFromCookie();
539     }
540 
541 
542     public boolean isRequestedSessionIdFromURL() {
543         return request.isRequestedSessionIdFromURL();
544     }
545 
546 
547     public boolean isRequestedSessionIdFromUrl() {
548         return request.isRequestedSessionIdFromURL();
549     }
550 
551 
552     public String getLocalAddr() {
553         return request.getLocalAddr();
554     }
555 
556 
557     public String getLocalName() {
558         return request.getLocalName();
559     }
560 
561 
562     public int getLocalPort() {
563         return request.getLocalPort();
564     }
565 
566 
567     public int getRemotePort() {
568         return request.getRemotePort();
569     }
570 
571 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
141 0% of 0
447 0% of 0