Comparing agents, servlets, and CGI programs

Agents, servlets, and CGI programs all allow you to extend the functionality of your Domino® Web application. Agents can be tightly integrated with a Web application through the form WebQueryOpen and WebQuerySave events. Servlets have special features available through the Servlet API classes, such as session and cookie management. Due to the growing popularity of Java, the trend today is to use servlets rather than CGI programs for new development. However, there is a large selection of off-the-shelf CGI programs already available.

If you are writing your own application and need to program some functionality on the server, you may have a choice of which type of program to use. Each type of program has its advantages and will be the best choice in particular situations. Here are some suggested uses for each type of program:

Program type

Best uses

Agent

Programs that perform Domino® actions when documents are read or posted.

Programs that need to be run on a schedule or when database actions occur, such as the arrival of new mail.

Servlet

Programs that use standard Java interfaces such as JDBC.

Programs that use HTTP session maintenance or cookies.

Complex or resource-intensive Java programs.

CGI program

Programs that need low-level access to system resources.

Programs that interface with another product through a non-Java API.

Here are some useful comparisons of the properties of these programs.

What language can the program be written in?

  • Agent: Java, LotusScript®, or Notes® formula language. All are inherently cross-platform.
  • Servlet: Java. Inherently cross-platform.
  • CGI program: Platform scripting languages; that is, any language compiled into an executable file, or cross-platform languages such as Java or Perl.

Where is the program stored?

  • Agent: Stored in a Domino® database, which means that agents take advantage of database replication and server clustering.
  • Servlet: Stored in the file system, usually in the domino\servlet directory.
  • CGI program: Stored in the file system, usually in the domino\cgi-bin directory.

How is the program invoked by a Web user?

  • Agent: Invoked automatically by a WebQueryOpen or WebQuerySave event, or invoked directly by an OpenAgent URL (for example, http://acme.com/sales.nsf/results?OpenAgent). Agents can also be triggered by server events, such as the arrival of new mail, or on a scheduled basis.
  • Servlet: Invoked directly by a URL. Domino® recognizes two types of servlet URLs. The first type specifies the servlet by its name (for example, http://acme.com/servlet/SQLDatabaseQuery?month=june). The second type specifies a file extension that the Domino® administrator has mapped to a servlet (for example, http://acme.com/sqlquery.esp?month=june).
  • CGI program: Invoked directly by a URL (for example, http://acme.com/cgi-bin/filesearch?string=widget).

When is the program loaded and unloaded by the server?

  • Agent: Loaded every time it is invoked and unloaded when it has finished.
  • Servlet: Loaded once; stays loaded until the HTTP server task is shut down or restarted. This gives servlets a significant performance advantage over agents or CGI programs. However, this also means that the servlet classes can be accessed from many requests simultaneously, so you must make sure that the servlet code is thread-safe.
  • CGI program: Loaded every time it is invoked and unloaded when it has finished.

How can the program interact with Domino®?

  • Agent: LotusScript® and Java agents can use the Domino® object classes. Formula agents can use most @functions.
  • Servlet: Can access Domino® through the Common Object Request Broker Architecture (CORBA) interface.
  • CGI program: Can access Domino® through the CORBA interface, or through the Domino® C or C++ APIs.

What security is available for the program?

  • Agent: To invoke an agent, a Web user must have at least Depositor access to the database containing the agent. An agent can run with the identity of its creator or the user. The full range of Domino® security features applies to operations performed by the agent.
  • Servlet: Access to the servlet can be controlled by file-protection documents in the Domino® Directory. If the servlet accesses Domino® through the CORBA interface, it can specify a Domino® user name and Internet password. Domino® security applies to all CORBA operations.
  • CGI program: Access to the program can be controlled by file-protection documents in the Domino® Directory. If the program accesses Domino® through a C API, it takes the identity of the server ID; if it uses the CORBA interface, it can specify a user name and Internet password. In both cases, Domino® security applies.