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.91 2006/11/23 08:56:52 gregwilkins Exp $

Author: Greg Wilkins (gregw)

See Also: HttpResponse

Field Summary
static String__CONNECT
Request METHODS.
static String__DELETE
Request METHODS.
static String__GET
Request METHODS.
static String__HEAD
Request METHODS.
static int__maxFormContentSize
Max size of the form content.
static int__maxLineLength
Maximum header line length.
static StringMap__methodCache
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 StringMap__versionCache
Constructor Summary
HttpRequest()
Constructor.
HttpRequest(HttpConnection connection)
Constructor.
Method Summary
voiddestroy()
Destroy the request.
ListgetAcceptableTransferCodings()
Get the acceptable transfer encodings.
StringgetAuthType()
StringgetAuthUser()
Cookie[]getCookies()
Extract received cookies from a header.
StringgetEncodedPath()
Get the encoded request path.
StringgetHost()
Get the request host.
HttpResponsegetHttpResponse()
Get the HTTP Response.
StringgetMethod()
Get the HTTP method for this request.
StringgetParameter(String name)
Get a parameter value.
SetgetParameterNames()
Get the set of parameter names.
MultiMapgetParameters()
MapgetParameterStringArrayMap()
ListgetParameterValues(String name)
Get multi valued paramater.
StringgetPath()
Get the request path.
intgetPort()
Get the request port.
StringgetQuery()
Get the request query.
StringgetRemoteAddr()
StringgetRemoteHost()
StringgetRequestLine()
Return the HTTP request line as it was received.
StringBuffergetRequestURL()
Reconstructs the URL the client used to make the request.
HttpResponsegetResponse()
StringBuffergetRootURL()
Reconstructs the URL the client used to make the request.
StringgetScheme()
Get the request Scheme.
longgetTimeStamp()
Get Request TimeStamp
StringgetTimeStampStr()
Get Request TimeStamp
URIgetURI()
Get the full URI.
PrincipalgetUserPrincipal()
StringgetVersion()
booleanhasUserPrincipal()
booleanisConfidential()
booleanisHandled()
Is the request handled.
booleanisIntegral()
booleanisUserInRole(String role)
voidreadHeader(LineInput in)
Read the request line and header.
voidsetAuthType(String a)
voidsetAuthUser(String user)
voidsetHandled(boolean handled)
Set the handled status.
voidsetMethod(String method)
voidsetPath(String path)
voidsetQuery(String q)
voidsetTimeStamp(long ts)
voidsetUserPrincipal(Principal principal)
voidwriteHeader(Writer writer)
Write the request header.
voidwriteRequestLine(Writer writer)
Write the HTTP request line as it was received.

Field Detail

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

__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

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

__versionCache

public static final StringMap __versionCache

Constructor Detail

HttpRequest

public HttpRequest()
Constructor.

HttpRequest

public HttpRequest(HttpConnection connection)
Constructor.

Parameters: connection

Method Detail

destroy

public void destroy()
Destroy the request. Help the garbage collector by null everything that we can.

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.

getParameters

public MultiMap getParameters()

Returns: Map of parameters

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

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

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)
Read the request line and header.

Parameters: in

Throws: IOException

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)
Write the request header. Places the message in __MSG_SENDING state.

Parameters: writer Http output stream

Throws: IOException IO problem

writeRequestLine

public void writeRequestLine(Writer writer)
Write the HTTP request line as it was received.
Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.