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.

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

Field Summary
 
Fields inherited from class org.apache.commons.httpclient.HttpMethodBase
USER_AGENT
 
Constructor Summary
MultipartPostMethod()
          No-arg constructor.
MultipartPostMethod(java.lang.String uri)
          Constructor specifying a URI.
MultipartPostMethod(java.lang.String uri, java.lang.String tempDir)
          Constructor specifying a URI and tempDir.
MultipartPostMethod(java.lang.String uri, java.lang.String tempDir, java.lang.String tempFile)
          Constructor specifying a URI, tempDir and tempFile.
 
Method Summary
 void addParameter(java.lang.String parameterName, java.io.File parameterFile)
           
 void addParameter(java.lang.String parameterName, java.lang.String parameterValue)
           
 void addParameter(java.lang.String parameterName, java.lang.String fileName, java.io.File parameterFile)
           
 void addPart(Part part)
          Adds another part to this post.
protected  void addRequestHeaders(HttpState state, HttpConnection conn)
          Populates the request headers map to with additional headers to be submitted to the given HttpConnection.
 java.lang.String getName()
          Returns "POST".
protected  int getRequestContentLength()
          Override method of HttpMethodBase to return the length of the request body.
 void recycle()
          Clear my request body.
protected  boolean writeRequestBody(HttpState state, HttpConnection conn)
          Override method of HttpMethodBase to write request parameters as 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, getRequestHeaders, getResponseBodyAsString, getResponseCharSet, getResponseFooter, getResponseFooters, getResponseHeader, getResponseHeaders, 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
 

Constructor Detail

MultipartPostMethod

public MultipartPostMethod()
No-arg constructor.


MultipartPostMethod

public MultipartPostMethod(java.lang.String uri)
Constructor specifying a URI.

Parameters:
uri - either an absolute or relative URI

MultipartPostMethod

public MultipartPostMethod(java.lang.String uri,
                           java.lang.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(java.lang.String uri,
                           java.lang.String tempDir,
                           java.lang.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 java.lang.String getName()
Returns "POST".

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

recycle

public void recycle()
Clear my request body.

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

addParameter

public void addParameter(java.lang.String parameterName,
                         java.lang.String parameterValue)

addParameter

public void addParameter(java.lang.String parameterName,
                         java.io.File parameterFile)
                  throws java.io.FileNotFoundException
java.io.FileNotFoundException

addParameter

public void addParameter(java.lang.String parameterName,
                         java.lang.String fileName,
                         java.io.File parameterFile)
                  throws java.io.FileNotFoundException
java.io.FileNotFoundException

addPart

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


addRequestHeaders

protected void addRequestHeaders(HttpState state,
                                 HttpConnection conn)
                          throws java.io.IOException,
                                 HttpException
Description copied from class: HttpMethodBase
Populates the request headers map to with additional headers to be submitted to the given HttpConnection.

This implementation adds User-Agent, Host, Cookie, Content-Length, Transfer-Encoding, and Authorization headers, when appropriate.

Subclasses may want to override this method to to add additional headers, and may choose to invoke this implementation (via super) to add the "standard" headers.

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

writeRequestBody

protected boolean writeRequestBody(HttpState state,
                                   HttpConnection conn)
                            throws java.io.IOException,
                                   HttpException
Override method of HttpMethodBase to write request parameters as the request body.

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

getRequestContentLength

protected int getRequestContentLength()
Override method of HttpMethodBase to 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:
0, indicating that the request has no body.


Copyright © 2001-2003 Apache Software Foundation. All Rights Reserved.