Sun Java System Web Server 7.0 NSAPI Developer's Guide

Service Example

This section discusses a very simple Service function called simple_service. All this function does is send a message in response to a client request. The message is initialized by the init_simple_service function during server initialization.

For a more complex example, see the file service.c in the examples directory, which is discussed in More Complex Service Example.

Installing the Service Example

To load the shared object containing your functions, add the following line in the Init section of the magnus.conf file:


Init fn=load-modules 
     shlib=yourlibrary 
     funcs=simple-service-init,simple-service

         

To call the simple-service-init function to initialize the message representing the generated output, add the following line to the Init section in magnus.conf. (This line must come after the one that loads the library containing simple-service-init.)


Init fn=simple-service-init
     generated-output="<H1>Generated output msg</H1>"

         

To execute the custom SAF during the request-response process for some object, add the following line to that object in the obj.conf file:

Service type="text/html" 
        fn=simple-service

The type="text/html" argument indicates that this function is invoked during the Service stage only if the content-type has been set to text/html.

The source code for this example is in the service.c file in the install_dir/samples/nsapi directory.

More Complex Service Example

The send-images function is a custom SAF that replaces the doit.cgi demonstration available on the iPlanet home pages. When a file is accessed as /dir1/dir2/something.picgroup, the send-images function checks if the file is being accessed by a Mozilla/1.1 browser. If not, it sends a short error message. The file something.picgroup contains a list of lines, each of which specifies a file name followed by a content-type (for example, one.gif image/gif).

To load the shared object containing your function, add the following line at the beginning of the magnus.conf file:

Init fn=load-modules shlib=yourlibrary funcs=send-images

Also, add the following line to the mime.types file:

type=magnus-internal/picgroup exts=picgroup

To execute the custom SAF during the request-response process for some object, add the following line to that object in the obj.conf file (send-images takes an optional parameter, delay, which is not used for this example):


Service method=(GET|HEAD) type=magnus-internal/picgroup fn=send-images

         

The source code for this example is in the service.c file in the install_dir/samples/nsapi directory.