## org.mortbay.http
Class HttpRequest

    java.lang.Object
      |
      +--org.mortbay.http.HttpMessage
            |
            +--org.mortbay.http.HttpRequest

public class HttpRequest
extends HttpMessage

HTTP Request. This class manages the headers, trailers and content streams of a HTTP request. It can be used for receiving or generating requests.

This class is not synchronized. It should be explicitly synchronized if it is used by multiple threads.

Version:
  $Id: HttpRequest.java,v 1.64.2.3 2004/04/19 14:17:40 gregwilkins Exp $
Author:
  Greg Wilkins (gregw)
See Also:
  `HttpResponse`

Nested Class Summary

Nested classes inherited from class org.mortbay.http.HttpMessage
`HttpMessage.HeaderWriter`

Field Summary
`static java.lang.String` `__CONNECT` Request METHODS.
`static java.lang.String` `__DELETE` Request METHODS.
`static java.lang.String` `__GET` Request METHODS.
`static java.lang.String` `__HEAD` Request METHODS.
`static int` `__maxFormContentSize` Max size of the form content.
`static int` `__maxLineLength` Maximum header line length.
`static StringMap` `__methodCache`
`static java.lang.String` `__MOVE` Request METHODS.
`static java.lang.String` `__OPTIONS` Request METHODS.
`static java.lang.String` `__POST` Request METHODS.
`static java.lang.String` `__PUT` Request METHODS.
`static java.lang.String` `__TRACE` Request METHODS.
`static StringMap` `__versionCache`

Fields inherited from class org.mortbay.http.HttpMessage
`__HTTP_0_9, __HTTP_1_0, __HTTP_1_1, __HTTP_1_X, __MSG_BAD, __MSG_EDITABLE, __MSG_RECEIVED, __MSG_SENDING, __MSG_SENT, __SCHEME, __SSL_SCHEME, __state`

Constructor Summary
`HttpRequest()` Constructor.
`HttpRequest(HttpConnection connection)` Constructor.

Method Summary
`void` `destroy()` Destroy the request.
`java.util.List` `getAcceptableTransferCodings()` Get the acceptable transfer encodings.
`java.lang.String` `getAuthType()`
`java.lang.String` `getAuthUser()`
`Cookie[]` `getCookies()` Extract received cookies from a header.
`java.lang.String` `getEncodedPath()` Get the encoded request path.
`java.lang.String` `getHost()` Get the request host.
`HttpResponse` `getHttpResponse()` Get the HTTP Response.
`java.lang.String` `getMethod()` Get the HTTP method for this request.
`java.lang.String` `getParameter(java.lang.String name)` Get a parameter value.
`java.util.Set` `getParameterNames()` Get the set of parameter names.
`MultiMap` `getParameters()`
`java.util.Map` `getParameterStringArrayMap()`
`java.util.List` `getParameterValues(java.lang.String name)` Get multi valued paramater.
`java.lang.String` `getPath()` Get the request path.
`int` `getPort()` Get the request port.
`java.lang.String` `getQuery()` Get the request query.
`java.lang.String` `getRemoteAddr()`
`java.lang.String` `getRemoteHost()`
`java.lang.String` `getRequestLine()` Return the HTTP request line as it was received.
`java.lang.StringBuffer` `getRequestURL()` Reconstructs the URL the client used to make the request.
`HttpResponse` `getResponse()` Deprecated. use getHttpResponse()
`java.lang.StringBuffer` `getRootURL()` Reconstructs the URL the client used to make the request.
`java.lang.String` `getScheme()` Get the request Scheme.
`long` `getTimeStamp()` Get Request TimeStamp
`java.lang.String` `getTimeStampStr()` Get Request TimeStamp
`URI` `getURI()` Get the full URI.
`UserPrincipal` `getUserPrincipal()`
`java.lang.String` `getVersion()` Get the protocol version.
`boolean` `isConfidential()`
`boolean` `isHandled()` Is the request handled.
`boolean` `isIntegral()`
`boolean` `isUserInRole(java.lang.String role)`
`void` `readHeader(LineInput in)` Read the request line and header.
`void` `setAuthType(java.lang.String a)`
`void` `setAuthUser(java.lang.String user)`
`void` `setHandled(boolean handled)` Set the handled status.
`void` `setMethod(java.lang.String method)`
`void` `setPath(java.lang.String path)`
`void` `setQuery(java.lang.String q)`
`void` `setTimeStamp(long ts)`
`void` `setUserPrincipal(UserPrincipal principal)`
`void` `writeHeader(java.io.Writer writer)` Write the request header.
`void` `writeRequestLine(java.io.Writer writer)` Write the HTTP request line as it was received.

Methods inherited from class org.mortbay.http.HttpMessage

`acceptTrailer, addDateField, addDateField, addField, addIntField, containsField, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getDateField, getDotVersion, getField, getFieldNames, getFieldValues, getFieldValues, getHeader, getHttpConnection, getInputStream, getIntField, getMimeType, getOutputStream, getState, getTrailer, getWrapper, isCommitted, isDirty, removeAttribute, removeField, setAcceptTrailer, setAttribute, setCharacterEncoding, setContentLength, setContentType, setDateField, setDateField, setField, setField, setIntField, setState, setVersion, setWrapper, toString`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### __GET

    public static final java.lang.String __GET

  Request METHODS.

  See Also:
    Constant Field Values

### __POST

    public static final java.lang.String __POST

  Request METHODS.

  See Also:
    Constant Field Values

### __HEAD

    public static final java.lang.String __HEAD

  Request METHODS.

  See Also:
    Constant Field Values

### __PUT

    public static final java.lang.String __PUT

  Request METHODS.

  See Also:
    Constant Field Values

### __OPTIONS

    public static final java.lang.String __OPTIONS

  Request METHODS.

  See Also:
    Constant Field Values

### __DELETE

    public static final java.lang.String __DELETE

  Request METHODS.

  See Also:
    Constant Field Values

### __TRACE

    public static final java.lang.String __TRACE

  Request METHODS.

  See Also:
    Constant Field Values

### __CONNECT

    public static final java.lang.String __CONNECT

  Request METHODS.

  See Also:
    Constant Field Values

### __MOVE

    public static final java.lang.String __MOVE

  Request METHODS.

  See Also:
    Constant Field Values

### __maxFormContentSize

    public static int __maxFormContentSize

  Max size of the form content. Limits the size of the data a client can push at the server. Set via the org.mortbay.http.HttpRequest.maxContentSize system property.

### __maxLineLength

    public static int __maxLineLength

  Maximum header line length.

### __methodCache

    public static final StringMap __methodCache

### __versionCache

    public static final StringMap __versionCache

Constructor Detail

### HttpRequest

    public HttpRequest()

  Constructor.

### HttpRequest

    public HttpRequest(HttpConnection connection)

  Constructor.

Parameters:
  `connection` -

Method Detail

### getTimeStampStr

    public java.lang.String getTimeStampStr()

  Get Request TimeStamp

  Returns:
    The time that the request was received.

### getTimeStamp

    public long getTimeStamp()

  Get Request TimeStamp

  Returns:
    The time that the request was received.

### setTimeStamp

    public void setTimeStamp(long ts)

### getResponse

    public HttpResponse getResponse()

  Deprecated. use getHttpResponse()

### getHttpResponse

    public HttpResponse getHttpResponse()

  Get the HTTP Response. Get the HTTP Response associated with this request.

  Returns:
    associated response

### isHandled

    public boolean isHandled()

  Is the request handled.

  Returns:
    True if the request has been set to handled or the associated response is not editable.

### setHandled

    public void setHandled(boolean handled)

  Set the handled status.

  Parameters:
    `handled` - true or false

### readHeader

    public void readHeader(LineInput in)
                    throws java.io.IOException

  Read the request line and header.

  Parameters:
    `in` -
  Throws:
    `java.io.IOException`

### writeRequestLine

    public void writeRequestLine(java.io.Writer writer)
                          throws java.io.IOException

  Write the HTTP request line as it was received.

    `java.io.IOException`

### writeHeader

    public void writeHeader(java.io.Writer writer)
                     throws java.io.IOException

  Write the request header. Places the message in __MSG_SENDING state.

  Overrides:
    `writeHeader` in class `HttpMessage`
  Parameters:
    `writer` - Http output stream
  Throws:
    `java.io.IOException` - IO problem

### getRequestLine

    public java.lang.String getRequestLine()

  Return the HTTP request line as it was received.

### getMethod

    public java.lang.String getMethod()

  Get the HTTP method for this request. Returns the method with which the request was made. The returned value can be "GET", "HEAD", "POST", or an extension method. Same as the CGI variable REQUEST_METHOD.

  Returns:
    The method

### setMethod

    public void setMethod(java.lang.String method)

### getVersion

    public java.lang.String getVersion()

  Description copied from class: `HttpMessage`
  Get the protocol version.

  Overrides:
    `getVersion` in class `HttpMessage`
  Returns:
    return the version.

### getRootURL

    public java.lang.StringBuffer getRootURL()

  Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and, but it does not include a path.

  Because this method returns a `StringBuffer`, not a string, you can modify the URL easily, for example, to append path and query parameters. This method is useful for creating redirect messages and for reporting errors.

  Returns:
    "scheme://host:port"

### getRequestURL

    public java.lang.StringBuffer getRequestURL()

  Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.

  Because this method returns a `StringBuffer`, not a string, you can modify the URL easily, for example, to append query parameters.

  This method is useful for creating redirect messages and for reporting errors.

  Returns:
    a `StringBuffer` object containing the reconstructed URL

### getURI

    public URI getURI()

  Get the full URI.

  Returns:
    the request URI (not a clone).

### getScheme

    public java.lang.String getScheme()

  Get the request Scheme. The scheme is obtained from an absolute URI. If the URI in the request is not absolute, then the connections default scheme is returned. If there is no connection "http" is returned.

  Returns:
    The request scheme (eg. "http", "https", etc.)

### isIntegral

    public boolean isIntegral()

  Returns:
    True if this request came over an integral channel such as SSL

### isConfidential

    public boolean isConfidential()

  Returns:
    True if this request came over an confidential channel such as SSL.

### getHost

    public java.lang.String getHost()

  Get the request host.

  Returns:
    The host name obtained from an absolute URI, the HTTP header field, the requests connection or the local host name.

### getPort

    public int getPort()

  Get the request port. The port is obtained either from an absolute URI, the HTTP Host header field, the connection or the default.

  Returns:
    The port. 0 should be interpreted as the default port.

### getPath

    public java.lang.String getPath()

  Get the request path.

  Returns:
    The URI path of the request.

### setPath

    public void setPath(java.lang.String path)

### getEncodedPath

    public java.lang.String getEncodedPath()

  Get the encoded request path.

  Returns:
    The path with % encoding.

### getQuery

    public java.lang.String getQuery()

  Get the request query.

  Returns:
    the request query excluding the '?'

### setQuery

    public void setQuery(java.lang.String q)

### getRemoteAddr

    public java.lang.String getRemoteAddr()

### getRemoteHost

    public java.lang.String getRemoteHost()

### getAcceptableTransferCodings

    public java.util.List getAcceptableTransferCodings()

  Get the acceptable transfer encodings. The TE field is used to construct a list of acceptable extension transfer codings in quality order. An empty list implies that only "chunked" is acceptable. A null list implies that no transfer coding can be applied. If the "trailer" coding is found in the TE field, then message trailers are enabled in any linked response.

  Returns:
    List of codings.

### getParameters

    public MultiMap getParameters()

  Returns:
    Map of parameters

### getParameterNames

    public java.util.Set getParameterNames()

  Get the set of parameter names.

  Returns:
    Set of parameter names.

### getParameter

    public java.lang.String getParameter(java.lang.String name)

  Get a parameter value.

  Parameters:
    `name` - Parameter name
  Returns:
    Parameter value

### getParameterValues

    public java.util.List getParameterValues(java.lang.String name)

  Get multi valued paramater.

  Parameters:
    `name` - Parameter name
  Returns:
    Parameter values

### getParameterStringArrayMap

    public java.util.Map getParameterStringArrayMap()

  Returns:
    Parameters as a map of String arrays

### getCookies

    public Cookie[] getCookies()

  Extract received cookies from a header.

  Returns:
    Array of Cookies.

### isUserInRole

    public boolean isUserInRole(java.lang.String role)

### getAuthType

    public java.lang.String getAuthType()

### setAuthType

    public void setAuthType(java.lang.String a)

### getAuthUser

    public java.lang.String getAuthUser()

### setAuthUser

    public void setAuthUser(java.lang.String user)

### getUserPrincipal

    public UserPrincipal getUserPrincipal()

### setUserPrincipal

    public void setUserPrincipal(UserPrincipal principal)

### destroy

    public void destroy()

  Destroy the request. Help the garbage collector by null everything that we can.

  Overrides:
    `destroy` in class `HttpMessage`

Copyright © 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.