All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.extropia.net.JavaCGIBridgeExtension

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

public class JavaCGIBridgeExtension
extends JavaCGIBridge
This class extends the core JavaCGIBridge class. It contains helper methods which may be useful for programmers communicating with a web server in a browser environment, but are not as likely to be used by every applet.

The main helper method subsets are as follows:

[1] Serialization Support. Applets can send serialized Objects to and from a Web Server. Typically this will be used with CGI programs written in Java or with Java Servlets. However, serialization can also be a useful way of storing an applet's state on the server. In this case, another language such as Perl can easily serve as a conduit through which the serialized objects are stored as files on the web server.

[2] fetch records support. Typically, you will get all the records at once with getParsedData() or use the observer interface to keep track of records as they are parsed on the fly. However, if the observer interface seems like it is too much overhead to set up, the fetchNextRecord() method provides an intermediate alternative to getting all the records at the end of the entire response and the overhead of setting up an observer interface in your applet.

[3] show document support. Mac Netscape 3.x and below have a bug in the showDocument method. The show document method here provides a cross-browser way of displaying other HTML pages. For more information on Cross-Browser Bugs, view the web site devoted to these topics at http://gunther.web66.com/crossjava/.

In addition, show document also supports passing the JavaCGIBridge form variables Hashtable data structure. JavaCGIBridgeExtension's showDocument() method will automatically URL encoded and add the form variables to the URL so that a CGI program can be called with the GET method from showDocument().

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


Variable Index

 o _showDocCount
long which contains a runnning counter of how many documents have been shown with the showDocument() method.

Constructor Index

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

Method Index

 o fetchNextRecord()
Obtains a Vector containing the fields of the individual record returned from parsing the records currently being processed by the JavaCGIBridge object.
 o getByteArrayOutputStream()
Obtains a ByteArrayOutputStream.
 o getObjectData(URL)
Obtains an ObjectInputStream that encapsulates the stream of data being returned from the web server.
 o getObjectData(URL, Hashtable)
Obtains an ObjectInputStream that encapsulates the stream of data being returned from the web server.
 o getObjectOutputStream()
Obtains an ObjectOutputStream.
 o showDocument(AppletContext, URL, String)
Tells the browser to show a document.
 o showDocument(AppletContext, URL, String, Hashtable)
Tells the browser to show a document.
 o showDocument(AppletContext, URL, String, Hashtable, boolean)
Tells the browser to show a document.

Variables

 o _showDocCount
 private static long _showDocCount
long which contains a runnning counter of how many documents have been shown with the showDocument() method. This is done to resolve a bug in Mac Netscape 3.0 showDocument() method.

See Also:
showDocument

Constructors

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

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

Methods

 o getByteArrayOutputStream
 public ByteArrayOutputStream getByteArrayOutputStream() throws IOException
Obtains a ByteArrayOutputStream. This is used to store raw data to send to a CGI Script. A more advanced version of this method is getObjectOutputStream which is used to send serialized objects as binary data over a byte array output stream. You can use this method to bypass posting data with normal URLEncoded data. This can be useful to post binary data to a CGI script which will decode it in whatever way you choose to program the parser.

Returns:
ByteArrayOutputStream
See Also:
getObjectOutputStream
 o getObjectOutputStream
 public ObjectOutputStream getObjectOutputStream() throws IOException
Obtains an ObjectOutputStream. This is used to store the objects which will be serialized and streamed to the web server.

Example Usage:

 JavaCGIBridgeExtension jcbe = new JavaCGIBridgeExtension();
 ObjectOutputStream oos = jcbe.getObjectOutputStream();
 oos.writeObject(myFirstObject);
 oos.writeObject(mySecondObject);
 oos.close();
 ObjectInputStream ois = jcbe.getObjectData(myURL);
 

Returns:
ObjectOutputStream
See Also:
getObjectData
 o getObjectData
 public ObjectInputStream getObjectData(URL u) throws JavaCGIBridgeTimeOutException, StreamCorruptedException, IOException
Obtains an ObjectInputStream that encapsulates the stream of data being returned from the web server.

It follows the same basic syntax of getRawData() and getParsedData() methods from the core JavaCGIBridge class.

Parameters:
u - URL to get object data from
Returns:
ObjectInputStream data stream to deserialize objects from
Throws: JavaCGIBridgeTimeOutException
If the retrieval times out
Throws: StreamCorruptedException
If something is wrong with the stream of serialized objects.
Throws: IOException
If there is something wrong with the stream other than being in the wrong format for retrieving serialized objects.
 o getObjectData
 public ObjectInputStream getObjectData(URL u,
                                        Hashtable ht) throws JavaCGIBridgeTimeOutException, StreamCorruptedException, IOException
Obtains an ObjectInputStream that encapsulates the stream of data being returned from the web server.

It follows the same basic syntax of getRawData() and getParsedData() methods from the core JavaCGIBridge class.

Parameters:
u - URL to get object data from
ht - Hashtable containing form variables to POST
Returns:
ObjectInputStream data stream to deserialize objects from
Throws: JavaCGIBridgeTimeOutException
If the retrieval times out
Throws: StreamCorruptedException
If something is wrong with the stream of serialized objects.
Throws: IOException
If there is something wrong with the stream other than being in the wrong format for retrieving serialized objects.
 o fetchNextRecord
 public Vector fetchNextRecord() throws JavaCGIBridgeTimeOutException
Obtains a Vector containing the fields of the individual record returned from parsing the records currently being processed by the JavaCGIBridge object.

This method is useful for users who wish to retrieve results before the entire response has been sent from the Web Server yet without the programmatic overhead of using the observer interface. For example, you may want to start displaying the first 100 or so records of data to the user right away even if there may be a lot more records to retrieve eventually such as 10,000.

Please note that you should be aware that there are multi-threading concerns when using this method. If you are using JavaCGIBridgePool to manage your objects, then be aware that the JavaCGIBridge object delibrately does not set processing to IDLE at the end of processing when fetchNextRecord is being called. This behavior is activated by passing "true" to the callOneWay method.

Because it is not set to IDLE, JavaCGIBridgePool has no way of knowing that you are done with the objects. There are two ways to set the JavaCGIBridge object idle. The first and easiest way demonstrated below), is to simply iterate over fetchNextRecord() until it returns null (end of records). When it does this, the JavaCGIBridge will immediately be set to the IDLE state. The second way is to manually called setStatus(JavaCGIBridge.IDLE) yourself.

If you are not using JavaCGIBridgePool, then this need to set the object IDLE is not necesssary if you do not plan on reusing the object itself.

Example Usage:

 Vector v;
 JavaCGIBridgeExtension jcbe = new JavaCGIBridgeExtension();
 // true is passed because we are fetching records after the
 // one-way operation
 jcbe.callOneWay(myURL, true);
 while (null != (v = jcbe.fetchNextRecord())) {
     // Do something with Vector v
 }
 

Returns:
Vector a vector containing the fields of parsed data
Throws: JavaCGIBridgeTimeOutException
If the retrieval times out
 o showDocument
 public void showDocument(AppletContext ac,
                          URL u,
                          String target)
Tells the browser to show a document. Basically the difference between this showDocument() and AppletContext's showDocument() method is that this one fixes some cross platform problems with the Mac Netscape 3.x implementation of showDocument().

Parameters:
ac - AppletContext
u - URL to load
target - Target to load document in. Same as target in AppletContext.showDocument()
 o showDocument
 public void showDocument(AppletContext ac,
                          URL u,
                          String target,
                          Hashtable formVars)
Tells the browser to show a document. Basically the difference between this showDocument() and AppletContext's showDocument() method is that this one fixes some cross platform problems with the Mac Netscape 3.x implementation of showDocument().

In addition, you can pass a Hashtable with form variables which will be used to construct a URL encoded query string to append to the URL itself.

Parameters:
ac - AppletContext
u - URL to load
target - Target to load document in. Same as target in AppletContext.showDocument().
formVars - Hashtable contains form variables to add to GET method
 o showDocument
 public void showDocument(AppletContext ac,
                          URL u,
                          String target,
                          Hashtable formVars,
                          boolean fixMacBug)
Tells the browser to show a document. Basically the difference between this showDocument() and AppletContext's showDocument() method is that this one fixes some cross platform problems with the Mac Netscape 3.x implementation of showDocument().

In addition, you can pass a Hashtable with form variables which will be used to construct a URL encoded query string to append to the URL itself.

Parameters:
ac - AppletContext
u - URL to load
target - Target to load document in. Same as target in AppletContext.showDocument().
formVars - Hashtable contains form variables to add to GET method
fixMacBug - boolean indicating whether or not the code for fixing the Mac Bug should be activated. There may be intranet applications where you may choose not to activate the Mac Bug fix feature.

All Packages  Class Hierarchy  This Package  Previous  Next  Index