ObjectType() Example

                                                                                                                                                                                                                                                                                                                                      Back to [Book]     [Topic]

ObjectType() Example

The example in this section demonstrates how to implement html2shtml, a custom SAF that instructs the server to treat a .html file as a .shtml file if a .shtml version of the requested file exists.

A well-behaved ObjectType function checks whether the content type is already set. If the type is set, the function returns REQ_NOACTION.

if(pblock_findval("content-type", rq->srvhdrs))
    return REQ_NOACTION;     

If the content type is not set, ObjectType directive sets the content type. This example sets the content type to magnus-internal/parsed-html in the following lines:

/* Set the content-type to magnus-internal/parsed-html */
pblock_nvinsert("content-type", "magnus-internal/parsed-html",
                rq->srvhdrs);     

The html2shtml function checks the requested file name. If the name ends with .html, the function searches for a file with the same base name, with the extension .shtml. If a .shtml is found, the function uses that path and informs the server that the file is parsed HTML instead of regular HTML. Note that this check requires an extra stat call for every HTML file accessed.

Installing the ObjectType() Example

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

Init fn=load-modules
     shlib="_path_" 
     funcs=html2shtml

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:

ObjectType fn=html2shtml

The source code for this example is in otype.c 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