All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.extropia.net.JavaCGIBridge

java.lang.Object
   |
   +----java.util.Observable
           |
           +----com.extropia.net.JavaCGIBridge

public class JavaCGIBridge
extends Observable
implements Runnable
This is a class that POSTS and GETS data from URLs using various helper methods. This class also provides the capability of timing out if the connection takes too long to transfer data by using threads to monitor whether the data is taking too long to transfer (implements Runnable).

Helper methods allow you to set up form variables, get setup information over a URL, get raw or pre-parsed HTML data, and more.

The getParsedData method relies on instance variables which tell the parser where the data begins and ends (top and bottom separators respectively). The field and row separators inform the parser where records and fields end.

The default start of data separator is <!--start of data-->\n

The default end of data separator is <!--end of data-->\n

The default field separator is | (pipe).

The default record separator is \n (newline).

If the data you are sending is likely to contain special characters such as newlines in database fields or | symbols, you can expand the record and field separators to be more restrictive. For example, you might consider making the field seperator ~|~ (tilde + pipe + tilde) if you think a stray pipe might appear somewhere.

Another strategy is to follow a MIME like strategy where you make very long separators that are very unlikely to appear randomly in binary or large database field data. An example separator string might be "__CabbageNeck_Peter_Joe_Erik_Mark_Anthony_David_987XxX". However, be aware that although longer separator strings provide more security against random stray characters matching, they will also increase the parsing time.

Version:
2.00, 18 Jul 1998
Author:
Gunther Birznieks, Marty Hall

Variable Index

 o _endDataSeparator
The bottom of data separator.
 o _fetchCount
This lets us know at what point fetchNextRecord() needs to read the next Vector.
 o _fieldSeparator
The field separator.
 o _parseAsRaw
_parseAsRaw is a flag that indicates whether the Vector of Vectors will contain fields as traditional Java Strings (false, the default) or raw binary byte arrays (true).
 o _parseDataAsVector
_parseDataAsVector is a flag letting the HTTP parser know to parse data on the fly as it is coming in.
 o _parsedNotifyInterval
This is the number of parsed lines before notifying observers of the latest batch of parsed Vector records.
 o _processingStatus
This integer holds the current processing status of the class.
 o _rawNotifyInterval
This is the number of raw data bytes (usually HTML chars) before notifying observers of the latest batch of raw data.
 o _recordSeparator
The record separator.
 o _serialObjectStream
This is an object stream that contains a decorator for the byte stream which contains serialized objects for POSTing.
 o _serialStream
This is a byte stream that contains object serialization data in-memory.
 o _startDataSeparator
The top of data separator.
 o _thread
This is a handle to the currently running communications thread.
 o _threadBaseTime
This variable contains the base time that the thread last received valid data.
 o _threadCompleted
This is a flag indicating whether the URL data was retrieved inside the thread or not.
 o _threadFormVar
The HTML form data for the URL that data is retrieved from.
 o _threadIdleAtEnd
_threadIdleAtEnd sets the object in the IDLE state automatically when a callOneWay() is used to launch an HTTP session.
 o _threadOneWay
_threadOneWay tells the run() method whether it was launched from an asynchronous method such as callOneWay() or a synchronous method such as getRawData().
 o _threadRawData
This is the returned URL data.
 o _threadTimeOut
This is the actual CGI Timeout value in milliseconds for the instantiated object.
 o _threadURL
The URL That data is retrieved from.
 o _vectorParsedData
This is the vector of vectors of parsed data.
 o IDLE
IDLE indicates that the JavaCGIBridge object has finished processing and can move on to do something else.
 o PROCESSING
PROCESSING indicates that the JavaCGIBridge object is in the middle of processing a request.
 o SETUP
SETUP indicates that the processing status is in setup mode.

Constructor Index

 o JavaCGIBridge()
Constructs the object with no initialization.
 o JavaCGIBridge(String, String, String, String)
Constructs the object with new separator values

Method Index

 o _getBytes(String)
This private routine converts strings to byte arrays in a way that is more convenient than the traditional JDK 1.0.2 method.
 o _getData(URL, Hashtable)
Starts up the communications thread and gets the data from it in a synchronous manner.
 o _getHttpRequestInThread(URL, Hashtable)
Returns the HTTP Request data to the thread that was launched to GET/POST data for a URL.
 o _getIndex(ByteArrayOutputStream, byte[], int, int)
Retrieves the index in the ByteArrayOutputStream of where a string to search for is located.
 o _initJavaCGIBridge(String, String, String, String)
Initializes the object with new separator values.
 o _notifyObservers(Object, boolean)
Notifies the observers of the data that is being parsed or received in the communications thread.
 o addFormValue(Hashtable, String, String)
Adds a form variable, value pair to the passed Hashtable.
 o callOneWay(URL)
Calls the URL but returns immediately.
 o callOneWay(URL, boolean)
Calls the URL but returns immediately.
 o callOneWay(URL, Hashtable)
Calls the URL but returns immediately.
 o callOneWay(URL, Hashtable, boolean)
Calls the URL but returns immediately.
 o getEndDataSeparator()
Returns the end of data separator for the object.
 o getFieldSeparator()
Returns the field separator for the object.
 o getKeyValuePairs(Vector)
Takes the parsed data returned from the getParsedData method and changes it to a Hashtable of key, value pairs where the first Vector entry of each Vector record is the key and the rest of the second Vector entry for each record is the value of the Hashtable.
 o getParseAsRaw()
Returns true or false depending on whether the JavaCGIBridge will parse the fields in the HTTP response as Strings (default) or as raw data byte arrays.
 o getParsedData(URL)
Returns parsed data in the form of a Vector of Vectors containing the returned fields inside of a Vector of returned rows.
 o getParsedData(URL, Hashtable)
Returns parsed data in the form of a Vector of Vectors containing the returned fields inside of a Vector of returned rows.
 o getParsedNotifyInterval()
Returns an integer indicating the number of records which will trigger a notification to observers with the contents of what has been parsed so far.
 o getRawData(URL)
Returns raw HTML data as a String from the passed URL.
 o getRawData(URL, Hashtable)
Returns raw HTML data as a String from the passed URL and list of Form variable/value pairs stored in a Hashtable.
 o getRawNotifyInterval()
Returns an integer indicating the number of raw content bytes from the HTTP response which will trigger a notification to observers with the contents of what has been read so far.
 o getRecordSeparator()
Returns the record separator for the object.
 o getStartDataSeparator()
Returns the start of data separator for the object.
 o getStatus()
Returns the processing status of the JavaCGIBridge objects.
 o getTimeOut()
Returns the actual communication time out in milliseconds for the object.
 o getURLEncodedHashtable(Hashtable)
Returns the form variables inside the hashtable as a URL encoded string of parameters for a CGI based program to process.
 o run()
This run thread asynchronously POSTs and GETs data from a URL and places the contents into the _threadRawData variable.
 o setEndDataSeparator(String)
Sets the end of data separator for the object.
 o setFieldSeparator(String)
Sets the field separator for the object.
 o setParseAsRaw(boolean)
Sets the flag that indicates whether the JavaCGIBridge will parse the HTTP response data as raw byte array or as String (default).
 o setParsedNotifyInterval(int)
Sets an integer indicating the number of records which will trigger a notification to observers with the contents of what has been parsed so far.
 o setRawNotifyInterval(int)
Sets an integer indicating the number of raw content bytes from the HTTP response which will trigger a notification to observers with the contents of what has been read so far.
 o setRecordSeparator(String)
Sets the record separator for the object.
 o setStartDataSeparator(String)
Sets the start of data separator for the object.
 o setStatus(int)
Sets the processing status of the JavaCGIBridge object.
 o setTimeOut(int)
Sets the actual communication time out in milliseconds for the object.

Variables

 o SETUP
 public static final int SETUP
SETUP indicates that the processing status is in setup mode. This means that no communications have been established yet. In otherwords, the programmer is still setting up defaults.

See Also:
getStatus, setStatus
 o PROCESSING
 public static final int PROCESSING
PROCESSING indicates that the JavaCGIBridge object is in the middle of processing a request.

See Also:
getStatus, setStatus
 o IDLE
 public static final int IDLE
IDLE indicates that the JavaCGIBridge object has finished processing and can move on to do something else. Usually this means that the JavaCGIBridgePool object can give this instance to another consumer now that it is done with the request.

See Also:
getStatus, setStatus
 o _vectorParsedData
 protected Vector _vectorParsedData
This is the vector of vectors of parsed data. It is protected so that fetchNextRecord() can peep it in the JavaCGIBridgeExtension class.

 o _threadTimeOut
 protected int _threadTimeOut
This is the actual CGI Timeout value in milliseconds for the instantiated object. Notice that the default value is a static class variable that applies across all instances of this class. This variable, on the other hand, is the actual value the object uses.

It is protected so that the other JavaCGIBridge-type classes can also detect whether a JavaCGIBridge object has timed out.

 o _threadCompleted
 protected boolean _threadCompleted
This is a flag indicating whether the URL data was retrieved inside the thread or not. It is protected so that other JavaCGIBridge-type classes can figure out if a JavaCGIBridge object has timed out.

 o _fetchCount
 protected int _fetchCount
This lets us know at what point fetchNextRecord() needs to read the next Vector. This variable is located here so that it can be manipulated by the communications thread as it parses Vector data for consumption by fetchNextRecord().

 o _threadBaseTime
 protected long _threadBaseTime
This variable contains the base time that the thread last received valid data. The base time basically tells the object how much time has past between successful communications when compared with System.currentTimeMillis(). It is protected so that other JavaCGIBridge-type objects can figure out whether a JavaCGIBridge object has timed out.

 o _thread
 protected Thread _thread
This is a handle to the currently running communications thread. It is protected so that the JavaCGIBridgePool objects can stop timed out threads in its clean up thread.

 o _serialStream
 protected ByteArrayOutputStream _serialStream
This is a byte stream that contains object serialization data in-memory. It is protected so that it can be accessed by the serialization API methods in JavaCGIBridgeExtension class.

 o _serialObjectStream
 protected ObjectOutputStream _serialObjectStream
This is an object stream that contains a decorator for the byte stream which contains serialized objects for POSTing. It is protected so that its contents can be accessed by the serialization API methods in the JavaCGIBridgeExtension class.

 o _fieldSeparator
 private byte _fieldSeparator[]
The field separator. When a CGI script or HTML file returns data, then the getParsedData() method will know how to separate fields by looking at this variable. The default value is "|" (pipe). This is considered sufficiently unlikely to appear inside of actual field data that it is a pretty good field separator to parse on. If the user of this class needs a different separator, it may be overridden by calling the appropriate method.

 o _recordSeparator
 private byte _recordSeparator[]
The record separator. When a CGI script or HTML file returns data, then the getParsedData() method will know how to separate returned rows by looking at this variable. The default value is "\n" (newline). This is considered sufficiently unlikely to appear inside of actual row data that it is a pretty good row separator to parse on. If the user of this class needs a different separator, it may be overridden by calling the appropriate method.

 o _startDataSeparator
 private byte _startDataSeparator[]
The top of data separator. When a CGI script or HTML file returns data, then the getParsedData() method will determine when to start parsing data by encountering this separator. The default value is "\n" including a a newline. That is, a newline is generally expected to follow this separator.

 o _endDataSeparator
 private byte _endDataSeparator[]
The bottom of data separator. When a CGI script or HTML file returns data, then the getParsedData() method will determine when to stop parsing data by encountering this separator. The default value is "\n" including a newline. That is, a newline is generally expected to follow this separator.

 o _threadURL
 private URL _threadURL
The URL That data is retrieved from. This is an instance variable rather than a parameter because the data retrieval is done from a launched thread which gets no parameters.

 o _threadFormVar
 private Hashtable _threadFormVar
The HTML form data for the URL that data is retrieved from. This is an instance variable rather than a parameter because the data retrieval is done from a launched thread which gets no parameters.

 o _threadRawData
 private byte _threadRawData[]
This is the returned URL data. It is an instance variable because the run() method of the thread cannot explicitly return data.

 o _parseDataAsVector
 private boolean _parseDataAsVector
_parseDataAsVector is a flag letting the HTTP parser know to parse data on the fly as it is coming in.

 o _parseAsRaw
 private boolean _parseAsRaw
_parseAsRaw is a flag that indicates whether the Vector of Vectors will contain fields as traditional Java Strings (false, the default) or raw binary byte arrays (true).

 o _threadIdleAtEnd
 private boolean _threadIdleAtEnd
_threadIdleAtEnd sets the object in the IDLE state automatically when a callOneWay() is used to launch an HTTP session. This value is generally set to true by default, but it will be set to false if the user calls the callOneWay() method by telling it that they intend to call fetchNextRecord(). The reason this is done is that it is possible, in a multi threaded environment that fetchNextRecord() might be called after the whole HTTP session has finished. In this case, another thread might easily reuse the JavaCGIBridge object in the IDLE state before fetchNextRecord() was called. Therefore, it is imperative that if you intend to use fetchNextRecord() that you tell the callOneWay() function you intend to do so.

 o _threadOneWay
 private boolean _threadOneWay
_threadOneWay tells the run() method whether it was launched from an asynchronous method such as callOneWay() or a synchronous method such as getRawData(). _threadOneWay == true if it was launched from an asynchronous method.

 o _parsedNotifyInterval
 private int _parsedNotifyInterval
This is the number of parsed lines before notifying observers of the latest batch of parsed Vector records. The default is 0 (no notification).

See Also:
getParsedNotifyInterval, setParsedNotifyInterval
 o _rawNotifyInterval
 private int _rawNotifyInterval
This is the number of raw data bytes (usually HTML chars) before notifying observers of the latest batch of raw data. The default is 0 (no notification).

See Also:
getRawNotifyInterval, setRawNotifyInterval
 o _processingStatus
 private int _processingStatus
This integer holds the current processing status of the class. Its value is either SETUP (1), PROCESSING (2), or IDLE (3).

Constructors

 o JavaCGIBridge
 public JavaCGIBridge(String field,
                      String record,
                      String startData,
                      String endData)
Constructs the object with new separator values

 o JavaCGIBridge
 public JavaCGIBridge()
Constructs the object with no initialization. This is the default (empty) constructor.

Methods

 o addFormValue
 public void addFormValue(Hashtable ht,
                          String formKey,
                          String formValue)
Adds a form variable, value pair to the passed Hashtable.

Parameters:
ht - the Hashtable that contains the form variable/value pairs
formKey - the String that contains the form variable to add
formValue - the String that contains the form value to add
 o getKeyValuePairs
 public Hashtable getKeyValuePairs(Vector vectorOfVectors)
Takes the parsed data returned from the getParsedData method and changes it to a Hashtable of key, value pairs where the first Vector entry of each Vector record is the key and the rest of the second Vector entry for each record is the value of the Hashtable.

Parameters:
vectorOfVectors - the Vector of Vectors for the parsed data
Returns:
Hashtable containing converted variable/value pairs
See Also:
getParsedData
 o getParsedData
 public Vector getParsedData(URL u) throws JavaCGIBridgeTimeOutException
Returns parsed data in the form of a Vector of Vectors containing the returned fields inside of a Vector of returned rows.

Parameters:
u - URL to get parsed data from.
Returns:
Vector (records) of vectors (fields) of parsed data
Throws: JavaCGIBridgeTimeOutException
If the retrieval times out
See Also:
getRawData, callOneWay, getParseAsRaw, setParseAsRaw, getParsedNotifyInterval, setParsedNotifyInterval
 o getParsedData
 public Vector getParsedData(URL u,
                             Hashtable ht) throws JavaCGIBridgeTimeOutException
Returns parsed data in the form of a Vector of Vectors containing the returned fields inside of a Vector of returned rows. This form POSTs the HTML Form variable data to the URL.

Parameters:
u - URL to get parsed data from.
ht - Hashtable contains form variables to POST
Returns:
Vector (records) of vectors (fields) of parsed data
Throws: JavaCGIBridgeTimeOutException
If the retrieval times out
See Also:
getRawData, callOneWay, getParseAsRaw, setParseAsRaw, getParsedNotifyInterval, setParsedNotifyInterval
 o getRawData
 public byte[] getRawData(URL u) throws JavaCGIBridgeTimeOutException
Returns raw HTML data as a String from the passed URL.

Parameters:
u - URL to get raw HTML from.
Returns:
String containing plain HTML text
Throws: JavaCGIBridgeTimeOutException
If the retrieval times out
See Also:
getParsedData, callOneWay, getRawNotifyInterval, setRawNotifyInterval
 o getRawData
 public byte[] getRawData(URL u,
                          Hashtable ht) throws JavaCGIBridgeTimeOutException
Returns raw HTML data as a String from the passed URL and list of Form variable/value pairs stored in a Hashtable. This form POSTs the HTML Form variable data to the URL.

Parameters:
u - URL to get raw HTML from.
ht - Hashtable contains form variables to POST
Returns:
String containing plain HTML text
Throws: JavaCGIBridgeTimeOutException
If the retrieval times out
See Also:
getParsedData, callOneWay, getRawNotifyInterval, setRawNotifyInterval
 o callOneWay
 public void callOneWay(URL u)
Calls the URL but returns immediately. This is called a ONEWAY operation. This method is used in one of three circumstances.

[1] You want to "fire and forget" an operation such as an update to a file or database on the web server without worrying about a return code or whether the operation even succedded.

[2] You want to set up an observer interface to the bridge to notify yourself as data comes in instead of blocking the whole program while waiting for the data.

[3] You want to call fetchNextRecord method in the JavaCGIBridgeExtension class. Basically, the callOneWay() operation returns immediately so that it leaves your program free to loop through the fetchNextRecord() method. Note that if you use callOneWay for this purpose, it is recommended that you call the version where you set "fetchData" equal to true so that the Object is not set to the IDLE state prematurely. This is discussed in further detail in the documentation for fetchNextRecord() in the JavaCGIBridgeExtension class.

Parameters:
u - URL to get raw HTML from.
See Also:
getRawData, getParsedData, getRawNotifyInterval, setRawNotifyInterval, getParsedNotifyInterval, setParsedNotifyInterval
 o callOneWay
 public void callOneWay(URL u,
                        boolean fetchData)
Calls the URL but returns immediately. This is called a ONEWAY operation. This method is used in one of three circumstances.

[1] You want to "fire and forget" an operation such as an update to a file or database on the web server without worrying about a return code or whether the operation even succedded.

[2] You want to set up an observer interface to the bridge to notify yourself as data comes in instead of blocking the whole program while waiting for the data.

[3] You want to call fetchNextRecord method in the JavaCGIBridgeExtension class. Basically, the callOneWay() operation returns immediately so that it leaves your program free to loop through the fetchNextRecord() method. Note that if you use callOneWay for this purpose, it is recommended that you call the version where you set "fetchData" equal to true so that the Object is not set to the IDLE state prematurely. This is discussed in further detail in the documentation for fetchNextRecord() in the JavaCGIBridgeExtension class.

Parameters:
u - URL to get raw HTML from.
fetchData - Set to true if you intend to use the fetchNextRecord() method. This avoids the thread automatically setting the state of the object to IDLE when the thread completes. This is necessary because it is possible that fetchNextRecord has not completed fetching all the records by the time the communications thread ends.
See Also:
getRawData, getParsedData, getRawNotifyInterval, setRawNotifyInterval, getParsedNotifyInterval, setParsedNotifyInterval
 o callOneWay
 public void callOneWay(URL u,
                        Hashtable ht)
Calls the URL but returns immediately. This is called a ONEWAY operation. This method is used in one of three circumstances.

[1] You want to "fire and forget" an operation such as an update to a file or database on the web server without worrying about a return code or whether the operation even succedded.

[2] You want to set up an observer interface to the bridge to notify yourself as data comes in instead of blocking the whole program while waiting for the data.

[3] You want to call fetchNextRecord method in the JavaCGIBridgeExtension class. Basically, the callOneWay() operation returns immediately so that it leaves your program free to loop through the fetchNextRecord() method. Note that if you use callOneWay for this purpose, it is recommended that you call the version where you set "fetchData" equal to true so that the Object is not set to the IDLE state prematurely. This is discussed in further detail in the documentation for fetchNextRecord() in the JavaCGIBridgeExtension class.

Parameters:
u - URL to get raw HTML from.
ht - Hashtable contains form variables to POST
See Also:
getRawData, getParsedData, getRawNotifyInterval, setRawNotifyInterval, getParsedNotifyInterval, setParsedNotifyInterval
 o callOneWay
 public void callOneWay(URL u,
                        Hashtable ht,
                        boolean fetchData)
Calls the URL but returns immediately. This is called a ONEWAY operation. This method is used in one of three circumstances.

[1] You want to "fire and forget" an operation such as an update to a file or database on the web server without worrying about a return code or whether the operation even succedded.

[2] You want to set up an observer interface to the bridge to notify yourself as data comes in instead of blocking the whole program while waiting for the data.

[3] You want to call fetchNextRecord method in the JavaCGIBridgeExtension class. Basically, the callOneWay() operation returns immediately so that it leaves your program free to loop through the fetchNextRecord() method. Note that if you use callOneWay for this purpose, it is recommended that you call the version where you set "fetchData" equal to true so that the Object is not set to the IDLE state prematurely. This is discussed in further detail in the documentation for fetchNextRecord() in the JavaCGIBridgeExtension class.

Parameters:
u - URL to get raw HTML from.
ht - Hashtable contains form variables to POST
fetchData - Set to true if you intend to use the fetchNextRecord() method. This avoids the thread automatically setting the state of the object to IDLE when the thread completes. This is necessary because it is possible that fetchNextRecord has not completed fetching all the records by the time the communications thread ends.
See Also:
getRawData, getParsedData, getRawNotifyInterval, setRawNotifyInterval, getParsedNotifyInterval, setParsedNotifyInterval
 o getTimeOut
 public int getTimeOut()
Returns the actual communication time out in milliseconds for the object. The default is 10 seconds. When the object retrieves data from a URL, it must get the data within timeout milliseconds or a JavaCGIBridgeTimeOutException is thrown.

Returns:
communication time out in milliseconds
See Also:
setTimeOut
 o setTimeOut
 public void setTimeOut(int t)
Sets the actual communication time out in milliseconds for the object. The default is 10 seconds. When the object retrieves data from a URL, it must get the data within timeout milliseconds or a JavaCGIBridgeTimeOutException is thrown.

Parameters:
t - communication time out in milliseconds
See Also:
getTimeOut
 o setFieldSeparator
 public void setFieldSeparator(String s)
Sets the field separator for the object. When getParsedData method is called, the object uses the field separator to determine where fields in a returned record of the raw HTML result set begin and end.

Parameters:
s - String containing new delimiting separator
See Also:
getParsedData, getFieldSeparator
 o getFieldSeparator
 public String getFieldSeparator()
Returns the field separator for the object. When getParsedData method is called, the object uses the field separator to determine where fields in a returned record of the raw HTML result set begin and end.

Returns:
Separator string
See Also:
getParsedData, setFieldSeparator
 o setRecordSeparator
 public void setRecordSeparator(String s)
Sets the record separator for the object. When getParsedData method is called, the object uses the record separator to determine where records/rows of the raw HTML result set begin and end.

Parameters:
s - String containing new delimiting separator
See Also:
getParsedData, getRecordSeparator
 o getRecordSeparator
 public String getRecordSeparator()
Returns the record separator for the object. When getParsedData method is called, the object uses the record separator to determine where records/rows of the raw HTML result set begin and end.

Returns:
Separator string
See Also:
getParsedData, setRecordSeparator
 o setStartDataSeparator
 public void setStartDataSeparator(String s)
Sets the start of data separator for the object. When getParsedData method is called, the object uses the start of data separator to determine where the rows of data inside the raw HTML output actually begin.

Parameters:
s - String containing new delimiting separator
See Also:
getParsedData, getStartDataSeparator
 o getStartDataSeparator
 public String getStartDataSeparator()
Returns the start of data separator for the object. When getParsedData method is called, the object uses the start of data separator to determine where the rows of data inside the raw HTML output actually begin.

Returns:
Separator string
See Also:
getParsedData, setStartDataSeparator
 o setEndDataSeparator
 public void setEndDataSeparator(String s)
Sets the end of data separator for the object. When getParsedData method is called, the object uses the end of data separator to determine where the rows of data inside the raw HTML output actually end.

Parameters:
s - String containing new delimiting separator
See Also:
getParsedData, getEndDataSeparator
 o getEndDataSeparator
 public String getEndDataSeparator()
Returns the end of data separator for the object. When getParsedData method is called, the object uses the end of data separator to determine where the rows of data inside the raw HTML output actually end.

Returns:
Separator string
See Also:
getParsedData, setEndDataSeparator
 o getParsedNotifyInterval
 public int getParsedNotifyInterval()
Returns an integer indicating the number of records which will trigger a notification to observers with the contents of what has been parsed so far. When this is set to a positive number, it will also notify when the records have finished being parsed at the end of the HTTP response. When this is set to a negative number, no periodic notifications will be sent, however one will be sent at the end of the HTTP response.

Returns:
int Number of records between parse notifications. Set to 0 to turn off parsing notification, Set to a negative number to only send notifications at the end.
See Also:
setParsedNotifyInterval
 o setParsedNotifyInterval
 public void setParsedNotifyInterval(int n)
Sets an integer indicating the number of records which will trigger a notification to observers with the contents of what has been parsed so far. When this is set to a positive number, it will also notify when the records have finished being parsed at the end of the HTTP response. When this is set to a negative number, no periodic notifications will be sent, however one will be sent at the end of the HTTP response.

Parameters:
n - Number of records between parse notifications. Set to 0 to turn off parsing notification, Set to a negative number to only send notifications at the end.
See Also:
getParsedNotifyInterval
 o getRawNotifyInterval
 public int getRawNotifyInterval()
Returns an integer indicating the number of raw content bytes from the HTTP response which will trigger a notification to observers with the contents of what has been read so far. When this is set to a positive number, it will also notify when the HTTP response has finished. When this is set to a negative number, no periodic notifications will be sent, however one will be sent at the end of the HTTP response.

Returns:
int Number of bytes between notifications. Set to 0 to turn off notification after lines of HTML sent in the HTTP response, Set to a negative number to only send notifications at the end.
See Also:
setRawNotifyInterval
 o setRawNotifyInterval
 public void setRawNotifyInterval(int n)
Sets an integer indicating the number of raw content bytes from the HTTP response which will trigger a notification to observers with the contents of what has been read so far. When this is set to a positive number, it will also notify when the HTTP response has finished. When this is set to a negative number, no periodic notifications will be sent, however one will be sent at the end of the HTTP response.

Parameters:
n - Number of bytes between notifications. Set to 0 to turn off notification after bytes of HTML sent in the HTTP response, Set to a negative number to only send notifications at the end.
See Also:
getRawNotifyInterval
 o getParseAsRaw
 public boolean getParseAsRaw()
Returns true or false depending on whether the JavaCGIBridge will parse the fields in the HTTP response as Strings (default) or as raw data byte arrays. Use byte arrays if you public void setRawNotifyInterval(int n) { _rawNotifyInterval = n; } /** Returns true or false depending on whether the JavaCGIBridge will parse the fields in the HTTP response as Strings (default) or as raw data byte arrays. Use byte arrays if you will be transferring binary data such as a jpeg or gif image.

Returns:
boolean Flag indicating parsing as raw byte array or as Strings
See Also:
setParseAsRaw
 o setParseAsRaw
 public void setParseAsRaw(boolean b)
Sets the flag that indicates whether the JavaCGIBridge will parse the HTTP response data as raw byte array or as String (default).

Parameters:
b - Flag indicating true or false
See Also:
getParseAsRaw
 o getStatus
 public int getStatus()
Returns the processing status of the JavaCGIBridge objects. It will be equal to SETUP (1), PROCESSING (2), or IDLE (3) public static class variables.

Returns:
int Status code
See Also:
setStatus
 o setStatus
 public void setStatus(int status)
Sets the processing status of the JavaCGIBridge object. You will set it to SETUP (1), PROCESSING (2), or IDLE (3) public static class variables.

Parameters:
status - Status code
See Also:
getStatus
 o run
 public void run()
This run thread asynchronously POSTs and GETs data from a URL and places the contents into the _threadRawData variable. Since Threads do not return or pass parameter values, instance variables in this object are used to maintain state. This method is only public so that the Thread class can launch the thread.

See Also:
getRawData
 o getURLEncodedHashtable
 public String getURLEncodedHashtable(Hashtable ht)
Returns the form variables inside the hashtable as a URL encoded string of parameters for a CGI based program to process.

Parameters:
ht - Hashtable containing form variables
Returns:
URLencoded string of HTML form variables & values
See Also:
addFormValue
 o _getHttpRequestInThread
 private byte[] _getHttpRequestInThread(URL u,
                                        Hashtable ht) throws JavaCGIBridgeTimeOutException
Returns the HTTP Request data to the thread that was launched to GET/POST data for a URL. This is a private method.

Parameters:
u - URL to retrieve and post data for
ht - Form variables to send to URL
Returns:
String containing retrieved HTML text
Throws: JavaCGIBridgeTimeOutException
If the retrieval times out
See Also:
run
 o _getIndex
 private int _getIndex(ByteArrayOutputStream baos,
                       byte toLookFor[],
                       int begin,
                       int end)
Retrieves the index in the ByteArrayOutputStream of where a string to search for is located. The current algorithm is based loosely off of the code in String.indexOf in the java.lang.String source code.

 o _notifyObservers
 private void _notifyObservers(Object o,
                               boolean endOfData) throws JavaCGIBridgeTimeOutException
Notifies the observers of the data that is being parsed or received in the communications thread. It constructs a JavaCGIBridgeNotify object to send the information including whether or not the JavaCGIBridge timed out or whether the end of data has been reached.

Parameters:
o - Object containing data to send out such as the latest Vector or the latest byte array of data.
endOfData - indicates whether the end of data was reached
Throws: JavaCGIBridgeTimeOutException
If the retrieval times out
 o _initJavaCGIBridge
 private void _initJavaCGIBridge(String field,
                                 String record,
                                 String startData,
                                 String endData)
Initializes the object with new separator values. It is called from the constructors of this object.

Parameters:
field - Field separator
record - Record separator
startData - Start of Data separator
endData - End of Data separator
 o _getData
 private void _getData(URL u,
                       Hashtable ht) throws JavaCGIBridgeTimeOutException
Starts up the communications thread and gets the data from it in a synchronous manner. Thus, this method blocks until it gets all the data. It also implements a timeout mechanism using wait() and notify(). It is basically the same as Thread.join() except that it fixes the broken Thread.join() implementation in Netscape browsers.

Parameters:
u - URL to get parsed data from.
ht - Hashtable contains form variables to POST
Throws: JavaCGIBridgeTimeOutException
If the retrieval times out
See Also:
getParsedData, getRawData
 o _getBytes
 private byte[] _getBytes(String s)
This private routine converts strings to byte arrays in a way that is more convenient than the traditional JDK 1.0.2 method. In otherwords, this is a wrapper for the more complex version of the String to byte array converter method.

Parameters:
s - String to convert to bytes
Returns:
byte[] converted byte array

All Packages  Class Hierarchy  This Package  Previous  Next  Index