mmhttp.protocol
Class RequestBuilder

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

public class RequestBuilder
extends java.lang.Object

While Request is used for parsing requests, this clas is used to build request.


Constructor Summary
RequestBuilder(java.lang.String resource)
          Contructs a new RequestBuilder with the specified resource.
 
Method Summary
 void addCredentials(java.lang.String username, java.lang.String password)
          Adds digest authentication credentials to the request.
 void addHeader(java.lang.String key, java.lang.String value)
          Adds a header to the request.
 void addInput(java.lang.String key, java.lang.Object value)
          Add inputs that will be go in the query string.
 void addInputAsPart(java.lang.String name, java.io.InputStream input, int size, java.lang.String contentType)
          Same as addInputAsPart(String name, Object content) except that this version should be used for large datasets that wouldn't want to load into memory all at once.
 void addInputAsPart(java.lang.String name, java.lang.Object content)
          Add the input as multi-part content to the request.
 java.lang.String getBoundary()
          Build a unique boundary for sparating multi-part content.
 java.lang.String getText()
           
 java.lang.String queryString()
          Builds the query string for this request.
 void send(java.io.OutputStream output)
          Writes an HTTP 1.1 compiant representation of the request to the provided OutputStream.
 void setHostAndPort(java.lang.String host, int port)
          Use to build the Host header.
 void setMethod(java.lang.String method)
          Sets the HTTP method...
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestBuilder

public RequestBuilder(java.lang.String resource)
Contructs a new RequestBuilder with the specified resource. This is sufficient for a minimal compliant HTTP request.

Parameters:
resource -
Method Detail

setMethod

public void setMethod(java.lang.String method)
Sets the HTTP method... GET, POST, etc...

Parameters:
method -

addHeader

public void addHeader(java.lang.String key,
                      java.lang.String value)
Adds a header to the request.

Parameters:
key -
value -

getText

public java.lang.String getText()
                         throws java.lang.Exception
Returns:
an HTTP 1.1 compliant string representation of the request.
Throws:
java.lang.Exception

send

public void send(java.io.OutputStream output)
          throws java.lang.Exception
Writes an HTTP 1.1 compiant representation of the request to the provided OutputStream.

Parameters:
output -
Throws:
java.lang.Exception

addInput

public void addInput(java.lang.String key,
                     java.lang.Object value)
              throws java.lang.Exception
Add inputs that will be go in the query string.

Parameters:
key -
value -
Throws:
java.lang.Exception

queryString

public java.lang.String queryString()
                             throws java.lang.Exception
Builds the query string for this request.

Returns:
query string
Throws:
java.lang.Exception

addCredentials

public void addCredentials(java.lang.String username,
                           java.lang.String password)
                    throws java.lang.Exception
Adds digest authentication credentials to the request.

Parameters:
username -
password -
Throws:
java.lang.Exception

setHostAndPort

public void setHostAndPort(java.lang.String host,
                           int port)
Use to build the Host header.

Parameters:
host -
port -

getBoundary

public java.lang.String getBoundary()
Build a unique boundary for sparating multi-part content.

Returns:
a unique boundary

addInputAsPart

public void addInputAsPart(java.lang.String name,
                           java.lang.Object content)
                    throws java.lang.Exception
Add the input as multi-part content to the request. Once called the request becomes a multi-part request and all inputs will be included in the body of the request, ie. no query string.

Parameters:
name -
content -
Throws:
java.lang.Exception

addInputAsPart

public void addInputAsPart(java.lang.String name,
                           java.io.InputStream input,
                           int size,
                           java.lang.String contentType)
                    throws java.lang.Exception
Same as addInputAsPart(String name, Object content) except that this version should be used for large datasets that wouldn't want to load into memory all at once.

Parameters:
name -
input -
size - - number of bytes in the input stream
contentType - - for the Content-Type header
Throws:
java.lang.Exception


Copyright © 2009 Micah Martin. All Rights Reserved.