org.xlightweb
Class MultipartFormDataRequest

Package class diagram package MultipartFormDataRequest
java.lang.Object
  extended by org.xlightweb.Part
      extended by org.xlightweb.HttpRequest
          extended by org.xlightweb.MultipartRequest
              extended by org.xlightweb.MultipartFormDataRequest
All Implemented Interfaces:
IHeader, IHttpMessage, IHttpRequest, IPart

public class MultipartFormDataRequest
extends MultipartRequest

A multipart/form-data request, which supports file uploads. Example:

   MultipartFormDataRequest req = new MultipartFormDataRequest(url);
   req.addPart("file", file);
   req.addPart("description", "text/plain", "A unsigned ...");
   
   IHttpResponse resp = httpClient.call(req);
   // ...
 
see RFC 1867


Field Summary
 
Fields inherited from interface org.xlightweb.IHttpMessage
CONNECT_METHOD, DEFAULT_ENCODING, DEFAULT_ENCODING_KEY, DELETE_METHOD, GET_METHOD, HEAD_METHOD, OPTIONS_METHOD, POST_METHOD, PUT_METHOD, TRACE_METHOD
 
Constructor Summary
MultipartFormDataRequest(String url)
          constructor
 
Method Summary
 void addPart(String name, File file)
          adds a part
 void addPart(String name, String contentType, String content)
          adds a part
 Object getAttribute(String name)
          Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
 Enumeration getAttributeNames()
          Returns an Enumeration containing the names of the attributes available to this message.
 Set<String> getAttributeNameSet()
          Returns an Set containing the names of the attributes available to this messaget.
 int getContentLength()
          Returns the length, in bytes, of the message body and made available by the input stream, or -1 if the length is not known.
 IHttpMessageHeader getMessageHeader()
          returns the message header
 void removeHopByHopHeaders()
          removes all hop-by-hop headers without Transfer-Encoding if set to chunked
 void setAttribute(String name, Object o)
          Stores an attribute in this header.
 void setContentLength(int length)
          sets the content length in bytes
 
Methods inherited from class org.xlightweb.MultipartRequest
addPart
 
Methods inherited from class org.xlightweb.HttpRequest
addMatrixParameter, addParameter, getAccept, getBooleanParameter, getBooleanParameter, getContextPath, getDoubleParameter, getDoubleParameter, getFloatParameter, getFloatParameter, getHost, getIntParameter, getIntParameter, getLongParameter, getLongParameter, getMatrixParameter, getMatrixParameterNameSet, getMatrixParameterValues, getMethod, getParameter, getParameter, getParameterNames, getParameterNameSet, getParameterValues, getPathInfo, getPathInfo, getProtocol, getProtocolVersion, getQueryString, getRemoteAddr, getRemoteHost, getRemotePort, getRequestHandlerPath, getRequestHeader, getRequestURI, getRequestUrl, getRequiredBooleanParameter, getRequiredDoubleParameter, getRequiredFloatParameter, getRequiredIntParameter, getRequiredLongParameter, getRequiredStringParameter, getScheme, getServerName, getServerPort, getUserAgent, isSecure, removeMatrixParameter, removeParameter, setContextPath, setHost, setMatrixParameter, setMethod, setParameter, setRequestHandlerPath, setRequestURI, setRequestUrl, setUserAgent
 
Methods inherited from class org.xlightweb.Part
addHeader, addHeaderLine, addHeaderlines, containsHeader, getBlockingBody, getBody, getCharacterEncoding, getContentType, getDisposition, getDispositionParam, getDispositionType, getHeader, getHeaderList, getHeaderNames, getHeaderNameSet, getHeaders, getNonBlockingBody, getPartHeader, getTransferEncoding, hasBody, removeHeader, setContentType, setHeader, setTransferEncoding, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.xlightweb.IHttpMessage
getAttribute, getAttributeNames, getAttributeNameSet, getCharacterEncoding, getContentLength, getContentType, getMessageHeader, getTransferEncoding, removeHopByHopHeaders, setAttribute, setContentLength, setContentType, setTransferEncoding
 
Methods inherited from interface org.xlightweb.IPart
getBlockingBody, getBody, getNonBlockingBody, getPartHeader, hasBody
 
Methods inherited from interface org.xlightweb.IHeader
addHeader, addHeaderLine, addHeaderlines, containsHeader, getDisposition, getDispositionParam, getDispositionType, getHeader, getHeaderList, getHeaderNames, getHeaderNameSet, getHeaders, removeHeader, setHeader
 

Constructor Detail

MultipartFormDataRequest

public MultipartFormDataRequest(String url)
                         throws MalformedURLException,
                                IOException
constructor

Parameters:
url - the url string
Throws:
MalformedURLException - if the url is malformed
IOException
Method Detail

addPart

public void addPart(String name,
                    String contentType,
                    String content)
             throws IOException
adds a part

Parameters:
name - the part name
content - the content
Throws:
IOException - if an exception occurs

addPart

public void addPart(String name,
                    File file)
             throws IOException
adds a part

Parameters:
name - the part name
file - the file
Throws:
IOException - if an exception occurs

getMessageHeader

public final IHttpMessageHeader getMessageHeader()
returns the message header

Specified by:
getMessageHeader in interface IHttpMessage
Returns:
the message header

setAttribute

public final void setAttribute(String name,
                               Object o)
Stores an attribute in this header. Attributes are reset between messages.

Attribute names should follow the same conventions as package names.

Specified by:
setAttribute in interface IHttpMessage
Parameters:
name - a String specifying the name of the attribute
o - the Object to be stored

getAttribute

public final Object getAttribute(String name)
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

Attribute names should follow the same conventions as package names.

Specified by:
getAttribute in interface IHttpMessage
Parameters:
name - a String specifying the name of the attribute
Returns:
an Object containing the value of the attribute, or null if the attribute does not exist

getAttributeNames

public final Enumeration getAttributeNames()
Returns an Enumeration containing the names of the attributes available to this message. This method returns an empty Enumeration if the message has no attributes available to it.

Specified by:
getAttributeNames in interface IHttpMessage
Returns:
an Enumeration of strings containing the names of the message's attributes

getAttributeNameSet

public final Set<String> getAttributeNameSet()
Returns an Set containing the names of the attributes available to this messaget. This method returns an empty Set if the request has no attributes available to it.

Specified by:
getAttributeNameSet in interface IHttpMessage
Returns:
an Set of strings containing the names of the message's attributes

getContentLength

public final int getContentLength()
Returns the length, in bytes, of the message body and made available by the input stream, or -1 if the length is not known.

Specified by:
getContentLength in interface IHttpMessage
Returns:
an integer containing the length of the message body or -1 if the length is not known

setContentLength

public final void setContentLength(int length)
sets the content length in bytes

Specified by:
setContentLength in interface IHttpMessage
Parameters:
length - the content length in bytes

removeHopByHopHeaders

public final void removeHopByHopHeaders()
removes all hop-by-hop headers without Transfer-Encoding if set to chunked

Specified by:
removeHopByHopHeaders in interface IHttpMessage