Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/prolifics/servlet/FilterHttpServletRequest.java


1   /*************************************************/
2   /*  Copyright (c) 1999         */
3   /*      by         */
4   /*  JYACC, Inc., New York NY USA     */
5   /*  and contributors.         */
6   /*  Use of this program is governed by the   */
7   /*  JYACC Public License Version 1.0, a copy of   */
8   /*  which can be obtained at       */
9   /*  http://www.possl.org/jyacc-license.html   */
10  /*************************************************/
11  
12  /* @(#)FilterHttpServletRequest.java  77.1 99/04/22 15:03:04 */
13  
14  package com.prolifics.servlet;
15  
16  import javax.servlet.http.*;
17  import javax.servlet.*;
18  import java.util.Enumeration;
19  
20  import java.io.BufferedReader;
21  import java.io.IOException;
22  import java.io.UnsupportedEncodingException;
23  
24  /**
25   * An HTTP servlet request.  This interface gets data from the client
26   * to the servlet for use in the <code>HttpServlet.service</code>
27   * method.  It allows the HTTP-protocol specified header information to
28   * be accessed from the <code>service</code> method.  This interface is
29   * implemented by network-service developers for use within servlets.
30   *
31   * @version    @(#)FilterHttpServletRequest.java  77.1 99/04/22 15:03:04
32   */
33  public
34  class FilterHttpServletRequest implements HttpServletRequest
35  {
36    private static String sccsid = "@(#)FilterHttpServletRequest.java  77.1 99/04/22 15:03:04";
37  
38    private HttpServletRequest req;
39  
40    public FilterHttpServletRequest(HttpServletRequest req)
41    {
42      this.req = req;
43    }
44  
45    /**
46     * Gets the array of cookies found in this request.
47     *
48     * @return the array of cookies found in this request
49     */
50    public Cookie[] getCookies()
51    {
52      return req.getCookies();
53    }
54  
55    /**
56     * Gets the HTTP method (for example, GET, POST, PUT) with which
57     * this request was made. Same as the CGI variable REQUEST_METHOD.
58     *
59     * @return the HTTP method with which this request was made
60     */
61    public String getMethod()
62    {
63      return req.getMethod();
64    }
65  
66    /**
67     * Gets, from the first line of the HTTP request, the part of this
68     * request's URI that is to the left of any query string.
69     * For example,
70     *
71     * <blockquote>
72     * <table>
73     * <tr align=left><th>First line of HTTP request<th>
74     * <th>Return from <code>getRequestURI</code>
75     * <tr><td>POST /some/path.html HTTP/1.1<td><td>/some/path.html
76     * <tr><td>GET http://foo.bar/a.html HTTP/1.0
77     * <td><td>http://foo.bar/a.html
78     * <tr><td>HEAD /xyz?a=b HTTP/1.1<td><td>/xyz
79     * </table>
80     * </blockquote>
81     * 
82     * <p>To reconstruct a URL with a URL scheme and host, use the
83     * method javax.servlet.http.HttpUtils.getRequestURL, which returns
84     * a StringBuffer.
85     *
86     * @return this request's URI
87     * @see javax.servlet.http.HttpUtils#getRequestURL
88     */
89    public String getRequestURI()
90    {
91      return req.getRequestURI();
92    }
93  
94    /**
95     * Gets the part of this request's URI that refers to the servlet
96     * being invoked. Analogous to the CGI variable SCRIPT_NAME.
97     *
98     * @return the servlet being invoked, as contained in this
99     * request's URI
100    */
101   public String getServletPath()
102   {
103     return req.getServletPath();
104   }
105 
106   /**
107    * Gets any optional extra path information following the servlet
108    * path of this request's URI, but immediately preceding its query
109    * string. Same as the CGI variable PATH_INFO.
110    *
111    * @return the optional path information following the servlet
112    * path, but before the query string, in this request's URI; null
113    * if this request's URI contains no extra path information
114    */
115   public String getPathInfo()
116   {
117     return req.getPathInfo();
118   }
119 
120   /**
121    * Gets any optional extra path information following the servlet
122    * path of this request's URI, but immediately preceding its query
123    * string, and translates it to a real path.  Similar to the CGI
124    * variable PATH_TRANSLATED
125    *
126    * @return extra path information translated to a real path or null
127    * if no extra path information is in the request's URI
128    */
129   public String getPathTranslated()
130   {
131     return req.getPathTranslated();
132   }
133 
134   /**
135    * Gets any query string that is part of the HTTP request URI.
136    * Same as the CGI variable QUERY_STRING.
137    *
138    * @return query string that is part of this request's URI, or null
139    * if it contains no query string
140    */
141   public String getQueryString()
142   {
143     return req.getQueryString();
144   }
145 
146   /**
147    * Gets the name of the user making this request.  The user name is
148    * set with HTTP authentication.  Whether the user name will
149    * continue to be sent with each subsequent communication is
150    * browser-dependent.  Same as the CGI variable REMOTE_USER.
151    *
152    * @return the name of the user making this request, or null if not
153    * known.
154    */
155   public String getRemoteUser()
156   {
157     return req.getRemoteUser();
158   }
159 
160   /**
161    * Gets the authentication scheme of this request.  Same as the CGI
162    * variable AUTH_TYPE.
163    *
164    * @return this request's authentication scheme, or null if none.
165    */
166   public String getAuthType()
167   {
168     return req.getAuthType();
169   }
170 
171   /**
172    * Gets the value of the requested header field of this request.
173    * The case of the header field name is ignored.
174    * 
175    * @param name the String containing the name of the requested
176    * header field
177    * @return the value of the requested header field, or null if not
178    * known.
179    */
180   public String getHeader(String name)
181   {
182     return req.getHeader(name);
183   } 
184 
185   /**
186    * Gets the value of the specified integer header field of this
187    * request.  The case of the header field name is ignored.  If the
188    * header can't be converted to an integer, the method throws a
189    * NumberFormatException.
190    * 
191    * @param name the String containing the name of the requested
192    * header field
193    * @return the value of the requested header field, or -1 if not
194    * found.
195    */
196   public int getIntHeader(String name)
197   {
198     return req.getIntHeader(name);
199   }
200 
201   /**
202    * Gets the value of the requested date header field of this
203    * request.  If the header can't be converted to a date, the method
204    * throws an IllegalArgumentException.  The case of the header
205    * field name is ignored.
206    * 
207    * @param name the String containing the name of the requested
208    * header field
209    * @return the value the requested date header field, or -1 if not
210    * found.
211    */
212   public long getDateHeader(String name)
213   {
214     return req.getDateHeader(name);
215   }
216 
217   /**
218    * Gets the header names for this request.
219    *
220    * @return an enumeration of strings representing the header names
221    * for this request. Some server implementations do not allow
222    * headers to be accessed in this way, in which case this method
223    * will return null.
224    */
225   public Enumeration getHeaderNames()
226   {
227     return req.getHeaderNames();
228   }
229 
230   /**
231    * Gets the current valid session associated with this request, if
232    * create is false or, if necessary, creates a new session for the
233    * request, if create is true.
234    *
235    * <p><b>Note</b>: to ensure the session is properly maintained,
236    * the servlet developer must call this method (at least once)
237    * before any output is written to the response.
238    *
239    * <p>Additionally, application-writers need to be aware that newly
240    * created sessions (that is, sessions for which
241    * <code>HttpSession.isNew</code> returns true) do not have any
242    * application-specific state.
243    *
244    * @return the session associated with this request or null if
245    * create was false and no valid session is associated
246    * with this request.
247    */
248   public HttpSession getSession (boolean create)
249   {
250     return req.getSession(create);
251   }
252 
253   /**
254    * Gets the current valid session associated with this request,
255    * or, if necessary, creates a new session for the
256    * request.
257    *
258    * <p><b>Note</b>: to ensure the session is properly maintained,
259    * the servlet developer must call this method (at least once)
260    * before any output is written to the response.
261    *
262    * <p>Additionally, application-writers need to be aware that newly
263    * created sessions (that is, sessions for which
264    * <code>HttpSession.isNew</code> returns true) do not have any
265    * application-specific state.
266    *
267    * @return the session associated with this request.
268    */
269   public HttpSession getSession()
270   {
271     HttpSession session = getSession(false);
272     if (session == null)
273     {
274       session = getSession(true);
275     }
276     return session;
277 
278     /* new return req.getSession(); */
279   }
280 
281    
282   /**
283    * Gets the session id specified with this request.  This may
284    * differ from the actual session id.  For example, if the request
285    * specified an id for an invalid session, then this will get a new
286    * session with a new id.
287    *
288    * @return the session id specified by this request, or null if the
289    * request did not specify a session id
290    * 
291    * @see #isRequestedSessionIdValid */
292   public String getRequestedSessionId ()
293   {
294     return req.getRequestedSessionId();
295   }
296 
297   /**
298    * Checks whether this request is associated with a session that
299    * is valid in the current session context.  If it is not valid,
300    * the requested session will never be returned from the
301    * <code>getSession</code> method.
302    * 
303    * @return true if this request is assocated with a session that is
304    * valid in the current session context.
305    *
306    * @see #getRequestedSessionId
307    * @see javax.servlet.http.HttpSessionContext
308    * @see #getSession
309    */
310   public boolean isRequestedSessionIdValid ()
311   {
312     return req.isRequestedSessionIdValid();
313   }
314 
315   /**
316    * Checks whether the session id specified by this request came in
317    * as a cookie.  (The requested session may not be one returned by
318    * the <code>getSession</code> method.)
319    * 
320    * @return true if the session id specified by this request came in
321    * as a cookie; false otherwise
322    *
323    * @see #getSession
324    */
325   public boolean isRequestedSessionIdFromCookie ()
326   {
327     return req.isRequestedSessionIdFromCookie ();
328   }
329 
330   /**
331    * Checks whether the session id specified by this request came in
332    * as part of the URL.  (The requested session may not be the one
333    * returned by the <code>getSession</code> method.)
334    * 
335    * @return true if the session id specified by the request for this
336    * session came in as part of the URL; false otherwise
337    *
338    * @see #getSession
339    */
340   public boolean isRequestedSessionIdFromUrl ()
341   {
342     return req.isRequestedSessionIdFromUrl();
343   }
344 
345   /**
346    * Checks whether the session id specified by this request came in
347    * as part of the URL.  (The requested session may not be the one
348    * returned by the <code>getSession</code> method.)
349    * 
350    * @return true if the session id specified by the request for this
351    * session came in as part of the URL; false otherwise
352    *
353    * @see #getSession
354    */
355   public boolean isRequestedSessionIdFromURL ()
356   {
357     /* new return req.isRequestedSessionIdFromURL(); */
358     return req.isRequestedSessionIdFromUrl();
359   }
360 
361   /**
362    * Returns the size of the request entity data, or -1 if not known.
363    * Same as the CGI variable CONTENT_LENGTH.
364    */
365   public int getContentLength()
366   {
367     return req.getContentLength();
368   }
369 
370   /**
371    * Returns the Internet Media Type of the request entity data, or
372    * null if not known. Same as the CGI variable CONTENT_TYPE.
373    */
374   public String getContentType()
375   {
376     return req.getContentType();
377   }
378 
379   /**
380    * Returns the protocol and version of the request as a string of
381    * the form <code>&lt;protocol&gt;/&lt;major version&gt;.&lt;minor
382    * version&gt</code>.  Same as the CGI variable SERVER_PROTOCOL.
383    */
384   public String getProtocol()
385   {
386     return req.getProtocol();
387   }
388 
389   /**
390    * Returns the scheme of the URL used in this request, for example
391    * "http", "https", or "ftp".  Different schemes have different
392    * rules for constructing URLs, as noted in RFC 1738.  The URL used
393    * to create a request may be reconstructed using this scheme, the
394    * server name and port, and additional information such as URIs.
395    */
396   public String getScheme()
397   {
398     return req.getScheme();
399   }
400 
401   /**
402    * Returns the host name of the server that received the request.
403    * Same as the CGI variable SERVER_NAME.
404    */
405   public String getServerName()
406   {
407     return req.getServerName();
408   }
409 
410   /**
411    * Returns the port number on which this request was received.
412    * Same as the CGI variable SERVER_PORT.
413    */
414   public int getServerPort()
415   {
416     return req.getServerPort();
417   }
418 
419   /**
420    * This method places an attribute into the request for later
421    * use by other objects which will have access to this request
422    * ojbect such as nested servlets.
423    */
424 
425   public void setAttribute(String name, Object object)
426   {
427     /* new req.setAttribute(name, object); */
428   }
429 
430   /**
431    * Returns the IP address of the agent that sent the request.
432    * Same as the CGI variable REMOTE_ADDR.
433    */
434   public String getRemoteAddr()
435   {
436     return req.getRemoteAddr();
437   }
438 
439   /**
440    * Returns the fully qualified host name of the agent that sent the
441    * request. Same as the CGI variable REMOTE_HOST.
442    */
443   public String getRemoteHost()
444   {
445     return req.getRemoteHost();
446   }
447 
448   /**
449    * Applies alias rules to the specified virtual path and returns
450    * the corresponding real path, or null if the translation can not
451    * be performed for any reason.  For example, an HTTP servlet would
452    * resolve the path using the virtual docroot, if virtual hosting
453    * is enabled, and with the default docroot otherwise.  Calling
454    * this method with the string "/" as an argument returns the
455    * document root.
456    *
457    * @param path the virtual path to be translated to a real path
458    */
459   public String getRealPath(String path)
460   {
461     return req.getRealPath(path);
462   }
463 
464   /**
465    * Returns an input stream for reading binary data in the request body.
466    *
467    * @see getReader
468    * @exception IllegalStateException if getReader has been
469    *  called on this same request.
470    * @exception IOException on other I/O related errors.
471    */
472   public ServletInputStream getInputStream() throws IOException
473   {
474     return req.getInputStream();
475   }  
476 
477   /**
478    * Returns a string containing the lone value of the specified
479    * parameter, or null if the parameter does not exist. For example,
480    * in an HTTP servlet this method would return the value of the
481    * specified query string parameter. Servlet writers should use
482    * this method only when they are sure that there is only one value
483    * for the parameter.  If the parameter has (or could have)
484    * multiple values, servlet writers should use
485    * getParameterValues. If a multiple valued parameter name is
486    * passed as an argument, the return value is implementation
487    * dependent.
488    *
489    * @see #getParameterValues
490    *
491    * @param name the name of the parameter whose value is required.
492    */
493   public String getParameter(String name)
494   {
495     return req.getParameter(name);
496   }
497 
498   /**
499    * Returns the values of the specified parameter for the request as
500    * an array of strings, or null if the named parameter does not
501    * exist. For example, in an HTTP servlet this method would return
502    * the values of the specified query string or posted form as an
503    * array of strings.
504    *
505    * @param name the name of the parameter whose value is required.
506    * @see javax.servlet.ServletRequest#getParameter
507    */
508   public String[] getParameterValues(String name)
509   {
510     return req.getParameterValues(name);
511   }
512 
513   /**
514    * Returns the parameter names for this request as an enumeration
515    * of strings, or an empty enumeration if there are no parameters
516    * or the input stream is empty.  The input stream would be empty
517    * if all the data had been read from the stream returned by the
518    * method getInputStream.
519    */
520   public Enumeration getParameterNames()
521   {
522     return req.getParameterNames();
523   }
524 
525   /**
526    * Returns the value of the named attribute of the request, or
527    * null if the attribute does not exist.  This method allows
528    * access to request information not already provided by the other
529    * methods in this interface.  Attribute names should follow the
530    * same convention as package names. 
531    * The following predefined attributes are provided.
532    *
533    * <TABLE BORDER>
534    * <tr>
535    *  <th>Attribute Name</th>
536    *  <th>Attribute Type</th>
537    *  <th>Description</th>
538    *  </tr>
539    *
540    * <tr>
541    *  <td VALIGN=TOP>javax.net.ssl.cipher_suite</td>
542    *  <td VALIGN=TOP>string</td>
543    *  <td>The string name of the SSL cipher suite in use, if the
544    *    request was made using SSL</td>
545    *  </tr>
546    *
547    * <tr>
548    *  <td VALIGN=TOP>javax.net.ssl.peer_certificates</td>
549    *  <td VALIGN=TOP>array of javax.security.cert.X509Certificate</td>
550    *  <td>The chain of X.509 certificates which authenticates the client.
551    *    This is only available when SSL is used with client
552    *    authentication is used.</td>
553    *  </tr>
554    *
555    * <tr>
556    *  <td VALIGN=TOP>javax.net.ssl.session</td>
557    *  <td VALIGN=TOP>javax.net.ssl.SSLSession</td>
558    *  <td>An SSL session object, if the request was made using SSL.</td>
559    *  </tr>
560    *
561    * </TABLE>
562    *
563    * <BR>
564    * <P>The package (and hence attribute) names beginning with java.*,
565    * and javax.* are reserved for use by Javasoft. Similarly, com.sun.*
566    * is reserved for use by Sun Microsystems.
567    *
568    * @param name the name of the attribute whose value is required
569    */
570   public Object getAttribute(String name)
571   {
572     return req.getAttribute(name);
573   }
574 
575   /**
576    * Returns an enumeration of all the attribute names contained
577    * in the request.
578    */
579   public Enumeration getAttributeNames()
580   {
581     /* new return req.getAttributeNames(); */
582     return null;
583   }
584 
585   /**
586    * Returns a buffered reader for reading text in the request body.
587    * This translates character set encodings as appropriate. 
588    *
589    * @see getInputStream
590    *
591    * @exception UnsupportedEncodingException if the character set encoding
592    *  is unsupported, so the text can't be correctly decoded.
593    * @exception IllegalStateException if getInputStream has been
594    *  called on this same request.
595    * @exception IOException on other I/O related errors.
596    */
597   public BufferedReader getReader () throws IOException
598   {
599     return req.getReader();
600   }
601 
602   /**
603    * Returns the character set encoding for the input of this request.
604    */
605   public String getCharacterEncoding ()
606   {
607     return req.getCharacterEncoding();
608   }
609 }