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

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

Chapter 2
Quick Start: Running the Examples

This chapter explains how to compile and run some of the sample WAI applications provided with your server.

You can find these sample applications in the server_root/wai/examples directory on UNIX and in the server_root\wai\examples directory on Windows NT.

NOTE: These examples assume that your server is running in non-secure mode.
For more detailed information on setting up, writing, and running WAI applications, see the rest of the chapters in this manual:

Running the Sample C Application (CIIOP)

The sample C application provided with the web server is in the server_root/wai/examples/CIIOP directory. The source file for the example is CAPIIIOP.c.

This example sends a page containing the text Hello World back to the client, as shown in the following figure:

The rest of this section explains how to set up and use this example. You can use this as a guideline for setting up and running your own C examples.

To run the sample C application, follow these steps:

  1. (For 3.0 servers only)Start up osagent.
    osagent is located under server_root/wai/bin in UNIX and server_root\wai\bin in Windows NT.
    Specify the -a flag to restrict osagent to the localhost IP address. For example:
    osagent -a 127.0.0.1

    For more information, see "Starting osagent (3.0 Servers Only)".

  2. Enable WAI applications on the web server.
    From the Server Administration page in the administration server, click the button labelled with your server name. This displays the Server Manager for your server.
    Click Programs | WAI Management to display the form for administering WAI on your server.
    Under Enable WAI Services, select the Yes radio button and click OK. Save and apply your changes.
    For more information, see "Setting the Option to Enable WAI".

  3. In the wai/examples/CIIOP (in UNIX) or wai\examples\CIIOP (on Windows NT) directory, review the sample source file CAPIIIOP.c.
    Basically, the code in this source file does the following (for a more complete explanation of these steps, see Chapter 4, "Writing a WAI Application in C"):
  4. Accepts an argument that specifies the host and port where the web server is running. For example, you can use the following command argument to specify that your web server is running on port 80 of the server named mooncheese:
  5.       CAPIIIOP mooncheese:80
  6. Calls the WAIcreateWebAppService() function to create a new web application service named CAPIIIOP. Users will be able to access this web service through the following URL (if, for example, your web server is running on port 80 of the server named mooncheese):
  7.       http://mooncheese.mydomain.com:80/iiop/CAPIIIOP
  8. Calls the WAIregisterService() function to register the web application with the web server running on the host and port number specified on the command-line.
  9. Calls the WAIimplIsReady() function to indicate to the web server that it is ready to receive requests.
  10. When the application receives a request, it does the following:

  11. Compile and link the sample application.
    The sample application includes a Makefile (for example, Makefile.SOLARIS or Makefile.WINNT) that you can use to compile and link the application.
    For more information on compiling and linking your application, see "Compiling C/C++ Applications".

  12. After compiling and linking the application, run the application by entering the following command:
       CAPIIIOP hostname:port
    where hostname and port identify the name of the machine that the web server runs on and the port number that the server listens to. For example:
       CAPIIIOP myserver:80
    This registers the application with the web server. The web server should be able to find the CAIIIOP WAI application.

  13. In a web browser, go to the following URL:
       http://hostname:port/iiop/CAPIIIOP
    where hostname and port identify the name of the machine that the web server runs on and the port number that the server listens to. For example:
       http://myserver:80/iiop/CAPIIIOP
    The web server processes the request. While processing the request, the server parses the URL, retrieves the name of the service you want to access (CAPIIIOP), and contacts your application.
    Your application receives the request and returns the Hello World string. The web server returns this to the web browser.
Effectively, the web browser has requested a service, and your WAI application has delivered back results through the web server.

Running the Sample C++ Application (WASP)

The sample C++ application provided with the web server is in the server_root/wai/examples/WASP directory. The source file for the example is WASP.cpp.

This example does the following:

The following screenshot illustrates the results of this service.

Note that this example can be compiled and linked as a standalone application that runs outside the web server's process and as a server plug-in that runs within the web server's process.

The rest of this section explains how to set up and use the standalone application in this example. (For an example of writing a server plug-in, see Chapter 7, "Writing a WAI Server Plug-In".)

You can use this example as a guideline for setting up and running your own C++ examples.

To run the sample C++ application, follow these steps:

  1. (For 3.0 servers only) Start up osagent.
    osagent is located under server_root/wai/bin in UNIX and server_root\wai\bin in Windows NT.
    Specify the -a flag to restrict osagent to the localhost IP address. For example:
    osagent -a 127.0.0.1

    For more information, see "Starting osagent (3.0 Servers Only)".

  2. Enable WAI applications on the web server.
    From the Server Administration page in the administration server, click the button labelled with your server name. This displays the Server Manager for your server.
    Click Programs | WAI Management to display the form for administering WAI on your server.
    Under Enable WAI Services, select the Yes radio button and click OK. Save and apply your changes.
    For more information, see "Setting the Option to Enable WAI".

  3. In the wai/examples/WASP (in UNIX) or wai\examples\WASP (on Windows NT) directory, review the sample source file WASP.cpp.
    Basically, the code in this source file does the following (for a more complete explanation of these steps, see Chapter 5, "Writing a WAI Application in C++"):
  4. Accepts an argument that specifies the host and port where the web server is running. For example, you can use the following command argument to specify that your web server is running on port 80 of the server named mooncheese:
  5.       WASP mooncheese:80
  6. Creates a new web application service named WASP. Users will be able to access this web service through the following URL (if, for example, your web server is running on port 80 of the server named mooncheese):
  7.       http://mooncheese.mydomain.com:80/iiop/WASP
  8. Calls the RegisterService method to register the web application with the web server running on the host and port number specified on the command-line.
  9. When the application receives a request, it does the following:

  10. Compile and link the sample application.
    The sample application includes a sample Makefile (for example, Makefile.SOLARIS or Makefile.WINNT) that you can use to compile and link the application.
    For more information on compiling and linking your application, see "Compiling C/C++ Applications".

  11. After compiling and linking the application, run the application by entering the following command:
    WASP hostname:port
    where hostname and port identify the name of the machine that the web server runs on and the port number that the server listens to. For example:
       WASP myserver:80
    This registers the application with the web server. The web server should be able to find the WASP WAI application.

  12. In a web browser, go to the following URL:
       http://hostname:port/iiop/WASP
    where hostname and port identify the name of the machine that the web server runs on and the port number that the server listens to. For example:
       http://myserver:80/iiop/WASP
    The web server processes the request. While processing the request, the server parses the URL, retrieves the name of the service you want to access (WASP), and contacts your application.
    Your application receives the request and retrieving information from the request and the web server. The web server returns this information to the web browser in an HTML page.
Effectively, the web browser has requested a service, and your WAI application has delivered back results through the web server.

Running the Sample Java Application (WASP.Java)

The sample Java application provided with the web server is in the server_root/wai/examples/WASP directory. The source file for the example is WASP.java.

This example does the following:

The following screenshot illustrates the results of this service.

The rest of this section explains how to set up and use this example. You can use this as a guideline for setting up and running your own Java examples.

To run the sample Java application, follow these steps:

  1. (For 3.0 servers only) Start up osagent.
    osagent is located under server_root/wai/bin in UNIX and server_root\wai\bin in Windows NT.
    Specify the -a flag to restrict osagent to the localhost IP address. For example:
    osagent -a 127.0.0.1

    For more information, see "Starting osagent (3.0 Servers Only)".

  2. Enable WAI applications on the web server.
    From the Server Administration page in the administration server, click the button labelled with your server name. This displays the Server Manager for your server.
    Click Programs | WAI Management to display the form for administering WAI on your server.
    Under Enable WAI Services, select the Yes radio button and click OK. Save and apply your changes.
    For more information, see "Setting the Option to Enable WAI".

  3. In the wai/examples/WASP (in UNIX) or wai\examples\WASP (on Windows NT) directory, compile the sample application.
    Make sure to include the following files in your CLASSPATH environment variable:
  4. server_root/wai/java/nisb.zip
  5. server_root/wai/java/WAI.zip
  6. After compiling the application, run the application.

    If you are running a 3.0 version of a Netscape web server, run the following command:

    java -DDISABLE_ORB_LOCATOR WASP hostname:port
    The -DDISABLE_ORB_LOCATOR option specifies that osagent should not be used to find the ORB in the Netscape web server.

    If you are running a 3.0.1 version of a Netscape web server, run the following command:

    java WASP hostname:port
    This registers the application with the web server. The web server should be able to find the JavaWASP WAI application.

  7. In a web browser, go to the following URL:
    http://hostname:port/iiop/JavaWASP
    where hostname and port identify the name of the machine that the web server runs on and the port number that the server listens to. For example:
    http://myserver:80/iiop/JavaWASP
    The web server processes the request. While processing the request, the server parses the URL, retrieves the name of the service you want to access (JavaWASP), and contacts your application.
    (Note that the name used to register the server -- JavaWASP -- does not necessarily need to be the same as the name of the class -- WASP.)
    Your application receives the request and retrieving information from the request and the web server. The web server returns this information to the web browser in an HTML page.
Effectively, the web browser has requested a service, and your WAI application has delivered back results through the web server.

Running the FormHandler Sample

The classes used for writing WAI applications include a class for handling submissions through HTML forms. Using the FormHandler class, you can write a WAI application that receives and interprets data submitted through an HTML form.

To read in and parse posted form data (where the client used the HTTP POST method to submit the form), create an instance of the FormHandler class. The constructor for this class reads in the data and parses it.

To read in and parse form data submitted through the HTTP GET method, create an instance of the FormHandler class and call the ParseQueryString method.

Depending on the language you are using, you can access the parsed data in different ways:

About the FormHandler Class Example

The FormHandler samples provided with the web server are in the server_root/wai/examples/forms directory. This directory contains C++ and Java examples of using the WAI FormHandler class. You can use this class to process data submitted through an HTML form.

This directory contains the following files:

The C++ example is written as an in-process server plug-in. The Java example is written as a stand-alone application (running out of process). Both examples process and display data submitted through the form.html form.

Running the C++ FormHandler Sample

The FormHandler sample provided with the web server is in the server_root/wai/examples/forms directory. The source file for the example is formHandler.cpp.

This example is written as an in-process server plug-in that performs the following tasks:

This example can be compiled and linked as a stand-alone application that runs outside the web server's process and as a server plug-in that runs within the web server's process.

The rest of this section explains how to set up and use the server plug-in that runs within the web server's process. (For an example of writing a server plug-in, see Chapter 7, "Writing a WAI Server Plug-In".)

You can use this example as a guideline for setting up and running your own C++ forms.

  1. Compile the example using the makefile provided.
    For example:
    nmake -f Makefile.WINNT
    or
    make -f Makefile.SOLARIS

  2. Open the obj.conf file (located in the server-root/server-id/config directory) in a text editor.

  3. Add an Init directive to specify the intialization function (FormInit) for this server plug-in (form.dll or form.so).
    For example:
    Init funcs="FormInit" shlib="server-root/wai/examples/forms/form.dll" fm="load-modules"
    Init LateInit="yes" fn="FormInit"
    or
    Init funcs="FormInit" shlib="server_root/wai/examples/forms/form.so" fn="load-modules"
    Init LateInit="yes" fn="FormInit"
    When you specify the Init directive make sure to set LateInit to "yes".

  4. Save your changes and exit from the text editor.

  5. In the Administration Server, click the Apply Changes button in the top frame and restart the Enterprise Server.

  6. Copy form.html to the documentation root directory of your Enterprise Server (for example, server-root/docs).

  7. Open the form.html file in a text editor and verify that the action of the form is set to "/iiop/FORMip".
    For example:
    <FORM name="submitform" method="POST" ACTION="/iiop/FORMip">
    FORMip is the name with which this WAI server plug-in registers.

  8. Go to the following URL:
    http://server-name:port-number/form.html

  9. Fill in the fields and click Send to submit the form.
    The WAI server plug-in should send a generated HTML page back to your browser. The page should display some of the data you have submitted.

Running the Java FormHandler Sample

The Java example is written as a stand-alone application, running out of process. It processes and displays data submitted through the form.html form in the /wai/examples/forms directory.

  1. Compile the TestDriver.java example.
    javac TestDriver.java

  2. Run the TestDriver Java application.
    Specify the server name and port number of your Enterprise Server as follows:
    java TestDriver server-name:port-number

  3. Copy form.html to the documentation root directory for your Enterprise Server (for example, server-root/docs).

  4. Open the form.html file in a text editor and change the action of the form to "/iiop/JavaForm".
    For example:
    <FORM name="submitform" method="POST" ACTION="/iiop/JavaForm">
    JavaForm is the name with which this WAI application registers.

  5. Go to the following URL:
    http://server-name:port-number/form.html

  6. Fill in the fields and click Send to submit the form.
    The WAI application should send a generated HTML page back to your browser. The page should display some of the data you have submitted.


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

Last Updated: 12/04/97 16:11:51


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