vqServer API Sample applications


Some sample applications of the vqServer API are included with the developer's kit. The example applications all belong to the vq.server.apidemos package. The source code (with explanatory comments) and compiled class files are copied to the website/apidemos/ directory during installation of the developer's kit. To use the examples, add website/apidemos/ to the CLASSPATH that is used when vqServer is invoked (alternatively copy the contents of website/apidemos/ to your CLASSPATH).

Example 1: GuestReg

vq.server.apidemos.GuestReg is a servlet which uses the vqServer API to manipulate the vqServer user database. It uses the vqServer user database to hold guest book information.

To use GuestReg you will need to add the website/apidemos/ directory to your CLASSPATH before starting vqServer and create an alias named /servlet/vq.server.apidemos.GuestReg whose real name is vq.server.apidemos.GuestReg and whose action is set to Run Java servlet. A page containing a form which invokes the servlet, guestreg.html, is copied to your website/public/ directory during installation of the developer's toolkit. Invoke this servlet using the form.

GuestReg's init() method obtains vqServer's list of ACLs using console.getAcls() and searches it for an ACL whose name is Guests. The simple sequential search illustrates iteration through a vq.utils.kllist. If the ACL is not found it is created and added to vqServer's list. GuestReg could be improved by transferring this logic to the service() method in case the ACL is deleted between invocations of the servlet.

GuestReg's service() method creates a new user record with a unique user ID and a dummy password, copies information from the form the the new user record, and adds the new user to vqServer's list of users.

GuestReg's generateOutput() method illustrates a simple way of buffering servlet output. Buffering the output means that its length is known before anything is written to the response output stream which means that vqServer can support a persistent HTTP connection.

Example 2: HelloServer

vq.server.apidemos.HelloServer is a hybrid servlet/application which uses the vqServer API to create a partial vqServer installation without using a configuration file. It sets up a web server on TCP/IP port 81 which responds to any requests by sending a simple message.

To use HelloServer you will need to add the website/apidemos/ directory to your CLASSPATH and then invoke HelloServer from the command line using something like jre vq.server.apidemos.HelloServer. Test HelloServer by typing http://localhost:81 in the address box of your browser and pressing the Enter key.

HelloServer starts off by setting your registration key using console.setRegKey(String). You'll need to modify the static variables regkey1, regkey2 and regkey3 to contain the first, second and third lines of your own registration key.

HelloServer then instantiates, initialises, configures and starts a vq.server.HttpServer object. The Aliases.addServlet(String, Servlet) method is used to add an instance of HelloServer to the server's list of aliases.

Most applications of this type will invoke console.getServers.add(myServer) to add server objects to vqServer's list of servers. There is little if any benefit in running an HttpServer object independently of the rest of vqServer. Most applications will also benefit from calling console.periodic(long) or HttpServer.periodic(long) to perform cache and connection management.

Example 3: SampleApp

vq.server.apidemos.SampleApp is a minimal application which includes vqServer's functionality as a subset of its own features. In fact, SampleApp's own functionality is limited to starting vqServer, sleeping for ten minutes and then shutting down vqServer.

To use SampleApp you will need to add the website/apidemos/ directory to your CLASSPATH and then invoke SampleApp from the command line using something like jre vq.server.apidemos.SampleApp. Test SampleApp from your browser in exactly the same way that you would test vqServer.


vqServer API version 1.9. Copyright © 1997-2000 Steve Shering and vqSoft. Last updated 26 May 2000.

vqSoft
vqServer
API home page

Contents
Download
Registration
FAQs
Support