Back to the overview. The Servlet Template

The Servlet Template

The following is the Java source code for a Bojangles compatible servlet. Serveral spots are highlighted in red. These indicate places where you need to substitute the values appropriate for your use.


import COM.ibm.jaws.services.sroot.SimpleRootBC;
import COM.ibm.jaws.util.Debug;
import COM.ibm.jaws.mofw.*;

import netscape.server.applet.ServerApplet;

/**
 * The run method of this class is started by the Netscape server and
 * will continue to run as long as the socket connection to the client
 * applet is alive. It will process requests from a client until the
 * session is broken. This is usually because the client breaks the
 * connection, but it could be because of a communications problem.
 * <p>ServerApplet is a class provided by netscape, and is one of the
 * set of possible classes that a servlet must extend to be able to
 * execute within the bounds of the netscape process.
 */
public class ServletClassName extends ServerApplet
{
    // Bojangles provides a debug class to help in debugging and
    // maintaining your code. Currently this using this support is the
    // best way to get information about failures as Netscape does not
    // provide an error log.
    private static Debug d = new Debug("ServletClassName", true);
    private static String outFile = "errorLogFilename";
    
    /**
    * The run method will be started by the Netscape server and
    * execute until the client applet is destroyed. It will run on the
    * Netscape servers thread provided at start. The thread will
    * execute the complete request and return the IIOPReply to the
    * client.
    */
    public void run() throws Exception
    {
       // This try block is needed to get good error messages out of
       // the web server
       try {    
	 d.rebindOut(outFile);
	 d.rebindErr(outFile);

	 // Connect to your activation space.
	 String name = "activationSpaceName";
	 // E.g., String activationSpaceName = "TRSActivationSpace";

	 BaseCollection root = SimpleRootBC.getRoot(name);

	 // Test for failure to connect
	 if (root == null) {
	   String msg = "Could not connect to activation space: " +
			name;
	   d.errln(msg);
	   throw new Error(msg);
	 }

	 // Optionally resolve to get a relative context, if you
	 // don't need a relative context then discard this code
	 // and pass null as the second argument to the
	 // ServerORBlet constructor

	 String key = "relativeContextKey";
	 // E.g.; String key = "/TRSRoot";

	 KeyedCollection relativeContext = 
	  (KeyedCollection) root.resolve(key);

	 // Test for failure to locate the relative context
	 if (relativeContext == null) {
	   String msg = "Could not locate relative context" + key;
	   d.errln(msg);
	   throw new Error(msg);
	 }	      

	 // Now create the ServerORBlet object and start it running
	 COM.ibm.corba.ORB orb = (COM.ibm.corba.ORB) new
	     COM.ibm.corba.ServerORBlet(root, relativeContext,
		 getClientSocket());
	 orb.run();

       } catch (Throwable e) {
	  e.printStackTrace();
	  throw new Error(e.getMessage());
       }
    }
}