net.grinder.plugin.http
Interface HTTPUtilities


public interface HTTPUtilities

Things that HTTP scripts find useful.

Author:
Philip Aston
See Also:
HTTPPluginControl.getHTTPUtilities()

Method Summary
 NVPair basicAuthorizationHeader(String userID, String password)
          Create a NVPair for an HTTP Basic Authorization header.
 HTTPResponse getLastResponse()
          Return the response for the last request made by the calling worker thread.
 String valueFromBodyURI(String tokenName)
          Return the value for a path parameter or query string name-value token with the given tokenName in a URI in the body of the last response.
 String valueFromBodyURI(String tokenName, String afterText)
          Return the value for a path parameter or query string name-value token with the given tokenName in a URI in the body of the last response.
 String valueFromHiddenInput(String tokenName)
          Return the value for a hidden input token with the given tokenName in the body of the last response.
 String valueFromHiddenInput(String tokenName, String afterText)
          Return the value for a hidden input token with the given tokenName in the body of the last response.
 String valueFromLocationURI(String tokenName)
          Return the value for a path parameter or query string name-value token with the given tokenName in a Location header from the last response.
 

Method Detail

basicAuthorizationHeader

NVPair basicAuthorizationHeader(String userID,
                                String password)
Create a NVPair for an HTTP Basic Authorization header.

Parameters:
userID - The user name.
password - The password.
Returns:
The NVPair that can be used as a header with HTTPRequest.

getLastResponse

HTTPResponse getLastResponse()
                             throws GrinderException
Return the response for the last request made by the calling worker thread.

Returns:
The response, or null if the calling thread has not made any requests.
Throws:
GrinderException - If not called from a worker thread.

valueFromLocationURI

String valueFromLocationURI(String tokenName)
                            throws GrinderException
Return the value for a path parameter or query string name-value token with the given tokenName in a Location header from the last response. If there are multiple matches, the first value is returned.

If there is no match, an empty string is returned rather than null. This makes scripts more robust (as they don't need to check the value before using it), but they lose the ability to distinguish between a missing token and an empty value.

Parameters:
tokenName - The token name.
Returns:
The first value if one is found.
Throws:
GrinderException - If not called from a worker thread.

valueFromHiddenInput

String valueFromHiddenInput(String tokenName)
                            throws GrinderException
Return the value for a hidden input token with the given tokenName in the body of the last response. If there are multiple matches, the first value is returned.

If there is no match, an empty string is returned rather than null. This makes scripts more robust (as they don't need to check the value before using it), but they lose the ability to distinguish between a missing token and an empty value.

Parameters:
tokenName - The token name.
Returns:
The first value if one is found, or an empty string.
Throws:
GrinderException - If not called from a worker thread.
See Also:
valueFromHiddenInput(String, String)

valueFromHiddenInput

String valueFromHiddenInput(String tokenName,
                            String afterText)
                            throws GrinderException
Return the value for a hidden input token with the given tokenName in the body of the last response. If there are multiple matches, the first value is returned. This version of valueFromHiddenInput only considers matches following the first occurrence of the literal text afterText. If there are multiple matches, the first value is returned.

If there is no match, an empty string is returned rather than null. This makes scripts more robust (as they don't need to check the value before using it), but they lose the ability to distinguish between a missing token and an empty value.

Parameters:
tokenName - The token name.
afterText - The search begins after the first occurrence of this literal text.
Returns:
The first value if one is found, or an empty string if the body does not contain afterText followed by a URI containing a token with name tokenName.
Throws:
GrinderException - If not called from a worker thread.
See Also:
valueFromHiddenInput(String)

valueFromBodyURI

String valueFromBodyURI(String tokenName)
                        throws GrinderException
Return the value for a path parameter or query string name-value token with the given tokenName in a URI in the body of the last response. If there are multiple matches, the first value is returned.

If there is no match, an empty string is returned rather than null. This makes scripts more robust (as they don't need to check the value before using it), but they lose the ability to distinguish between a missing token and an empty value.

Parameters:
tokenName - The token name.
Returns:
The first value if one is found, or an empty string.
Throws:
GrinderException - If not called from a worker thread.
See Also:
valueFromBodyURI(String, String)

valueFromBodyURI

String valueFromBodyURI(String tokenName,
                        String afterText)
                        throws GrinderException
Return the value for a path parameter or query string name-value token with the given tokenName in a URI in the body of the last response. This version of valueFromBodyURI only considers matches following the first occurrence of the literal text afterText. If there are multiple matches, the first value is returned.

If there is no match, an empty string is returned rather than null. This makes scripts more robust (as they don't need to check the value before using it), but they lose the ability to distinguish between a missing token and an empty value.

Parameters:
tokenName - The token name.
afterText - The search begins after the first occurrence of this literal text.
Returns:
The first value if one is found, or an empty string if the body does not contain afterText followed by a URI containing a token with name tokenName.
Throws:
GrinderException - If not called from a worker thread.
See Also:
valueFromBodyURI(String)