org.faceless.util
Class HttpRequestReader

java.lang.Object
  extended by org.faceless.util.HttpRequestReader

public class HttpRequestReader
extends Object

Represents an incoming HTTP Request, in a similar way to the javax.servlet.http.HttpServletRequest class. Currently just a thin wrapper on top of that class.

See Also:
HttpRequestWriter

Constructor Summary
HttpRequestReader(javax.servlet.http.HttpServletRequest request)
           
 
Method Summary
 String getContentType()
          Return the value of the Content-Type header
 javax.servlet.http.Cookie getCookie(String name)
          Returns a cookie with the specified name.
 javax.servlet.http.Cookie[] getCookies()
          Returns an array containing all of the Cookie objects the client sent with this request.
 long getDateHeader(String key)
           Returns the value of the specified response header as a long value that represents a Date object.
 String getHeader(String key)
          Returns the value of the specified response header as a String.
 Iterator getHeaderNames()
          Returns an iterator of all the header names this response contains.
 Iterator getHeaders(String key)
           Returns all the values of the specified response header as an Iterator of String objects.
 InputStream getInputStream()
          Returns the body of the response as binary data using an InputStream.
 int getIntHeader(String key)
           Returns the value of the specified response header as an int.
 String getMethod()
          Get the status message returned from the response Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
 String getPathInfo()
          Returns any extra path information associated with the URL the client sent when it made this request.
 String getQueryString()
          Returns the query string that is contained in the request URL after the path.
 BufferedReader getReader()
          Returns the body of the response as character data using a BufferedReader.
 String getRemoteUser()
          Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.
 javax.servlet.http.HttpServletRequest getUnderlyingRequest()
          Returns the underlying HttpServletRequest this object is based on, or null if the request is not based on an HttpServletRequest
 String getURI()
          Get the URI that the request came for.
 String getURL()
          Get the URL that the request came for.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpRequestReader

public HttpRequestReader(javax.servlet.http.HttpServletRequest request)
Method Detail

getMethod

public String getMethod()
Get the status message returned from the response Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. Same as the value of the CGI variable REQUEST_METHOD

Returns:
a String specifying the name of the method with which this request was made

getURL

public String getURL()
Get the URL that the request came for.


getURI

public String getURI()
Get the URI that the request came for.


getQueryString

public String getQueryString()
Returns the query string that is contained in the request URL after the path. This method returns null if the URL does not have a query string. Same as the value of the CGI variable QUERY_STRING.

Returns:
a String containing the query string or null if the URL contains no query string

getPathInfo

public String getPathInfo()
Returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string. This method returns null if there was no extra path information. Same as the value of the CGI variable PATH_INFO.

Returns:
a String specifying extra path information that comes after the servlet path but before the query string in the request URL; or null if the URL does not have any extra path information

getCookies

public javax.servlet.http.Cookie[] getCookies()
Returns an array containing all of the Cookie objects the client sent with this request. This method returns null if no cookies were sent.

Returns:
an array of all the Cookies included with this request, or null if the request has no cookies

getCookie

public javax.servlet.http.Cookie getCookie(String name)
Returns a cookie with the specified name. If more than one cookie has this name, which one is returned is undefined. If no cookie is found with that name, returns null

Returns:
the Cookie from the request with the specified name

getRemoteUser

public String getRemoteUser()
Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated. Whether the user name is sent with each subsequent request depends on the browser and type of authentication. Same as the value of the CGI variable REMOTE_USER.

Returns:
a String specifying the login of the user making this request, or null

getHeaders

public Iterator getHeaders(String key)

Returns all the values of the specified response header as an Iterator of String objects.

Some headers, such as Accept-Language can be sent by clients as several headers each with a different value rather than sending the header as a comma separated list.

If the response did not include any headers of the specified name, this method returns an empty Iterator. The header name is case insensitive. You can use this method with any response header.

Parameters:
key - a String specifying the header name
Returns:
an Iterator containing the values of the requested header. If the response does not have any headers of that name return an empty iterator.

getHeaderNames

public Iterator getHeaderNames()
Returns an iterator of all the header names this response contains. If the response has no headers, this method returns an empty iterator.


getHeader

public String getHeader(String key)
Returns the value of the specified response header as a String. If the response did not include a header of the specified name, this method returns null. The header name is case insensitive. You can use this method with any response header.

Parameters:
key - a String specifying the name of a response header
Returns:
a String containing the value of the requested header, or null if the response does not have a header of that name

getIntHeader

public int getIntHeader(String key)
                 throws NumberFormatException

Returns the value of the specified response header as an int. If the response does not have a header of the specified name, this method returns -1. If the header cannot be converted to an integer, this method throws a NumberFormatException.

The header name is case insensitive.

Parameters:
key - a String specifying the name of a response header
Returns:
an integer expressing the value of the response header or -1 if the response doesn't have a header of this name
Throws:
NumberFormatException - if the header value can't be converted to an int

getDateHeader

public long getDateHeader(String key)

Returns the value of the specified response header as a long value that represents a Date object. Use this method with headers that contain dates, such as Last-Modified.

The date is returned as the number of milliseconds since January 1, 1970 GMT. The header name is case insensitive.

If the response did not have a header of the specified name, this method returns -1. If the header can't be converted to a date, the method throws an IllegalArgumentException.

Parameters:
key - a String specifying the name of a response header
Returns:
a long value representing the date specified in the header expressed as the number of milliseconds since January 1, 1970 GMT, or -1 if the named header was not included with the reqest
Throws:
IllegalArgumentException - if the header can't be converted to a date

getContentType

public String getContentType()
Return the value of the Content-Type header


getInputStream

public InputStream getInputStream()
                           throws IOException
Returns the body of the response as binary data using an InputStream. Either this method or getReader() may be called to read the body, but not both.

Returns:
an InputStream containing the body of the response
Throws:
IllegalStateException - if the getReader() method has already been called.
IOException

getReader

public BufferedReader getReader()
                         throws IOException
Returns the body of the response as character data using a BufferedReader. The reader translates the character data according to the character encoding used on the body. Either this method or getInputStream() may be called to read the body, but not both.

Returns:
a BufferedReader containing the body of the response
Throws:
IllegalStateException - if the getInputStream() method has already been called.
UnsupportedEncodingException - if the character encoding is not supported
IOException

getUnderlyingRequest

public javax.servlet.http.HttpServletRequest getUnderlyingRequest()
Returns the underlying HttpServletRequest this object is based on, or null if the request is not based on an HttpServletRequest



Copyright © 2001-2004 Big Faceless Organization