com.pushtotest.tool.protocolhandler
Class HTTPBody

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

public class HTTPBody
extends java.lang.Object
implements Body

This is an implementation of the Body interface for the HTTP and related protocols.


Constructor Summary
HTTPBody()
           
 
Method Summary
 void addHeaders(java.net.HttpURLConnection con)
          Adds the content-type header, assuming this is a POST
 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.util.Iterator getParams()
          Returns an Iterator of all of the parameter keys so that they user can get the list and then get the values.
 java.lang.String id()
          Returns an id for this protocol.
protected  java.lang.String paramsAsString()
          Gets all of the keys and values and turns them into the proper kind of string to be sent as a POST or a GET.
 java.lang.Object removeParameter(java.lang.String name)
          Removes a key/value from the parameters
 void setContentType(java.lang.String newtype)
          Sets the value to be used in the Content-Type header of a POST to the target host
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTTPBody

public HTTPBody()
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()
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.

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.

getParams

public java.util.Iterator getParams()
Returns an Iterator of all of the parameter keys so that they user can get the list and then get the values.

Returns:
An Iterator to iterate over to get all of the values.

paramsAsString

protected java.lang.String paramsAsString()
Gets all of the keys and values and turns them into the proper kind of string to be sent as a POST or a GET.

Returns:
The parameter string all made out.

removeParameter

public java.lang.Object removeParameter(java.lang.String name)
Removes a key/value from the parameters

Parameters:
String - key to parameter value

addHeaders

public void addHeaders(java.net.HttpURLConnection con)
Adds the content-type header, assuming this is a POST

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

setContentType

public void setContentType(java.lang.String newtype)
Sets the value to be used in the Content-Type header of a POST to the target host