com.pushtotest.tool.protocolhandler
Class HTTPMultipartBody

java.lang.Object
  extended by com.pushtotest.tool.protocolhandler.HTTPMultipartBody
All Implemented Interfaces:
Body

public class HTTPMultipartBody
extends java.lang.Object
implements Body

This is an implementation of the Body interface for the HTTP and related protocols. This enables multipart MIME encoded forms.


Constructor Summary
HTTPMultipartBody()
           
 
Method Summary
 void addFile(java.lang.String filename, java.lang.String contenttype, java.lang.String parametername)
          Adds a file that will be MIME encoded.
 void addHeaders(java.net.HttpURLConnection con)
          Allows the Body object to add its own HTTP header parameters
 void addParameter(java.lang.String name, java.lang.String value)
          Sets a parameter value pair as something that should be set in the header of this protocol.
 void addParameter(java.lang.String name, java.lang.String value, boolean encode)
          Sets a parameter value pair as something that should be set in the header of this protocol.
 void addParameter(java.lang.String name, java.lang.String value, java.lang.String encoding)
          Sets a parameter value pair as something that should be set in the header of this protocol.
 java.lang.String get(java.lang.String name)
          Returns the value of a first parameter variable as a String.
 java.lang.String getBody()
          Returns the content of the body to be used by the Protocol.
 java.lang.String getNext()
          Returns additional header values with the same key defined using the get() method.
 java.lang.String id()
          Returns an id for this protocol.
 void setData(java.lang.String bodydata)
           
 void setFile(java.lang.String filename, java.lang.String contenttype)
          Identifies a file that will be MIME encoded.
 void setFile(java.lang.String filename, java.lang.String contenttype, java.lang.String parametername)
          Identifies a file that will be MIME encoded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTTPMultipartBody

public HTTPMultipartBody()
Method Detail

id

public java.lang.String id()
Returns an id for this protocol. The id is a string that will be used to uniquily identify the protocol. For example :// would be appropriate (without the "://").

Specified by:
id in interface Body
Returns:
The id for this Protocol.

getBody

public java.lang.String getBody()
                         throws ToolException
Returns the content of the body to be used by the Protocol.

Specified by:
getBody in interface Body
Returns:
All of the content that should be sent as the Protocol body.
Throws:
ToolException

setFile

public void setFile(java.lang.String filename,
                    java.lang.String contenttype,
                    java.lang.String parametername)
Identifies a file that will be MIME encoded.

Parameters:
filename - The name and path to the file that will be encoded and sent to the host
contenttype - The MIME content type of the file, for example, plain/text or audio/x-pn-realaudio
parametername - The value of the name field in the content type description

setFile

public void setFile(java.lang.String filename,
                    java.lang.String contenttype)
Identifies a file that will be MIME encoded. The content type description defaults to "uploadFile".

Parameters:
filename - The name and path to the file that will be encoded and sent to the host
contenttype - The MIME content type of the file, for example, plain/text or audio/x-pn-realaudio

addFile

public void addFile(java.lang.String filename,
                    java.lang.String contenttype,
                    java.lang.String parametername)
Adds a file that will be MIME encoded.

Parameters:
filename - The name and path to the file that will be encoded and sent to the host
contenttype - The MIME content type of the file, for example, plain/text or audio/x-pn-realaudio
parametername - The value of the name field in the content type description

setData

public void setData(java.lang.String bodydata)

addHeaders

public void addHeaders(java.net.HttpURLConnection con)
Allows the Body object to add its own HTTP header parameters

Specified by:
addHeaders in interface Body
Parameters:
con - The HttpURLConnection object that will communicate with the host using HTTP protocols

addParameter

public void addParameter(java.lang.String name,
                         java.lang.String value)
                  throws ToolException
Sets a parameter value pair as something that should be set in the header of this protocol. This delegates to the set(name,value,encode) method passing through the values and setting encode to 'false'.

Specified by:
addParameter in interface Body
Parameters:
name - The name of the header variable.
value - The value to set for this header variable.
Throws:
ToolException

addParameter

public void addParameter(java.lang.String name,
                         java.lang.String value,
                         boolean encode)
                  throws ToolException
Sets a parameter value pair as something that should be set in the header of this protocol. Optionally will encode the value with UTF-8 protocol specific encoding. This is here mostly for backward compatibility with TestMaker 3 beta 3 and prior versions of TOOL.

Parameters:
name - The name of the header variable.
value - The value to set for this header variable.
encode - Whether or not to encode the value with the UTF-8 encoder
Throws:
ToolException

addParameter

public void addParameter(java.lang.String name,
                         java.lang.String value,
                         java.lang.String encoding)
                  throws ToolException
Sets a parameter value pair as something that should be set in the header of this protocol. Optionally will encode the value with a protocol specific encoding.

Parameters:
name - The name of the header variable.
value - The value to set for this header variable.
encode - Whether or not to encode the value with the right encoder for this type.
Throws:
ToolException

get

public java.lang.String get(java.lang.String name)
Returns the value of a first parameter variable as a String. Use getNext() to return additional parameters with the same key.

Parameters:
name - The name of the header variable to look for.

getNext

public java.lang.String getNext()
Returns additional header values with the same key defined using the get() method.

Returns:
null means no additional parameters.