The HTTP Sender and Receiver Xbeans

Function

The HTTP Sender is a sink Xbean that sends an XML document to an HTTP Receiver using HTTP as a transport mechanism. The Receiver is a source Xbean that receives the XML document and passes a DOM on to the next Xbean in the Xbean channel.

The HTTP Xbeans have been developed to work with any web server as long as there is a JDK installed on the server side. There is no requirement to have a J2EE system installed on the server side to use the HTTP sender and receiver Xbeans.

The HTTP Sender uses the HTTP protocol to invoke a CGI script on the web server that starts up a Java Virtual machine and invokes a receiver program whose first Xbean must be the HTTP Receiver Xbean. The receiver program must invoke receive() on the Receiver Xbean after initializing all of its properties. The HTTP Sender then writes the XML document as HTTP data and the Receiver Xbean reads XML and passes on a DOM to the next Xbean.

Note: An example receiver program is included with the Xbeans release in tests/source/org/xbeans/tests/ReceiverDemo.java. An example script (for Unix) that starts up the program is distributed with Xbeans in tests/rjava.cgi.

HTTP Sender XBean Properties

id The URL of the CGI script on the web server that will set up the server side part of the channel 

 compression

Setting this property to true causes the sender to compress the document using GZIP compression prior to sending it. 

Receiver XBean Properties

DOMListener As with all source Xbeans, the DOMListener property is the next Xbean in the channel. The DOMListener receives the DOM produced by receiver Xbean.

 id

This property is ignored. The id of the receiver is the URL of the CGI script invoked by the sender. 

 compression

This property must be set to indicate that the incoming documents will be compressed using GZIP compression. 

Using the HTTP Sender

The sender Xbean is in the org.xbeans.communication.http.sender package. The sender can be imported into Java source code as follows:

import org.xbeans.communication.http.sender.SenderBean;

Creating a sender Xbean is accomplished by instantiating the class:

SenderBean sender = new SenderBean();

Note that if you are using a Java Bean design tool found in many Java Integrated Development Environments, the above code is generated automatically when you drag and drop a sender Xbean into your application.

After creating the sender Xbean, you must set the remoteURL property. For example:

sender.setRemoteURL("http://www.mywebserver.com/rjava.cgi");

You need to get a DOM document by registering the sender with the previous Xbean in the channel.

previousXbean.setDOMListener(sender);

Again, if you are using a Java Bean design tool, the above calls to set properties may be automatically generated for you.

Creating a CGI Script

You must add a cgi script to your web server that starts up a Java Virtual machine and invokes a receiver program. Here is an example of such a script that runs on an Apache web server on Linux and other versions of Unix:

#!/bin/sh
DISPLAY=:0.0
export DISPLAY

/usr/java/jdk1.3.1/bin/java -classpath .:xbeansCompac.jar:xbeans.jar:xerces.jar org.xbeans.tests.ReceiverDemo

Note that in this case, the script is starting the receiver program ReceiverDemo. Your script should start whichever receiver program you create. Also note that the setting of the DISPLAY variable is only relevant to this demo code since it attempts to use the X windows display.

Creating a Receiver Program

The receiver program invoked by the CGI script is responsible for setting up the server side of the Xbean channel. Typically, the receiver program is created by adding Xbeans to a class using a JavaBean design tool such as the JBuilder designer.

The receiver Xbean is in the org.xbeans.communication.http.receiver package. The receiver can be imported into Java source code as follows:

import org.xbeans.communication.http.receiver.ReceiverBean;

Creating a receiver Xbean is accomplished by instantiating the class:

ReceiverBean receiver = new ReceiverBean();

Note that if you are using a Java Bean design tools found in many Java Integrated Development Environments, the above code is generated automatically when you drag and drop a sender Xbean into your application.

You need to establish which Xbean will receive the DOM document from the receiver. To pass the document on to the next Xbean, you simply register the next Xbean to be the receiver's DOM Listener.

receiver.setDOMListener(nextXbean);

Finally, after instantiating the Xbeans and setting their properties, the receiver program must tell the Receiver Xbean to receive the XML. That is accomplished by including a call to receive() method:

theReceiver.receive();

That will cause the Receiver Xbean to read the XML sent by the sender, produce a DOM and invoke documentReady() on the next Xbean in the channel.

Source files

source/org/xbeans/communication/http/*.java
tests/rjava.cgi