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.5 2001/10/11 01:17:44 gregwilkins Exp $
Author:
Greg Wilkins (gregw)
See Also:
HttpResponse

Field Summary
static java.lang.String __AuthType
           
static java.lang.String __AuthUser
           
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 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, __state
 
Constructor Summary
HttpRequest()
          Constructor.
HttpRequest(HttpConnection connection)
          Constructor.
 
Method Summary
 void appendRequestLine(java.lang.StringBuffer buf)
          Append the HTTP request line as it was received.
 void destroy()
          Destroy the request.
 java.lang.Object forceRemoveField(java.lang.String name)
          Force a removeField.
 java.util.List getAcceptableTransferCodings()
          Get the acceptable transfer encodings.
 java.lang.Object getAttribute(java.lang.String name)
          Get a request attribute.
 java.util.Collection getAttributeNames()
          Get Attribute names.
 Cookie[] getCookies()
          Extract received cookies from a header.
 java.lang.String getHost()
          Get the request host.
 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.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 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()
          Get the HTTP Response.
 java.lang.String getScheme()
          Get the request Scheme.
 URI getURI()
          Get the full URI.
 java.security.Principal getUserPrincipal()
           
 boolean isHandled()
          Is the request handled.
 boolean isUserInRole(java.lang.String role)
           
 void readHeader(ChunkableInputStream in)
          Read the request line and header.
 void recycle(HttpConnection connection)
          Recycle the request.
 void removeAttribute(java.lang.String name)
          Remove a request attribute.
 java.lang.Object setAttribute(java.lang.String name, java.lang.Object attribute)
          Set a request attribute.
 void setHandled(boolean handled)
          Set the handled status.
 void setHost(java.lang.String host)
          Set the request host.
 void setMethod(java.lang.String method)
          Set the HTTP method for this request.
 void setPath(java.lang.String path)
          Set the request path.
 void setPort(int port)
          Set the request port.
 void setQuery(java.lang.String query)
          Set the request query.
 void setScheme(java.lang.String scheme)
          Set the request scheme.
 void setURI(URI uri)
          Set the HTTP URI.
 void writeHeader(java.io.Writer writer)
          Write the request header.
 
Methods inherited from class org.mortbay.http.HttpMessage
acceptTrailer, addDateField, addField, addIntField, commit, commitHeader, complete, containsField, getCharacterEncoding, getDateField, getDotVersion, getField, getFieldNames, getFieldValues, getFieldValues, getHeader, getHttpConnection, getInputStream, getIntField, getMimeType, getOutputStream, getState, getTrailer, getVersion, isCommitted, isDirty, removeField, setAcceptTrailer, setCurrentTime, setDateField, setDateField, setField, setField, setIntField, setState, setVersion, 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.

__POST

public static final java.lang.String __POST
Request METHODS.

__HEAD

public static final java.lang.String __HEAD
Request METHODS.

__PUT

public static final java.lang.String __PUT
Request METHODS.

__OPTIONS

public static final java.lang.String __OPTIONS
Request METHODS.

__DELETE

public static final java.lang.String __DELETE
Request METHODS.

__TRACE

public static final java.lang.String __TRACE
Request METHODS.

__CONNECT

public static final java.lang.String __CONNECT
Request METHODS.

__MOVE

public static final java.lang.String __MOVE
Request METHODS.

__methodCache

public static final StringMap __methodCache

__versionCache

public static final StringMap __versionCache

__AuthType

public static final java.lang.String __AuthType

__AuthUser

public static final java.lang.String __AuthUser
Constructor Detail

HttpRequest

public HttpRequest()
Constructor.

HttpRequest

public HttpRequest(HttpConnection connection)
Constructor.
Parameters:
connection -  
Method Detail

getResponse

public HttpResponse getResponse()
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(ChunkableInputStream in)
                throws java.io.IOException
Read the request line and header.
Parameters:
in -  
Throws:
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.
Parameters:
out - Chunkable output stream
Throws:
java.io.IOException - IO problem

getRequestLine

public java.lang.String getRequestLine()
Return the HTTP request line as it was received.

appendRequestLine

public void appendRequestLine(java.lang.StringBuffer buf)
Append 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)
               throws java.lang.IllegalStateException
Set the HTTP method for this request.
Parameters:
method - the method
Throws:
java.lang.IllegalStateException - Request is not EDITABLE

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:
A cloned copy of the request URI

setURI

public void setURI(URI uri)
Set the HTTP URI.
Parameters:
uri - the uri
Throws:
java.lang.IllegalStateException - Request is not EDITABLE

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.)

setScheme

public void setScheme(java.lang.String scheme)
Set the request scheme. If the URI was not previously an absolute URI, the URI host and port are also set from the HTTP Host Header field.
Parameters:
scheme - The scheme
Throws:
java.lang.IllegalStateException - Request is not EDITABLE

getHost

public java.lang.String getHost()
Get the request host. The host is obtained from an absolute URI, the HTTP header field, the requests connection or the local host name.
Returns:
 

setHost

public void setHost(java.lang.String host)
             throws java.lang.IllegalStateException
Set the request host. If the current uri is absolute, then the URI is updated. The HTTP Host header field is always updated.
Parameters:
host - The host
Throws:
java.lang.IllegalStateException - Request is not EDITABLE

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.

setPort

public void setPort(int port)
             throws java.lang.IllegalStateException
Set the request port. If the current uri is absolute, then the URI is updated. The HTTP Host header field is always updated.
Parameters:
port - The port
Throws:
java.lang.IllegalStateException - Request is not EDITABLE

getPath

public java.lang.String getPath()
Get the request path.
Returns:
 

setPath

public void setPath(java.lang.String path)
Set the request path.
Parameters:
path - The path
Throws:
java.lang.IllegalStateException - Request is not EDITABLE

getQuery

public java.lang.String getQuery()
Get the request query.
Returns:
 

setQuery

public void setQuery(java.lang.String query)
Set the request query.
Parameters:
query - The query
Throws:
java.lang.IllegalStateException - Request is not EDITABLE

getRemoteAddr

public java.lang.String getRemoteAddr()

forceRemoveField

public java.lang.Object forceRemoveField(java.lang.String name)
Force a removeField. This call ignores the message state and forces a field to be removed from the request. It is required for the handling of the Connection field.
Parameters:
name - The field name
Returns:
The old value or null.

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:
 

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

getCookies

public Cookie[] getCookies()
Extract received cookies from a header.
Parameters:
buffer - Contains encoded cookies
Returns:
Array of Cookies.

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Get a request attribute.
Parameters:
name -  
Returns:
 

setAttribute

public java.lang.Object setAttribute(java.lang.String name,
                                     java.lang.Object attribute)
Set a request attribute.
Parameters:
name -  
attribute -  
Returns:
 

getAttributeNames

public java.util.Collection getAttributeNames()
Get Attribute names.
Returns:
 

removeAttribute

public void removeAttribute(java.lang.String name)
Remove a request attribute.
Parameters:
name -  
attribute -  
Returns:
 

isUserInRole

public boolean isUserInRole(java.lang.String role)

getUserPrincipal

public java.security.Principal getUserPrincipal()

recycle

public void recycle(HttpConnection connection)
Recycle the request.
Overrides:
recycle in class HttpMessage

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.