org.apache.commons.httpclient.methods
Class MultipartPostMethod

java.lang.Object
  |
  +--org.apache.commons.httpclient.HttpMethodBase
        |
        +--org.apache.commons.httpclient.methods.GetMethod
              |
              +--org.apache.commons.httpclient.methods.MultipartPostMethod
All Implemented Interfaces:
HttpMethod

public class MultipartPostMethod
extends GetMethod

POST Method for Multipart encoded forms. TODO: Privide decent class documentation

Since:
2.0
Author:
Matthew Albright, Jeff Dever, Adrian Sutton, Mark Diggory, Mike Bowler

Field Summary
static String MULTIPART_FORM_CONTENT_TYPE
          The Content-Type for multipart/form-data.
 
Fields inherited from class org.apache.commons.httpclient.HttpMethodBase
USER_AGENT
 
Constructor Summary
MultipartPostMethod()
          No-arg constructor.
MultipartPostMethod(String uri)
          Constructor specifying a URI.
MultipartPostMethod(String uri, String tempDir)
          Constructor specifying a URI and tempDir.
MultipartPostMethod(String uri, String tempDir, String tempFile)
          Constructor specifying a URI, tempDir and tempFile.
 
Method Summary
 void addParameter(String parameterName, File parameterFile)
          Add a parameter
 void addParameter(String parameterName, String parameterValue)
          Add a parameter
 void addParameter(String parameterName, String fileName, File parameterFile)
          Add a parameter.
 void addPart(Part part)
          Adds another part to this post.
protected  void addRequestHeaders(HttpState state, HttpConnection conn)
          Add content type header and set the Expect header if it has not already been set, in addition to the "standard" set of headers
 String getName()
          Returns "POST".
 Part[] getParts()
          Return all parts.
protected  int getRequestContentLength()
          Return the length of the request body.
 boolean getUseExpectHeader()
          Returns the useExpectHeader.
 void recycle()
          Clear my request body.
 void setUseExpectHeader(boolean value)
          Sets the useExpectHeader.
protected  boolean writeRequestBody(HttpState state, HttpConnection conn)
          Write the request body.
 
Methods inherited from class org.apache.commons.httpclient.methods.GetMethod
getFileData, getResponseBody, getResponseBodyAsStream, getTempDir, getTempFile, getUseDisk, readResponseBody, setFileData, setTempDir, setTempFile, setUseDisk
 
Methods inherited from class org.apache.commons.httpclient.HttpMethodBase
addAuthorizationRequestHeader, addContentLengthRequestHeader, addCookieRequestHeader, addHostRequestHeader, addProxyAuthorizationRequestHeader, addRequestHeader, addRequestHeader, addResponseFooter, addUserAgentRequestHeader, checkNotUsed, checkUsed, execute, generateRequestLine, getContentCharSet, getDoAuthentication, getFollowRedirects, getHostConfiguration, getPath, getQueryString, getRecoverableExceptionCount, getRequestCharSet, getRequestHeader, getRequestHeaderGroup, getRequestHeaders, getResponseBodyAsString, getResponseCharSet, getResponseFooter, getResponseFooters, getResponseHeader, getResponseHeaderGroup, getResponseHeaders, getResponseTrailerHeaderGroup, getStatusCode, getStatusLine, getStatusText, getURI, hasBeenUsed, isHttp11, isStrictMode, processResponseBody, processResponseHeaders, processStatusLine, readResponse, readResponseHeaders, readStatusLine, releaseConnection, removeRequestHeader, responseBodyConsumed, setDoAuthentication, setFollowRedirects, setHostConfiguration, setHttp11, setPath, setQueryString, setQueryString, setRequestHeader, setRequestHeader, setResponseStream, setStrictMode, shouldCloseConnection, validate, writeRequest, writeRequestHeaders, writeRequestLine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MULTIPART_FORM_CONTENT_TYPE

public static final String MULTIPART_FORM_CONTENT_TYPE
The Content-Type for multipart/form-data.

See Also:
Constant Field Values
Constructor Detail

MultipartPostMethod

public MultipartPostMethod()
No-arg constructor.


MultipartPostMethod

public MultipartPostMethod(String uri)
Constructor specifying a URI.

Parameters:
uri - either an absolute or relative URI

MultipartPostMethod

public MultipartPostMethod(String uri,
                           String tempDir)
Constructor specifying a URI and tempDir.

Parameters:
uri - either an absolute or relative URI
tempDir - directory to store temp files in

MultipartPostMethod

public MultipartPostMethod(String uri,
                           String tempDir,
                           String tempFile)
Constructor specifying a URI, tempDir and tempFile.

Parameters:
uri - either an absolute or relative URI
tempDir - directory to store temp files in
tempFile - file to store temporary data in
Method Detail

getName

public String getName()
Returns "POST".

Specified by:
getName in interface HttpMethod
Overrides:
getName in class GetMethod
Returns:
"POST"

getUseExpectHeader

public boolean getUseExpectHeader()
Returns the useExpectHeader.

Returns:
boolean

setUseExpectHeader

public void setUseExpectHeader(boolean value)
Sets the useExpectHeader.

Parameters:
value - The useExpectHeader to set

addParameter

public void addParameter(String parameterName,
                         String parameterValue)
Add a parameter

Parameters:
parameterName - The name of the parameter.
parameterValue - The value of the parameter.

addParameter

public void addParameter(String parameterName,
                         File parameterFile)
                  throws FileNotFoundException
Add a parameter

Parameters:
parameterName - The name of the parameter
parameterFile - The name of the file.
Throws:
FileNotFoundException - If the file cannot be found.

addParameter

public void addParameter(String parameterName,
                         String fileName,
                         File parameterFile)
                  throws FileNotFoundException
Add a parameter.

Parameters:
parameterName - The name of the parameter
fileName - The file name
parameterFile - The file
Throws:
FileNotFoundException - If the file cannot be found.

addPart

public void addPart(Part part)
Adds another part to this post.

Parameters:
part - The part to add.

getParts

public Part[] getParts()
Return all parts.

Returns:
an array of containing all parts

addRequestHeaders

protected void addRequestHeaders(HttpState state,
                                 HttpConnection conn)
                          throws IOException,
                                 HttpException
Add content type header and set the Expect header if it has not already been set, in addition to the "standard" set of headers

Overrides:
addRequestHeaders in class HttpMethodBase
Parameters:
state - the client state
conn - the HttpConnection the headers will eventually be written to
Throws:
IOException - when an error occurs writing the request
HttpException - when a HTTP protocol error occurs
See Also:
HttpMethodBase.writeRequestHeaders(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection)

writeRequestBody

protected boolean writeRequestBody(HttpState state,
                                   HttpConnection conn)
                            throws IOException,
                                   HttpException
Write the request body.

Overrides:
writeRequestBody in class HttpMethodBase
Parameters:
state - the client state
conn - the connection to write to
Returns:
true
Throws:
IOException - when i/o errors occur reading the response
HttpException - when a protocol error occurs or state is invalid

getRequestContentLength

protected int getRequestContentLength()

Return the length of the request body.

Once this method has been invoked, the request parameters cannot be altered until I am recycled.

Overrides:
getRequestContentLength in class HttpMethodBase
Returns:
The request content length.

recycle

public void recycle()
Clear my request body.

Specified by:
recycle in interface HttpMethod
Overrides:
recycle in class GetMethod


Copyright (c) 1999-2002 - Apache Software Foundation