org.apache.awf.web.http
Class HttpRequestImpl

java.lang.Object
  extended by org.apache.awf.web.http.HttpRequestImpl
All Implemented Interfaces:
HttpRequest
Direct Known Subclasses:
MalFormedHttpRequest

public class HttpRequestImpl
extends Object
implements HttpRequest


Field Summary
static Pattern COOKIE_SEPARATOR_PATTERN
          Regex to split cookie header following RFC6265 Section 5.4
static Pattern KEY_VALUE_PATTERN
          Regex to parse out key/value pairs
static Pattern PARAM_STRING_PATTERN
          Regex to parse out parameters from query string
static Pattern QUERY_STRING_PATTERN
          Regex to parse out QueryString from HttpRequest
static Pattern REQUEST_LINE_PATTERN
          Regex to parse HttpRequest Request Line
 
Constructor Summary
HttpRequestImpl()
           
HttpRequestImpl(String requestLine, Map<String,String> headers)
          Creates a new HttpRequest
 
Method Summary
 boolean expectContinue()
          Check if the request expect a response with 100 Continue header
 String getBody()
          The body of this request
protected  DynamicByteBuffer getBodyBuffer()
           
 int getContentLength()
          compute contentLength with header content-length when needed.
protected  HttpParsingContext getContext()
           
 String getCookie(String name)
          Returns a given cookie.
 Map<String,String> getCookies()
          Returns a map with all cookies contained in the request.
 String getHeader(String name)
          Get the value of a given HTTP header.
 Map<String,String> getHeaders()
          Get the read-only header of this request.
 HttpVerb getMethod()
          The method (POST,GET ..) used for this request.
 String getParameter(String name)
          Returns the value of a request parameter as a String, or null if the parameter does not exist.
 Map<String,Collection<String>> getParameters()
          Returns a map of all parameters where each key is a parameter name, linked value is a Collection of String containing all known values for the parameter.
 Collection<String> getParameterValues(String name)
          Returns a collection of all values associated with the provided parameter.
 InetAddress getRemoteHost()
          The address of the client which issued this request.
 int getRemotePort()
          The TCP port of the client which issued this request.
 String getRequestedPath()
          The path of this request Ex : http://www.w3.org/pub/WWW/TheProject.html
 String getRequestLine()
          Get the HTTP request line for the request.
 InetAddress getServerHost()
          The address of the server which received this request.
 int getServerPort()
          The TCP port of the server which received this request.
 String getVersion()
          The version of the HTTP protocol.
protected  void initKeepAlive()
           
protected  boolean isFinished()
           
 boolean isKeepAlive()
          Does keep-alive was requested.
protected  void pushToHeaders(String name, String value)
          Append the given value to the specified header.
protected  void setMethod(HttpVerb method)
           
protected  void setRemoteHost(InetAddress host)
           
protected  void setRemotePort(int port)
           
protected  void setServerHost(InetAddress host)
           
protected  void setServerPort(int port)
           
protected  void setURI(String uri)
          Sets the requestedPath and parse parameters using the received complete URI
protected  void setVersion(String version)
           
 String toString()
          TODO SLM This should output the real request and use a StringBuilder
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REQUEST_LINE_PATTERN

public static final Pattern REQUEST_LINE_PATTERN
Regex to parse HttpRequest Request Line


QUERY_STRING_PATTERN

public static final Pattern QUERY_STRING_PATTERN
Regex to parse out QueryString from HttpRequest


PARAM_STRING_PATTERN

public static final Pattern PARAM_STRING_PATTERN
Regex to parse out parameters from query string


KEY_VALUE_PATTERN

public static final Pattern KEY_VALUE_PATTERN
Regex to parse out key/value pairs


COOKIE_SEPARATOR_PATTERN

public static final Pattern COOKIE_SEPARATOR_PATTERN
Regex to split cookie header following RFC6265 Section 5.4

Constructor Detail

HttpRequestImpl

public HttpRequestImpl()

HttpRequestImpl

public HttpRequestImpl(String requestLine,
                       Map<String,String> headers)
Creates a new HttpRequest

Parameters:
requestLine - The Http request text line
headers - The Http request headers
Method Detail

getRequestLine

public String getRequestLine()
Description copied from interface: HttpRequest
Get the HTTP request line for the request.

Ex :

 GET http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1
 

Specified by:
getRequestLine in interface HttpRequest
Returns:
the current request line.

getRequestedPath

public String getRequestedPath()
Description copied from interface: HttpRequest
The path of this request

Ex :

 http://www.w3.org/pub/WWW/TheProject.html
 

Specified by:
getRequestedPath in interface HttpRequest
Returns:
the path requested

getVersion

public String getVersion()
Description copied from interface: HttpRequest
The version of the HTTP protocol.

Can be HTTP/1.0 or HTTP/1.1.

Specified by:
getVersion in interface HttpRequest
Returns:
the HTTP version

getHeaders

public Map<String,String> getHeaders()
Description copied from interface: HttpRequest
Get the read-only header of this request.

Specified by:
getHeaders in interface HttpRequest
Returns:
the header.
See Also:
HttpRequest.getHeader(String)

getHeader

public String getHeader(String name)
Description copied from interface: HttpRequest
Get the value of a given HTTP header.

Specified by:
getHeader in interface HttpRequest
Parameters:
name - the name of the requested header
Returns:
the value or null if the header is not found.
See Also:
HttpRequest.getHeaders()

getMethod

public HttpVerb getMethod()
Description copied from interface: HttpRequest
The method (POST,GET ..) used for this request.

Specified by:
getMethod in interface HttpRequest
Returns:
the method
See Also:
HttpVerb

getParameter

public String getParameter(String name)
Returns the value of a request parameter as a String, or null if the parameter does not exist. You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, use getParameterValues(java.lang.String). If you use this method with a multi-valued parameter, the value returned is equal to the first value in the array returned by getParameterValues.

Specified by:
getParameter in interface HttpRequest

getParameters

public Map<String,Collection<String>> getParameters()
Description copied from interface: HttpRequest
Returns a map of all parameters where each key is a parameter name, linked value is a Collection of String containing all known values for the parameter. When the parameter has no value, the collection will be empty.

Specified by:
getParameters in interface HttpRequest
Returns:
all the request parameters

getBody

public String getBody()
Description copied from interface: HttpRequest
The body of this request

Specified by:
getBody in interface HttpRequest
Returns:
the body as a String

getRemoteHost

public InetAddress getRemoteHost()
Description copied from interface: HttpRequest
The address of the client which issued this request.

Specified by:
getRemoteHost in interface HttpRequest
Returns:
the address

getServerHost

public InetAddress getServerHost()
Description copied from interface: HttpRequest
The address of the server which received this request.

Specified by:
getServerHost in interface HttpRequest
Returns:
an InetAddress representing the server address.

getRemotePort

public int getRemotePort()
Description copied from interface: HttpRequest
The TCP port of the client which issued this request.

Specified by:
getRemotePort in interface HttpRequest
Returns:
the remote port number.

getServerPort

public int getServerPort()
Description copied from interface: HttpRequest
The TCP port of the server which received this request.

Specified by:
getServerPort in interface HttpRequest
Returns:
the server port number.

setRemoteHost

protected void setRemoteHost(InetAddress host)

setServerHost

protected void setServerHost(InetAddress host)

setRemotePort

protected void setRemotePort(int port)

setServerPort

protected void setServerPort(int port)

getCookies

public Map<String,String> getCookies()
Returns a map with all cookies contained in the request. Cookies are represented as strings, and are parsed at the first invocation of this method

Specified by:
getCookies in interface HttpRequest
Returns:
a map containing all cookies of request

getCookie

public String getCookie(String name)
Returns a given cookie. Cookies are represented as strings, and are parsed at the first invocation of this method

Specified by:
getCookie in interface HttpRequest
Parameters:
name - the name of cookie
Returns:
the corresponding cookie, or null if the cookie does not exist

getParameterValues

public Collection<String> getParameterValues(String name)
Returns a collection of all values associated with the provided parameter. If no values are found an empty collection is returned.

Specified by:
getParameterValues in interface HttpRequest

isKeepAlive

public boolean isKeepAlive()
Description copied from interface: HttpRequest
Does keep-alive was requested.

Specified by:
isKeepAlive in interface HttpRequest
Returns:
true if keep-alive requested
See Also:
HTTP/1.1 persistent connections

toString

public String toString()
TODO SLM This should output the real request and use a StringBuilder

Overrides:
toString in class Object
Returns:

initKeepAlive

protected void initKeepAlive()

getContext

protected HttpParsingContext getContext()

setMethod

protected void setMethod(HttpVerb method)

setURI

protected void setURI(String uri)
Sets the requestedPath and parse parameters using the received complete URI

Parameters:
uri -

setVersion

protected void setVersion(String version)

pushToHeaders

protected void pushToHeaders(String name,
                             String value)
Append the given value to the specified header. If the header does not exist it will be added to the header map.


getContentLength

public int getContentLength()
compute contentLength with header content-length when needed. Please notice that it will also allocate the body buffer to the appropriate size.

Returns:
actual content length or 0 if not specified

getBodyBuffer

protected DynamicByteBuffer getBodyBuffer()

isFinished

protected boolean isFinished()

expectContinue

public boolean expectContinue()
Description copied from interface: HttpRequest
Check if the request expect a response with 100 Continue header

Specified by:
expectContinue in interface HttpRequest
Returns:


Copyright © 2012. All Rights Reserved.