Service() Example

                                                                                                                                                                                                                                                                                                                                      Back to [Book]     [Topic]

Service() Example

This section discusses two Service() function examples: one simple and one complex.

Simple Service() Example

This section describes a very simple Service function called simple_service. This function sends a message in response to a client request. The message is initialized by the init_simple_service function during server initialization.

To load the shared object containing your functions, add the following directive 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 directive to the Init section in magnus.conf. This directive must come after the directive 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 an object, add the following code 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.

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 whether the file is being accessed by a Mozilla 1.1 browser. If not, the function 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 directive at the beginning of the magnus.conf file:

Init fn=load-modules 
        shlib=_your-library_ 
        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 an object, add the following code 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.

Labels

java java Delete
server server Delete
sun sun Delete
webserver webserver Delete
application application Delete
system system Delete
webtier webtier Delete
guide guide Delete
webserver70 webserver70 Delete
sunjava sunjava Delete
nsapi nsapi Delete
nsapidevelopersguide nsapidevelopersguide Delete
developers developers Delete
web web Delete
+nsapiguide +nsapiguide Delete
nsapiguide nsapiguide Delete
developersguide developersguide Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Sign up or Log in to add a comment or watch this page.


The individuals who post here are part of the extended Sun Microsystems community and they might not be employed or in any way formally affiliated with Sun Microsystems. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Sun nor any other party necessarily agrees with them.

Copyright 1994-2009 Sun Microsystems, Inc.
Powered by Atlassian Confluence
Sun Guidelines on Public Discourse Privacy Policy Terms of Use Trademarks Site Map Employment Investor Relations Contact