de.unkrig.commons.net.http
Class HttpRequest

java.lang.Object
  extended by de.unkrig.commons.net.http.HttpMessage
      extended by de.unkrig.commons.net.http.HttpRequest

public class HttpRequest
extends HttpMessage

Representation of an HTTP request.


Nested Class Summary
static class HttpRequest.Method
          Representation of the various HTTP methods.
 
Nested classes/interfaces inherited from class de.unkrig.commons.net.http.HttpMessage
HttpMessage.Body
 
Field Summary
 
Fields inherited from class de.unkrig.commons.net.http.HttpMessage
EMPTY_BODY, NO_BODY
 
Constructor Summary
HttpRequest(HttpRequest.Method method, java.net.URI uri, java.lang.String httpVersion)
           
HttpRequest(HttpRequest.Method method, java.net.URI uri, java.lang.String httpVersion, java.io.InputStream in)
           
 
Method Summary
 void addParameter(java.lang.String name, java.lang.String value)
          Adds another parameter.
 void addParameter(java.lang.String name, java.lang.String[] values)
          Adds a multi-value parameter.
 java.lang.String getHttpVersion()
           
 HttpRequest.Method getMethod()
           
 java.lang.String[] getParameter(java.lang.String name)
           
 java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>> getParameterList()
           
 java.net.URI getUri()
           
static HttpRequest read(java.io.InputStream in)
          Parses and returns one HTTP request from the given InputStream.
static void read(java.nio.channels.ReadableByteChannel in, Multiplexer multiplexer, ConsumerWhichThrows<HttpRequest,java.io.IOException> requestConsumer)
          Reads one HTTP request from in through the multiplexer and passes it to the requestConsumer.
 void setHttpVersion(java.lang.String httpVersion)
          Changes the HTTP version of this request.
 void setMethod(HttpRequest.Method method)
          Changes the HTTP method of this request.
 void setParameter(java.lang.String name, java.lang.String value)
          Removes all parameters with the given name and adds another parameter.
 void setParameter(java.lang.String name, java.lang.String[] values)
          Removes all parameters with the given name and adds another multi-value parameter.
 void setParameterList(java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>> parameters)
          Changes this HTTP request's parameters.
 void setUri(java.net.URI uri)
          Changes the URI of this HTTP request.
 void write(java.io.OutputStream out)
          Writes this HTTP request to the given OutputStream.
 
Methods inherited from class de.unkrig.commons.net.http.HttpMessage
addHeader, addHeader, addHeader, addHeader, body, body, body, body, getCharset, getDateHeader, getHeader, getHeaders, getHeaders, getIntHeader, getLongHeader, readBody, readHeaders, readLine, readLine, removeBody, removeHeader, setBody, setHeader, setHeader, setHeader, setHeader, writeHeadersAndBody
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpRequest

public HttpRequest(HttpRequest.Method method,
                   java.net.URI uri,
                   java.lang.String httpVersion,
                   java.io.InputStream in)
            throws java.io.IOException
Throws:
java.io.IOException

HttpRequest

public HttpRequest(HttpRequest.Method method,
                   java.net.URI uri,
                   java.lang.String httpVersion)
Method Detail

read

public static HttpRequest read(java.io.InputStream in)
                        throws java.io.IOException,
                               InvalidHttpMessageException
Parses and returns one HTTP request from the given InputStream.

Throws:
java.io.IOException
InvalidHttpMessageException

getMethod

public HttpRequest.Method getMethod()
Returns:
The HTTP request's HttpRequest.Method

getHttpVersion

public java.lang.String getHttpVersion()
Returns:
This HTTP request's HTTP version, as given in the request line

getUri

public java.net.URI getUri()
Returns:
The URI of this HTTP request

setUri

public final void setUri(java.net.URI uri)
Changes the URI of this HTTP request.


getParameterList

public java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>> getParameterList()
                                                                                        throws java.io.IOException
Returns:
The parameters of this request, in order, as they exist in the body (POST, PUT) or in the query string (all other HTTP methods)
Throws:
java.io.IOException

setParameterList

public void setParameterList(java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>> parameters)
Changes this HTTP request's parameters.


getParameter

@Nullable
public java.lang.String[] getParameter(java.lang.String name)
                                throws java.io.IOException
Returns:
The values of all parameters with the given name
Throws:
java.io.IOException

addParameter

public void addParameter(java.lang.String name,
                         java.lang.String value)
                  throws java.io.IOException
Adds another parameter.

Throws:
java.io.IOException

addParameter

public void addParameter(java.lang.String name,
                         java.lang.String[] values)
                  throws java.io.IOException
Adds a multi-value parameter.

Throws:
java.io.IOException

setParameter

public void setParameter(java.lang.String name,
                         java.lang.String value)
                  throws java.io.IOException
Removes all parameters with the given name and adds another parameter.

Throws:
java.io.IOException

setParameter

public void setParameter(java.lang.String name,
                         java.lang.String[] values)
                  throws java.io.IOException
Removes all parameters with the given name and adds another multi-value parameter.

Throws:
java.io.IOException

setMethod

public void setMethod(HttpRequest.Method method)
Changes the HTTP method of this request.


setHttpVersion

public void setHttpVersion(java.lang.String httpVersion)
Changes the HTTP version of this request.


write

public void write(java.io.OutputStream out)
           throws java.io.IOException
Writes this HTTP request to the given OutputStream.

Throws:
java.io.IOException

read

public static void read(java.nio.channels.ReadableByteChannel in,
                        Multiplexer multiplexer,
                        ConsumerWhichThrows<HttpRequest,java.io.IOException> requestConsumer)
                 throws java.io.IOException
Reads one HTTP request from in through the multiplexer and passes it to the requestConsumer.

Throws:
java.io.IOException