Writing Web Applications With WAI: Netscape Enterprise Server/FastTrack Server, Version 3.0/3.01

[Contents] [Previous] [Next] [Index]

Chapter 7
Writing a WAI Server Plug-In

Using WAI, you can write server plug-ins that run within the web server's process (as opposed to standalone applications that run in their own processes). A server plug-in is a shared library or dynamic link library that is loaded and initialized when the server starts up.

Most of the instructions in the previous chapters apply to writing server plug-ins as well as applications. (For details on writing applications with WAI, see Chapter 4, "Writing a WAI Application in C" and Chapter 5, "Writing a WAI Application in C++". )

Typically, when you are writing a standalone application, you register your web application service when your application starts up. If you are writing a server plug-in instead of an application, you need to register your web application service when the server starts up. To do this, you need to:

Writing an Initialization Function

If you are writing a server plug-in, you need to write an initialization function to register your web application service. You can set up this initialization function to get invoked when the web server starts up.

In general, you call the same functions and methods to register a web application service in a server plug-in as you do to register the service in an application. The difference is that you call these functions and methods within an initialization function.

The next section, "Initialization in C", explains how to write your initialization functions.

Initialization in C

The initialization function must have the following prototype:

myfunc(pblock *pb, Session *sn, Request *rq) 
In the initialization function, you create a new web application service and register the service. As is the case with standalone applications, you call the WAIcreateWebAppService() function to create the service and WAIregisterService() to register the service. For example:

...
// Declare the global variable obj as the web service 
IIOPWebAppService_t obj;
...
// Create a new web application service
obj = WAIcreateWebAppService("MyServiceName", MyRunFunction, 0, 0);
// Register the web application service 
WAIregisterService(obj, "");
...
Unlike standalone applications, you do not need to specify host and port information as arguments to the WAIcreateWebAppService() function. Because your service runs within the web server process, the host and port information is not necessary.

The following example registers a web application service under the instance name CIIOPip. The service is defined in a server plug-in, which provides the initialization function CIIOPinit() for registering the service.

...
// Define your Run function
long 
MyRunFunction(ServerSession_t obj) 
{ 
...
} 
...
// Declare the global variable anObject as a web service instance 
IIOPWebAppService_t obj; 
...
// Specify the right type for compiling on Windows NT
#if defined(WIN32)
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
...
// Make the initialization function available 
extern "C" { 
   DLLEXPORT int CIIOPinit(pblock *pb, Session *sn, Request *rq); 
} 
...
// Your initialization function (called at server startup) 
int 
CIIOPinit(pblock *pb, Session *sn, Request *rq) 
{ 
// Create a new web application service 
   obj = WAIcreateWebAppService("CIIOPip", MyRunFunction, 0, 0); 
// Register the web application service 
   WAIregisterService(obj, ""); 
   return 0; 
} 
...

Configuring Your Web Server

Next, you need to configure the web server to run your initialization function when the server starts up.

Add the following Init directives to your obj.conf file (which is located under server_root/server_id/config in UNIX and server_root\server_id\config in Windows NT.

Init funcs="init_function" fn="load-modules" shlib="shared_lib" 
Init fn="init_function"
For example, suppose you define an initialization function myinit() in a shared/dynamic library /usr/netscape/suitespot/wai/lib/mylib.so. You need to add the following directives to your obj.conf file:

Init funcs="myinit" fn="load-modules" shlib="/usr/netscape/suitespot/wai/lib/mylib.so" 
Init fn="myinit"
When a WAI plugin needs to be run in-process to the http server, the load-modules and Init directives for this should occur after those corresponding to the load-modules and Init directives libONEiiop.so (or .dll).


[Contents] [Previous] [Next] [Index]

Last Updated: 12/04/97 16:12:42


Copyright © 1997 Netscape Communications Corporation

Any sample code included above is provided for your use on an "AS IS" basis, under the Netscape License Agreement - Terms of Use