org.mortbay.http

Class 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.90 2005/12/21 23:14:38 gregwilkins Exp $
Author:
Greg Wilkins (gregw)
See Also:
HttpResponse

Nested Class Summary

Nested classes/interfaces inherited from class org.mortbay.http.HttpMessage

HttpMessage.HeaderWriter

Field Summary

static String
__CONNECT
Request METHODS.
static String
__DELETE
Request METHODS.
static String
__GET
Request METHODS.
static String
__HEAD
Request METHODS.
static String
__MOVE
Request METHODS.
static String
__OPTIONS
Request METHODS.
static String
__POST
Request METHODS.
static String
__PUT
Request METHODS.
static String
__TRACE
Request METHODS.
static int
__maxFormContentSize
Max size of the form content.
static int
__maxLineLength
Maximum header line length.
static StringMap
__methodCache
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, _attributes, _characterEncoding, _connection, _dotVersion, _header, _mimeType, _state, _version, _wrapper

Constructor Summary

HttpRequest()
Constructor.
HttpRequest(HttpConnection connection)
Constructor.

Method Summary

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

Methods inherited from class org.mortbay.http.HttpMessage

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

Field Details

__CONNECT

public static final String __CONNECT
Request METHODS.

__DELETE

public static final String __DELETE
Request METHODS.

__GET

public static final String __GET
Request METHODS.

__HEAD

public static final String __HEAD
Request METHODS.

__MOVE

public static final String __MOVE
Request METHODS.

__OPTIONS

public static final String __OPTIONS
Request METHODS.

__POST

public static final String __POST
Request METHODS.

__PUT

public static final String __PUT
Request METHODS.

__TRACE

public static final String __TRACE
Request METHODS.

__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 Details

HttpRequest

public HttpRequest()
Constructor.

HttpRequest

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

Method Details

destroy

public void destroy()
Destroy the request. Help the garbage collector by null everything that we can.
Overrides:
destroy in interface HttpMessage

getAcceptableTransferCodings

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

getAuthType

public String getAuthType()

getAuthUser

public String getAuthUser()

getCookies

public Cookie[] getCookies()
Extract received cookies from a header.
Returns:
Array of Cookies.

getEncodedPath

public String getEncodedPath()
Get the encoded request path.
Returns:
The path with % encoding.

getHost

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

getHttpResponse

public HttpResponse getHttpResponse()
Get the HTTP Response. Get the HTTP Response associated with this request.
Returns:
associated response

getMethod

public 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

getParameter

public String getParameter(String name)
Get a parameter value.
Parameters:
name - Parameter name
Returns:
Parameter value

getParameterNames

public Set getParameterNames()
Get the set of parameter names.
Returns:
Set of parameter names.

getParameterStringArrayMap

public Map getParameterStringArrayMap()
Returns:
Parameters as a map of String arrays

getParameterValues

public List getParameterValues(String name)
Get multi valued paramater.
Parameters:
name - Parameter name
Returns:
Parameter values

getParameters

public MultiMap getParameters()
Returns:
Map of parameters

getPath

public String getPath()
Get the request path.
Returns:
The URI path of the request.

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.

getQuery

public String getQuery()
Get the request query.
Returns:
the request query excluding the '?'

getRemoteAddr

public String getRemoteAddr()

getRemoteHost

public String getRemoteHost()

getRequestLine

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

getRequestURL

public 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

getResponse

public HttpResponse getResponse()

Deprecated. use getHttpResponse()


getRootURL

public 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"

getScheme

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

getTimeStamp

public long getTimeStamp()
Get Request TimeStamp
Returns:
The time that the request was received.

getTimeStampStr

public String getTimeStampStr()
Get Request TimeStamp
Returns:
The time that the request was received.

getURI

public URI getURI()
Get the full URI.
Returns:
the request URI (not a clone).

getUserPrincipal

public Principal getUserPrincipal()

getVersion

public String getVersion()
Get the protocol version.
Overrides:
getVersion in interface HttpMessage
Returns:
return the version.

hasUserPrincipal

public boolean hasUserPrincipal()

isConfidential

public boolean isConfidential()
Returns:
True if this request came over an confidential channel such as SSL.

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.

isIntegral

public boolean isIntegral()
Returns:
True if this request came over an integral channel such as SSL

isUserInRole

public boolean isUserInRole(String role)

readHeader

public void readHeader(LineInput in)
            throws IOException
Read the request line and header.
Parameters:
in -

setAuthType

public void setAuthType(String a)

setAuthUser

public void setAuthUser(String user)

setHandled

public void setHandled(boolean handled)
Set the handled status.
Parameters:
handled - true or false

setMethod

public void setMethod(String method)

setPath

public void setPath(String path)

setQuery

public void setQuery(String q)

setTimeStamp

public void setTimeStamp(long ts)

setUserPrincipal

public void setUserPrincipal(Principal principal)

writeHeader

public void writeHeader(Writer writer)
            throws IOException
Write the request header. Places the message in __MSG_SENDING state.
Parameters:
writer - Http output stream

writeRequestLine

public void writeRequestLine(Writer writer)
            throws IOException
Write the HTTP request line as it was received.

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