NSAPI Sample Application

> NSAPI Sample Application
> This document describes how to utilize the NSAPI sample application in conjunction with Sun ONE Application Server version 7.

> This sample application document contains the following sections:

> - Overview

> - Compiling the Sample Applications

> - Deploying the Sample Applications

> - Running the Sample Applications

> - Troubleshooting

> Overview

> The following instructions describe how to use NSAPI samples.

> For more details on NSAPI and the samples demonstrated here, please refer to the Developer's Guide to NSAPI. Besides the source code of Custom SAFs provided, we also provide the samples to utilize these SAFs.

> Compiling the Sample Applications

> Depending on your operating system, choose one of the following two methods to compile the samples.

> - Solaris

>   - Execute gmake under s1as_install_dir/samples/nsapi/src/

>   Make sure gmake and cc are in your path

> - Windows 2000

>   You need to install Visual C++ to compile the samples. Please add nmake under $VC_INSTALL_DIR/bin into your path.

>   - Go to s1as_install_dir/samples/nsapi/src/

>   - execute nmake -f Makefile.w2k

> - Linux
>   - Execute gmake -f Makefile.linux under s1as_install_dir/samples/nsapi/src/
>   Make sure gmake and gcc are in your path
> Once you have created the sample application from scratch, you may proceed to Deploying the Sample Applications .

> Deploying the Sample Applications

> Instructions to deploy the individual sample reside inside the source code. Illustrated here are the steps to deploy all NSAPI samples and run them from a single URL.

> Init.conf, <server-instance> -obj.conf and mime.types under s1as_install_dir/domains/{domain_instance}/{server_instance}/config should be modified.

> The server has to be restarted after the config files modification. If you deploy on W2K, you need to replace .so with .dll .

> 1. Modify init.conf .

>    Add the following lines at the end of the file:

>    Init fn="load-modules" funcs="hardcoded_auth,explicit_pathinfo,acf_init,restrict_by_acf,html2shtml,send_images,brief_init,brief_log" shlib="s1as_install_dir/samples/nsapi/example.so"

>    Init fn=brief_init file="s1as_install_dir/samples/nsapi/src/test/addlogtest"

>    Init fn=acf_init file="s1as_install_dir/samples/nsapi/src/test/pathcheck/checkfile"

>    Init fn="load-modules" funcs="cgiwatch_init,cgiwatch_service" shlib="s1as_install_dir/samples/nsapi/cgiwatch.so"

>    Init fn=cgiwatch_init

>    Init fn="load-modules" funcs="qos_error_sample,qos_handler_sample" shlib="s1as_install_dir/samples/nsapi/qos.so" shlib_flags="(global|now)"

> 2. Modify <server-instance> -obj.conf.

>    Add the following lines inside the default object just before NameTrans fn=document-root root="$docroot":

>    NameTrans fn=pfx2dir from=/nsapi dir="s1as_install_dir/samples/nsapi/src/test"

>    NameTrans fn=pfx2dir from=/authtrans dir="s1as_install_dir/samples/nsapi/src/test/authtrans" name="authtrans"

>    NameTrans fn=pfx2dir from=/nametrans dir="s1as_install_dir/samples/nsapi/src/test/nametrans" name="nametrans"

>    NameTrans fn=pfx2dir from=/pathcheck dir="s1as_install_dir/samples/nsapi/src/test/pathcheck" name="pathcheck"

>    NameTrans fn=pfx2dir from=/objecttype dir="s1as_install_dir/samples/nsapi/src/test/objecttype" name="objecttype"

>    NameTrans fn=pfx2dir from=/service dir="s1as_install_dir/samples/nsapi/src/test/service" name="service"

>    NameTrans fn=pfx2dir from=/addlog dir="s1as_install_dir/samples/nsapi/src/test"

>    NameTrans fn=pfx2dir from=/qos dir="s1as_install_dir/samples/nsapi/src/test" name="qos"

>    NameTrans fn=assign-name from=/cgiwatch name=cgiwatch stop=true

> 3. Add the following line after AddLog fn=flex-log name="access":

>    Addlog fn=brief_log

> 4. At the end of the file, add the following lines:

>    <Object name="authtrans">

>    AuthTrans fn=basic-auth auth-type="basic" userdb=garbage userfn=hardcoded_auth

>    PathCheck fn=require-auth realm="test realm" auth-type="basic"

>    </Object>

>    <Object name="nametrans">

>    NameTrans fn=explicit_pathinfo separator=","

>    ObjectType fn=force-type type=magnus-internal/cgi

>    Service fn=send-cgi user="$user" group="$group" chroot="$chroot" dir="$dir" nice="$nice"

>    [In W2K, the send-cgi in the previous line should be replaced by send-shellcgi]

>    </Object>

>    <Object name="pathcheck">

>    PathCheck fn=restrict_by_acf

>    </Object>

>    <Object name="objecttype">

>    ObjectType fn=html2shtml

>    ObjectType fn="shtml-hacktype"

>    Service fn="parse-html" method="(GET|HEAD)" type="magnus-internal/parsed-html"

>    </Object>

>    <Object name="service">

>    Service method=(GET|HEAD) fn=send_images type=magnus-internal/picgroup

>    </Object>

>    <Object name="cgiwatch">

>    Service method=(GET|HEAD) fn=cgiwatch_service

>    </Object>

>    <Object name="qos">

>    AuthTrans fn="qos_handler_sample"

>    Error fn="qos_error_sample" code="503"

>    </Object>

> 5. Modify mime.type.

>    Add the following line at the end of the file:

>    type=magnus-internal/picgroup exts=picgroup

> Running the Sample Applications

> The following steps should be performed in order to run the samples:

> 1. Before you run the qos sample, you have to enable the qos from Admin server:

>    - Click on HTTP Server from the left pane.

>    - Click on QOS from the right pane.

>    - Enable the QOS.

>    - Set Bandswidth Limit to 50 and enable the "Enforce Bandwidth Limit" .

>    - Apply the Change.

> 2. In order to run Service, do the following:

>    - copy s1as_install_dir/samples/docs/images/SunONE.jpg to s1as_install_dir/samples/nsapi/src/test/service

> 3. In order to run NameTrans on Solaris, do the following:

>    - Run chmod 755 nametrans.cgi inside s1_as_install_dir/samples/nsapi/src/test/nametrans

> 4. In order to run NameTrans on Windows 2000, do the following:

>    - Modify nametrans.cgi inside s1_as_install_dir/samples/nsapi/src/test/nametrans, replace env with set .

>    - Go to My Computer -> Tools -> Folder Options -> File Types, add the new file type cgi , add the perl interpretor.

>    - The user who performed the previous step should be the same user who started the app server.

> The URL to access all the samples is: http://<AppServer hostname>:<port>/nsapi

> Table 1 explains the functionality of each.

> Table 1 Functionality
> Name | Do This | Results
> --- | --- | ---
> AuthTrans | Click AuthTrans. | A pop will be displayes. Type joe/shmoe or suzy/creamcheese in order to pass the authorization.
> NameTrans | Click NameTrans. | A cgi script is executed and the explicit path info nametrans should appear ( PATH_INFO=nametrans).
> PathCheck | Click PathCheck. | If the IP address from which your browser runs is in s1_as_install_dir/samples/nsapi/src/test/pathcheck/checkfile, you will be able to access this link. Otherwise, you will be denied access to this page.
> ObjectType | Click ObjectType | What this page demonstrates is that objecttype.shtml is rendered instead of objecttype.html
> Service | Click Service. | You should see a jpeg image which is listed in s1_as_install_dir/samples/nsapi/src/test/service/service.picgroup.
> AddLog | Click AddLog. | You should see an access log file.
> cgiwatch | Click cgiwatch. | You should see the cgi statistics for your machine.
> qos | Click qos. | You will see a directory. Keep Clicking Reload/Refresh very fast to make the bandwidth of the net traffic is over the limit we set up in the admin server. You should eventually see something like "Global bandwidth limit of 50 . Current bandwidth : 53".

> Troubleshooting

> - If you encounter problems when running the application, review the log files at s1as_install_dir/domains/<domain-instance> /<server-instance>/logs/server.log to learn what exactly went wrong.

> - If you use Internet Explorer, the Service link does not work since the file with the content type multipart/x-mixed-replace is not supported in Internet Explorer.

> Copyright © 2002 Sun Microsystems, Inc. All rights reserved.

Last Updated August 13, 2002