The Servlet Sender and Receiver Xbeans


The Servlet Sender is a sink Xbean that sends a DOM document to a Servlet Receiver. The Servlet Receiver is a source Xbean that receives the DOM document and passes it on to the next Xbean in the Xbean channel. The Servlet Receiver can be deployed in any J2EE compliant web container, such as Tomcat, Resin, Weblogic, etc.

Servlet Sender XBean Properties

id The URL of the servlet receiver Xbean. 


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

Servlet Receiver XBean

The servlet receiver does not have any Java Bean properties. Instead, all configuration is done in the web.xml file.


The servlet's URL is established in the web.xml file using the <servlet-mapping> tag.


Compression is determined by examining the URL used to invoke the servlet. If the URL ends in ".compressed", then the servlet decompresses the incoming data. 
DOMListener The DOMListener is set in web.xml as a servlet initialization parameter, domListener. If you have a single Xbean as a DOMListener, then you can set the parameter to be that Xbean. If on the other hand, you have several Xbeans forming a channel, you need to write a class that implements the DOMListener interface, instantiates and configures the channel and calls the first Xbean in the channel when documentReady is called by the receiver servlet.

Sample web.xml file

The Xbeans release comes with a sample web.xml file for deploying the servlet receiver. The file is in tests/source/WEB-INF/web.xml and shown below. Note the setting of the domListener in the <init-param> tag and the two servlet mappings, one for a non-compressed document and the other for a compressed document.

  <display-name>Xbean Servlet Demo</display-name>
  <description>Demonstrates Xbean receiver for servlets</description>
    <display-name>Xbean ReceiverServlet</display-name>
    <description>Xbean receiver for servlets</description>

Using the Servlet Sender

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

import org.xbeans.communication.servlet.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 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.

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


Your URL may differ depending on how the receiver servlet is deployed.

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


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

Source files