com.sun.slamd.scripting.http
Class HTTPResponseVariable

java.lang.Object
  extended bycom.sun.slamd.scripting.engine.Variable
      extended bycom.sun.slamd.scripting.http.HTTPResponseVariable
All Implemented Interfaces:
Argument

public class HTTPResponseVariable
extends Variable

This class defines a variable that can be used to encapsulate a response from an HTTP server. An HTTP response variable offers the following methods:


Field Summary
static java.lang.String GET_CONTENT_LENGTH_METHOD_NAME
          The name of the method used to retrieve the value of the Content-Length header.
static int GET_CONTENT_LENGTH_METHOD_NUMBER
          The method number for the "getContentLength" method.
static java.lang.String GET_CONTENT_TYPE_METHOD_NAME
          The name of the method used to retrieve the value of the Content-Type header.
static int GET_CONTENT_TYPE_METHOD_NUMBER
          The method number for the "getContentType" method.
static java.lang.String GET_DATA_AS_STRING_METHOD_NAME
          The name of the method used to retrieve a string representation of the data associated with this response.
static int GET_DATA_AS_STRING_METHOD_NUMBER
          The method number for the "getDataAsString" method.
static java.lang.String GET_HEADER_METHOD_NAME
          The name of the method used to retrieve the value of the requested header.
static int GET_HEADER_METHOD_NUMBER
          The method number for the "getHeader" method.
static java.lang.String GET_HEADER_NAMES_METHOD_NAME
          The name of the method used to retrieve the names of the headers associated this this response.
static int GET_HEADER_NAMES_METHOD_NUMBER
          The method number for the "getHeaderNames" method.
static java.lang.String GET_HEADER_VALUES_METHOD_NAME
          The name of the method used to retrieve the values of the requested header.
static int GET_HEADER_VALUES_METHOD_NUMBER
          The method number for the "getHeaderValues" method.
static java.lang.String GET_HTML_DOCUMENT_METHOD_NAME
          The name of the method used to retrieve the HTML document associated with this response.
static int GET_HTML_DOCUMENT_METHOD_NUMBER
          The method number for the "getHTMLDocument" method.
static java.lang.String GET_PROTOCOL_VERSION_METHOD_NAME
          The name of the method used to retrieve the protocol version string for this response.
static int GET_PROTOCOL_VERSION_METHOD_NUMBER
          The method number for the "getProtocolVersion" method.
static java.lang.String GET_RESPONSE_MESSAGE_METHOD_NAME
          The name of the method used to retrieve the response message for this response.
static int GET_RESPONSE_MESSAGE_METHOD_NUMBER
          The method number for the "getResponseMessage" method.
static java.lang.String GET_STATUS_CODE_METHOD_NAME
          The name of the method used to retrieve the HTTP status code for this response.
static int GET_STATUS_CODE_METHOD_NUMBER
          The method number for the "getStatusCode" method.
static Method[] HTTP_RESPONSE_VARIABLE_METHODS
          The set of methods associated with HTML document variables.
static java.lang.String HTTP_RESPONSE_VARIABLE_TYPE
          The name that will be used for the data type of HTTP response variables.
static java.lang.String IS_NULL_METHOD_NAME
          The name of the method used to determine whether this is a null response.
static int IS_NULL_METHOD_NUMBER
          The method number for the "isNull" method.
 
Constructor Summary
HTTPResponseVariable()
          Creates a new variable with no name, to be used only when creating a variable with Class.newInstance(), and only when setName() is called after that to set the name.
HTTPResponseVariable(HTTPResponse httpResponse)
          Creates a new HTTP response variable based on the provided response.
 
Method Summary
 void assign(Argument argument)
          Assigns the value of the provided argument to this variable.
 Variable executeMethod(int lineNumber, int methodNumber, Argument[] arguments)
          Executes the specified method, using the provided variables as arguments to the method, and makes the return value available to the caller.
 int getMethodNumber(java.lang.String methodName, java.lang.String[] argumentTypes)
          Retrieves the method number for the method that has the specified name and argument types, or -1 if there is no such method.
 Method[] getMethods()
          Retrieves a list of all methods defined for this variable.
 java.lang.String getReturnTypeForMethod(java.lang.String methodName, java.lang.String[] argumentTypes)
          Retrieves the return type for the method with the specified name and argument types.
 java.lang.String getValueAsString()
          Retrieves a string representation of the value of this argument.
 java.lang.String getVariableTypeName()
          Retrieves the name of the variable type for this variable.
 boolean hasMethod(java.lang.String methodName)
          Indicates whether this variable type has a method with the specified name.
 
Methods inherited from class com.sun.slamd.scripting.engine.Variable
getArgumentAsString, getArgumentType, getArgumentValue, getName, getStatTrackers, isValidIdentifier, setName, startStatTrackers, stopStatTrackers
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_RESPONSE_VARIABLE_TYPE

public static final java.lang.String HTTP_RESPONSE_VARIABLE_TYPE
The name that will be used for the data type of HTTP response variables.

See Also:
Constant Field Values

GET_CONTENT_LENGTH_METHOD_NAME

public static final java.lang.String GET_CONTENT_LENGTH_METHOD_NAME
The name of the method used to retrieve the value of the Content-Length header.

See Also:
Constant Field Values

GET_CONTENT_LENGTH_METHOD_NUMBER

public static final int GET_CONTENT_LENGTH_METHOD_NUMBER
The method number for the "getContentLength" method.

See Also:
Constant Field Values

GET_CONTENT_TYPE_METHOD_NAME

public static final java.lang.String GET_CONTENT_TYPE_METHOD_NAME
The name of the method used to retrieve the value of the Content-Type header.

See Also:
Constant Field Values

GET_CONTENT_TYPE_METHOD_NUMBER

public static final int GET_CONTENT_TYPE_METHOD_NUMBER
The method number for the "getContentType" method.

See Also:
Constant Field Values

GET_DATA_AS_STRING_METHOD_NAME

public static final java.lang.String GET_DATA_AS_STRING_METHOD_NAME
The name of the method used to retrieve a string representation of the data associated with this response.

See Also:
Constant Field Values

GET_DATA_AS_STRING_METHOD_NUMBER

public static final int GET_DATA_AS_STRING_METHOD_NUMBER
The method number for the "getDataAsString" method.

See Also:
Constant Field Values

GET_HEADER_METHOD_NAME

public static final java.lang.String GET_HEADER_METHOD_NAME
The name of the method used to retrieve the value of the requested header.

See Also:
Constant Field Values

GET_HEADER_METHOD_NUMBER

public static final int GET_HEADER_METHOD_NUMBER
The method number for the "getHeader" method.

See Also:
Constant Field Values

GET_HEADER_NAMES_METHOD_NAME

public static final java.lang.String GET_HEADER_NAMES_METHOD_NAME
The name of the method used to retrieve the names of the headers associated this this response.

See Also:
Constant Field Values

GET_HEADER_NAMES_METHOD_NUMBER

public static final int GET_HEADER_NAMES_METHOD_NUMBER
The method number for the "getHeaderNames" method.

See Also:
Constant Field Values

GET_HEADER_VALUES_METHOD_NAME

public static final java.lang.String GET_HEADER_VALUES_METHOD_NAME
The name of the method used to retrieve the values of the requested header.

See Also:
Constant Field Values

GET_HEADER_VALUES_METHOD_NUMBER

public static final int GET_HEADER_VALUES_METHOD_NUMBER
The method number for the "getHeaderValues" method.

See Also:
Constant Field Values

GET_HTML_DOCUMENT_METHOD_NAME

public static final java.lang.String GET_HTML_DOCUMENT_METHOD_NAME
The name of the method used to retrieve the HTML document associated with this response.

See Also:
Constant Field Values

GET_HTML_DOCUMENT_METHOD_NUMBER

public static final int GET_HTML_DOCUMENT_METHOD_NUMBER
The method number for the "getHTMLDocument" method.

See Also:
Constant Field Values

GET_RESPONSE_MESSAGE_METHOD_NAME

public static final java.lang.String GET_RESPONSE_MESSAGE_METHOD_NAME
The name of the method used to retrieve the response message for this response.

See Also:
Constant Field Values

GET_RESPONSE_MESSAGE_METHOD_NUMBER

public static final int GET_RESPONSE_MESSAGE_METHOD_NUMBER
The method number for the "getResponseMessage" method.

See Also:
Constant Field Values

GET_PROTOCOL_VERSION_METHOD_NAME

public static final java.lang.String GET_PROTOCOL_VERSION_METHOD_NAME
The name of the method used to retrieve the protocol version string for this response.

See Also:
Constant Field Values

GET_PROTOCOL_VERSION_METHOD_NUMBER

public static final int GET_PROTOCOL_VERSION_METHOD_NUMBER
The method number for the "getProtocolVersion" method.

See Also:
Constant Field Values

GET_STATUS_CODE_METHOD_NAME

public static final java.lang.String GET_STATUS_CODE_METHOD_NAME
The name of the method used to retrieve the HTTP status code for this response.

See Also:
Constant Field Values

GET_STATUS_CODE_METHOD_NUMBER

public static final int GET_STATUS_CODE_METHOD_NUMBER
The method number for the "getStatusCode" method.

See Also:
Constant Field Values

IS_NULL_METHOD_NAME

public static final java.lang.String IS_NULL_METHOD_NAME
The name of the method used to determine whether this is a null response.

See Also:
Constant Field Values

IS_NULL_METHOD_NUMBER

public static final int IS_NULL_METHOD_NUMBER
The method number for the "isNull" method.

See Also:
Constant Field Values

HTTP_RESPONSE_VARIABLE_METHODS

public static final Method[] HTTP_RESPONSE_VARIABLE_METHODS
The set of methods associated with HTML document variables.

Constructor Detail

HTTPResponseVariable

public HTTPResponseVariable()
                     throws ScriptException
Creates a new variable with no name, to be used only when creating a variable with Class.newInstance(), and only when setName() is called after that to set the name.

Throws:
ScriptException - If a problem occurs while initializing the new variable.

HTTPResponseVariable

public HTTPResponseVariable(HTTPResponse httpResponse)
Creates a new HTTP response variable based on the provided response.

Parameters:
httpResponse - The HTTP response to use to initialize this variable.
Method Detail

getVariableTypeName

public java.lang.String getVariableTypeName()
Retrieves the name of the variable type for this variable.

Specified by:
getVariableTypeName in class Variable
Returns:
The name of the variable type for this variable.

getMethods

public Method[] getMethods()
Retrieves a list of all methods defined for this variable.

Specified by:
getMethods in class Variable
Returns:
A list of all methods defined for this variable.

hasMethod

public boolean hasMethod(java.lang.String methodName)
Indicates whether this variable type has a method with the specified name.

Specified by:
hasMethod in class Variable
Parameters:
methodName - The name of the method.
Returns:
true if this variable has a method with the specified name, or false if it does not.

getMethodNumber

public int getMethodNumber(java.lang.String methodName,
                           java.lang.String[] argumentTypes)
Retrieves the method number for the method that has the specified name and argument types, or -1 if there is no such method.

Specified by:
getMethodNumber in class Variable
Parameters:
methodName - The name of the method.
argumentTypes - The list of argument types for the method.
Returns:
The method number for the method that has the specified name and argument types.

getReturnTypeForMethod

public java.lang.String getReturnTypeForMethod(java.lang.String methodName,
                                               java.lang.String[] argumentTypes)
Retrieves the return type for the method with the specified name and argument types.

Specified by:
getReturnTypeForMethod in class Variable
Parameters:
methodName - The name of the method.
argumentTypes - The set of argument types for the method.
Returns:
The return type for the method, or null if there is no such method defined.

executeMethod

public Variable executeMethod(int lineNumber,
                              int methodNumber,
                              Argument[] arguments)
                       throws ScriptException
Executes the specified method, using the provided variables as arguments to the method, and makes the return value available to the caller.

Specified by:
executeMethod in class Variable
Parameters:
lineNumber - The line number of the script in which the method call occurs.
methodNumber - The method number of the method to execute.
arguments - The set of arguments to use for the method.
Returns:
The value returned from the method, or null if it does not return a value.
Throws:
ScriptException - If the specified method does not exist, or if a problem occurs while attempting to execute it.

assign

public void assign(Argument argument)
            throws ScriptException
Assigns the value of the provided argument to this variable. The value of the provided argument must be of the same type as this variable.

Specified by:
assign in class Variable
Parameters:
argument - The argument whose value should be assigned to this variable.
Throws:
ScriptException - If a problem occurs while performing the assignment.

getValueAsString

public java.lang.String getValueAsString()
Retrieves a string representation of the value of this argument.

Returns:
A string representation of the value of this argument.