mmhttp.protocol
Class Request

java.lang.Object
  extended by mmhttp.protocol.Request

public class Request
extends java.lang.Object

This class is one of the primary work horses of MM HTTP. It parses incoming HTTP Requests and provided accessors to the data. Although compliant to the HTTP 1.1 protocol, it is by no means complete. For example, only the GET and POST methods are supported. But is does support multipart content and file uploads.


Field Summary
protected  java.lang.String authorizationPassword
           
protected  java.lang.String authorizationUsername
           
protected  java.lang.String entityBody
           
protected  java.util.HashMap<java.lang.String,java.lang.String> headers
           
protected  mmsocketserver.StreamReader input
           
protected  java.util.HashMap<java.lang.String,java.lang.Object> inputs
           
protected  java.lang.String queryString
           
protected  java.lang.String requestLine
           
protected  java.lang.String requestURI
           
protected  java.lang.String resource
           
 
Constructor Summary
protected Request()
           
  Request(java.io.InputStream input)
          Constructs a new Request with the provided InputStream, however the stream will not be read and the request will not be parsed until calling parse().
 
Method Summary
static java.lang.String decodeContent(java.lang.String content)
          Decodes the URL unescaping all the escaped characters.
 java.lang.String getAuthorizationPassword()
           
 java.lang.String getAuthorizationUsername()
           
 java.lang.String getBody()
           
 int getContentLength()
           
 java.lang.String getHeader(java.lang.String key)
          Retrieves the value of HTTP headers in the request.
 java.lang.Object getInput(java.lang.String key)
          Retrives the value of inputs that were included in the query string or multipart data of the request.
 java.lang.String getQueryString()
           
 java.lang.String getRequestLine()
           
 java.lang.String getRequestUri()
           
 java.lang.String getResource()
           
 java.lang.String getUserpass(java.lang.String headerValue)
          Helper method public only for testing.
 boolean hasBeenParsed()
           
 boolean hasHeader(java.lang.String key)
           
 boolean hasInput(java.lang.String key)
          Tells you if the specified input was included in the query string or multipart data.
 long numberOfBytesParsed()
          Sometimes clients will stop transmitting halfway through a request.
 void parse()
          Parses the request.
 void parseCredentials()
          The digest authentication parameters are not used by default.
protected  void parseQueryString(java.lang.String queryString)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

input

protected mmsocketserver.StreamReader input

requestURI

protected java.lang.String requestURI

resource

protected java.lang.String resource

queryString

protected java.lang.String queryString

inputs

protected java.util.HashMap<java.lang.String,java.lang.Object> inputs

headers

protected java.util.HashMap<java.lang.String,java.lang.String> headers

entityBody

protected java.lang.String entityBody

requestLine

protected java.lang.String requestLine

authorizationUsername

protected java.lang.String authorizationUsername

authorizationPassword

protected java.lang.String authorizationPassword
Constructor Detail

Request

protected Request()

Request

public Request(java.io.InputStream input)
        throws java.lang.Exception
Constructs a new Request with the provided InputStream, however the stream will not be read and the request will not be parsed until calling parse().

Parameters:
input -
Throws:
java.lang.Exception
Method Detail

parse

public void parse()
           throws java.lang.Exception
Parses the request.

Throws:
java.lang.Exception

getContentLength

public int getContentLength()
Returns:
Returns the number of bytes in the content of the request. (The value of the Content-Length header)

parseQueryString

protected void parseQueryString(java.lang.String queryString)

getRequestLine

public java.lang.String getRequestLine()
Returns:
the Request Line: the first line of the request.

getRequestUri

public java.lang.String getRequestUri()
Returns:
the Request Uri: the resource being requested + the query string.

getResource

public java.lang.String getResource()
Returns:
the resource being requested.

getQueryString

public java.lang.String getQueryString()
Returns:
the query string. Individual values in the query string should be retrieved via the getInput() method.
See Also:
getInput(java.lang.String)

hasInput

public boolean hasInput(java.lang.String key)
Tells you if the specified input was included in the query string or multipart data.

Parameters:
key -
Returns:
true if the input was provided

getInput

public java.lang.Object getInput(java.lang.String key)
Retrives the value of inputs that were included in the query string or multipart data of the request. The return value will typically be a string unless the input represents an uploaded file in which case the return value would be of type UploadedFile. null is returned if the specified input doesn't exist.

Parameters:
key -
Returns:
the value of the input.
See Also:
UploadedFile

hasHeader

public boolean hasHeader(java.lang.String key)
Parameters:
key -
Returns:
true if the header was included in the request

getHeader

public java.lang.String getHeader(java.lang.String key)
Retrieves the value of HTTP headers in the request. null is returned if the header was not present.

Parameters:
key -
Returns:
the value of the header

getBody

public java.lang.String getBody()
Returns:
the entity body of the request.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a handy string representation of the request, useful for debugging

decodeContent

public static java.lang.String decodeContent(java.lang.String content)
Decodes the URL unescaping all the escaped characters.

Parameters:
content -
Returns:
the decoded URL

hasBeenParsed

public boolean hasBeenParsed()
Returns:
true if parse() completed successfully.

getUserpass

public java.lang.String getUserpass(java.lang.String headerValue)
                             throws java.lang.Exception
Helper method public only for testing. Decodes the Base 64 digest autentication.

Parameters:
headerValue -
Returns:
the userpass string
Throws:
java.lang.Exception

parseCredentials

public void parseCredentials()
                      throws java.lang.Exception
The digest authentication parameters are not used by default. This method should be called to parse and load the username and password. Be sure to call this before calling getAuthorizationUsername() or getAuthorizationPassword().

Throws:
java.lang.Exception

getAuthorizationUsername

public java.lang.String getAuthorizationUsername()
Returns:
the digest authorization username.

getAuthorizationPassword

public java.lang.String getAuthorizationPassword()
Returns:
the digest authorization password.

numberOfBytesParsed

public long numberOfBytesParsed()
Sometimes clients will stop transmitting halfway through a request. This method gives some indiction of parsing progress being made.

Returns:
exactly what you might think


Copyright © 2009 Micah Martin. All Rights Reserved.