webtester.packages.threads
Class fastProxyHandler

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--webtester.packages.threads.fastProxyHandler
All Implemented Interfaces:
java.lang.Runnable

public class fastProxyHandler
extends java.lang.Thread

Used for proxying HTTP requests as quickly as possible. No data is recorded in this thread.

Author:
Aaron DeLong

Field Summary
private  java.util.ArrayList aExcludeList
          Contains a list of regular expressions to exclude while recording.
private  java.util.ArrayList aRegexes
          Contains regular expressions recorded with a test case.
private  boolean bEndProxy
          Inidicates whether the proxy has finished recording.
private  boolean bPostRedirect
          Indicates whether a POST request resulted in a redirect request.
private  boolean bRecord
          Indicates whether the proxy is recording a test case.
private  boolean bSSL
          Indicates whether the user attempted to make an SSL connection.
private  java.util.HashMap hHeaders
          Contains HTTP headers sent by the browser.
private  java.util.HashMap hServerTypes
          Indicates the type of webserver being accessed.
private static int iAllowedTries
          The number of allowed tries for reading data from a socket.
private static int iDefaultPort
          The default port to use for HTTP connections.
private static int iDefaultTimeout
          The default timeout value for HTTP connections.
private static int iHeaderLimit
          The minimum allowed length for http headers before they will be parsed.
private static int iHttpError
          The value at which HTTP return codes indicate an error.
private static int iHttpPort
          The default port for HTTP connections.
private static int iMinTokenLength
          The minimum length for a token to be recorded as a regular expression.
private  java.io.DataInputStream input
          Used to retrieve information from the browser.
private static int iNumTries
          The number of times to attempt to read an http response.
private static int iPostRedirect
          HTTP status code which indicates a POST redirect.
private static int iRequestLineLimit
          The number of lines to read from an incoming HTTP response for header info.
private static int iReturnCodeIndex
          The index to use when retrieving the HTTP status code.
private static int iSleepTime
          How long to wait between attempts to read an http response.
private static int iSocketTimeout
          The default timeout for http connections.
private static int iSSLPort
          The default port for SSL connections.
private static int iTestCaseIndex
          The starting index to use when parsing the test case name.
private static int iURLStartIndex
          The starting index to use when parsing URLs.
private  java.io.PrintStream output
          Used to send information to the browser.
private  java.lang.String sConfigFile
          The configuration file being written.
private  java.lang.String sData
          The data sent with the URL accessed.
private  java.lang.String sExcludeFile
          A file which contains a list of regexes to be excluded while recording.
private  java.lang.String sHost
          The host being contacted for the HTTP request.
private  java.lang.String sMethod
          The method associated with the URL accessed.
private  java.lang.String sParsedHeaders
          Contains the HTTP header information.
private  java.lang.String sSeparator
          The path separator for the OS on which this application is executing.
private  java.lang.String sTestcaseName
          The name of the test case being accessed.
private  java.lang.String sURL
          The URL being accessed.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
fastProxyHandler()
          The default constructor for the class, which takes no arguments.
fastProxyHandler(java.io.InputStream in, java.io.OutputStream out)
          Get the input/output streams for the browser.
 
Method Summary
private  java.lang.String fixHeaders(java.lang.String sHeader)
          Fix the HTTP headers so that microsoft webservers won't return errors.
 boolean getEndProxy()
          A boolean value which determines whether or not the proxy should exit and generate a config file.
 java.lang.String getParsedHeaders()
          Return the headers that were set previously.
 boolean getPostRedirect()
          Retrieve the value which indicates if a POST redirect request was encountered.
 boolean getRecordOn()
          Indicates whether a testcase is currently being recorded.
private  boolean getServerType()
          Determine the server type.
 java.util.HashMap getServerTypes()
          Return the server type information.
 boolean getSSL()
          Indicates whether the user tried to access an SSL connection.
 java.lang.String getTestcaseName()
          Return the currently assigned testcase name.
 java.lang.String getURL()
          Return the last URL accessed.
private  void parseHeaders(java.lang.String sStr)
          Parse the request headers into a hashmap.
 void run()
          The method used to start this thread.
private  void sendRequest(byte[] b)
          Send the browser request to the specified host, then read the response data.
 void setData(java.lang.String sVal)
          Set the data that will be used to generate the config file.
 void setExcludeFile(java.lang.String sFile)
          Set the name of the file which needs to be read to determine regexes that should NOT appear.
 void setParsedHeaders(java.lang.String sStr)
          Set the HTTP headers.
 void setPostRedirect(boolean bVal)
          Set the value which indicates if a POST redirect request was encountered.
 void setRecordOn(boolean bVal)
          Sets the value to indicate whether a testcase is being recorded.
 void setSeparator(java.lang.String sVal)
          Set the path separator so that the correct classpath can be displayed to the user.
 void setServerTypes(java.util.HashMap hData)
          Set the server type information.
 void setTestcaseName(java.lang.String sStr)
          Assign the current test case name a new value.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

input

private java.io.DataInputStream input
Used to retrieve information from the browser.


output

private java.io.PrintStream output
Used to send information to the browser.


hHeaders

private java.util.HashMap hHeaders
Contains HTTP headers sent by the browser.


hServerTypes

private java.util.HashMap hServerTypes
Indicates the type of webserver being accessed.


sHost

private java.lang.String sHost
The host being contacted for the HTTP request.


sMethod

private java.lang.String sMethod
The method associated with the URL accessed.


sData

private java.lang.String sData
The data sent with the URL accessed.


sURL

private java.lang.String sURL
The URL being accessed.


sParsedHeaders

private java.lang.String sParsedHeaders
Contains the HTTP header information.


sTestcaseName

private java.lang.String sTestcaseName
The name of the test case being accessed.


sExcludeFile

private java.lang.String sExcludeFile
A file which contains a list of regexes to be excluded while recording.


sConfigFile

private java.lang.String sConfigFile
The configuration file being written.


sSeparator

private java.lang.String sSeparator
The path separator for the OS on which this application is executing.


aRegexes

private java.util.ArrayList aRegexes
Contains regular expressions recorded with a test case.


aExcludeList

private java.util.ArrayList aExcludeList
Contains a list of regular expressions to exclude while recording.


bRecord

private boolean bRecord
Indicates whether the proxy is recording a test case.


bEndProxy

private boolean bEndProxy
Inidicates whether the proxy has finished recording.


bPostRedirect

private boolean bPostRedirect
Indicates whether a POST request resulted in a redirect request.


bSSL

private boolean bSSL
Indicates whether the user attempted to make an SSL connection.


iDefaultTimeout

private static final int iDefaultTimeout
The default timeout value for HTTP connections.

See Also:
Constant Field Values

iAllowedTries

private static final int iAllowedTries
The number of allowed tries for reading data from a socket.

See Also:
Constant Field Values

iDefaultPort

private static final int iDefaultPort
The default port to use for HTTP connections.

See Also:
Constant Field Values

iRequestLineLimit

private static final int iRequestLineLimit
The number of lines to read from an incoming HTTP response for header info.

See Also:
Constant Field Values

iReturnCodeIndex

private static final int iReturnCodeIndex
The index to use when retrieving the HTTP status code.

See Also:
Constant Field Values

iHttpError

private static final int iHttpError
The value at which HTTP return codes indicate an error.

See Also:
Constant Field Values

iPostRedirect

private static final int iPostRedirect
HTTP status code which indicates a POST redirect.

See Also:
Constant Field Values

iMinTokenLength

private static final int iMinTokenLength
The minimum length for a token to be recorded as a regular expression.

See Also:
Constant Field Values

iHttpPort

private static final int iHttpPort
The default port for HTTP connections.

See Also:
Constant Field Values

iSocketTimeout

private static final int iSocketTimeout
The default timeout for http connections.

See Also:
Constant Field Values

iNumTries

private static final int iNumTries
The number of times to attempt to read an http response.

See Also:
Constant Field Values

iSleepTime

private static final int iSleepTime
How long to wait between attempts to read an http response.

See Also:
Constant Field Values

iURLStartIndex

private static final int iURLStartIndex
The starting index to use when parsing URLs.

See Also:
Constant Field Values

iTestCaseIndex

private static final int iTestCaseIndex
The starting index to use when parsing the test case name.

See Also:
Constant Field Values

iHeaderLimit

private static final int iHeaderLimit
The minimum allowed length for http headers before they will be parsed.

See Also:
Constant Field Values

iSSLPort

private static final int iSSLPort
The default port for SSL connections.

See Also:
Constant Field Values
Constructor Detail

fastProxyHandler

public fastProxyHandler(java.io.InputStream in,
                        java.io.OutputStream out)
Get the input/output streams for the browser.

Parameters:
in - the browser input stream
out - the browser output stream

fastProxyHandler

public fastProxyHandler()
The default constructor for the class, which takes no arguments.

Method Detail

getTestcaseName

public java.lang.String getTestcaseName()
Return the currently assigned testcase name.

Returns:
a String which contains the test case name

getPostRedirect

public boolean getPostRedirect()
Retrieve the value which indicates if a POST redirect request was encountered.

Returns:
FALSE if the request was not encountered

setPostRedirect

public void setPostRedirect(boolean bVal)
Set the value which indicates if a POST redirect request was encountered.

Parameters:
bVal - the boolean value to use for assignment

setTestcaseName

public void setTestcaseName(java.lang.String sStr)
Assign the current test case name a new value.

Parameters:
sStr - the current test case name

getEndProxy

public boolean getEndProxy()
A boolean value which determines whether or not the proxy should exit and generate a config file.

Returns:
FALSE if the proxy has not finished recording

getRecordOn

public boolean getRecordOn()
Indicates whether a testcase is currently being recorded.

Returns:
FALSe if a test case is not being recorded

getSSL

public boolean getSSL()
Indicates whether the user tried to access an SSL connection.

Returns:
FALSE if the user did not try to access a connection via SSL

setSeparator

public void setSeparator(java.lang.String sVal)
Set the path separator so that the correct classpath can be displayed to the user.

Parameters:
sVal - the value for the path separator

setRecordOn

public void setRecordOn(boolean bVal)
Sets the value to indicate whether a testcase is being recorded.

Parameters:
bVal - the value for the parameter

setExcludeFile

public void setExcludeFile(java.lang.String sFile)
Set the name of the file which needs to be read to determine regexes that should NOT appear.

Parameters:
sFile - the name of the exclude file

setData

public void setData(java.lang.String sVal)
Set the data that will be used to generate the config file.

Parameters:
sVal - the data used to generate the config file

getURL

public java.lang.String getURL()
Return the last URL accessed.

Returns:
a String which denotes the last URL accessed

getServerTypes

public java.util.HashMap getServerTypes()
Return the server type information.

Returns:
a HashMap that contains information on webserver types

setServerTypes

public void setServerTypes(java.util.HashMap hData)
Set the server type information.

Parameters:
hData - contains information on webserver types

getParsedHeaders

public java.lang.String getParsedHeaders()
Return the headers that were set previously.

Returns:
a String that contains the header information

setParsedHeaders

public void setParsedHeaders(java.lang.String sStr)
Set the HTTP headers.

Parameters:
sStr - the HTTP header values

parseHeaders

private void parseHeaders(java.lang.String sStr)
Parse the request headers into a hashmap.

Parameters:
sStr - the header data represented as a String

getServerType

private boolean getServerType()
Determine the server type.

Returns:
FALSE if the server is NOT a microsoft server

sendRequest

private void sendRequest(byte[] b)
Send the browser request to the specified host, then read the response data.

Parameters:
b - an array of bytes to send to the webserver

fixHeaders

private java.lang.String fixHeaders(java.lang.String sHeader)
Fix the HTTP headers so that microsoft webservers won't return errors.

Parameters:
sHeader - the header data from the browser
Returns:
a String containing the modified header data

run

public void run()
The method used to start this thread.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread