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

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

Chapter 9
WAI Reference

This section discusses the signatures of the methods of the three WAI interfaces. According to the CORBA specification, a signature describes the legitimate values of request parameters and returned results.

The following table summarizes the signatures, classes, and methods available.

Methods of the HTTPServerRequest Interface
addResponseHeader
Adds a header to the response to be sent back to the client.

BuildURL
Builds a URL from the prefix of a URI and the suffix of a URI.

delResponseHeader
Deletes a header from the response to be sent to the client.

getConfigParameter
Gets the value of a parameter of the iiopexec function in the Service directive of the obj.conf file.

getContext
Gets the HTTPServerContext object for the server.

getCookie
Gets a cookie from the request headers sent by the client.

getRequestHeader
Gets a specified header from the client's request.

getRequestInfo
Gets information about the client request (such as the value of a CGI 1.1 environment variable).

getResponseContentLength
Gets the value of the Content-length header from the response to be sent to the client.

getResponseHeader
Gets the specified header from the response to be sent to the client.

LogError
Logs an entry to the server's error log file (server_root/server_id/logs/errors on UNIX and server_root\server_id\logs\errors on Windows NT).

ReadClient
Reads data from the client (for example, for data sent through the HTTP POST method).

RespondRedirect
Redirects the client to a specified URL.

setCookie
Sets a cookie in the response header to be sent to the client.

setRequestInfo
(This method has no functional use at this time.)

setResponseContentLength
Sets the content length (the value of the Content-length header) of the response to be sent to the client.

setResponseContentType
Sets the content type (the value of the Content-type header) of the response to be sent to the client.

setResponseStatus
Sets the HTTP response code (for example, 404 for "File Not Found") of the response to be sent back to the client.

StartResponse
Starts to send the response to the client.

WriteClient
Writes data to the client.

Methods of the HTTPServerContext Interface
getHost
Retrieves the host name of the machine running the web server.

getInfo
Retrieves information about the web server (such as the value of CGI 1.1 environment variables that describe the server).

getName
Retrieves the server ID (for example, https-myhost).

getPort
Retrieves the port number that the server listens to.

getServerSoftware
Retrieves the product name and version of the web server (for example, Netscape Enterprise/3.0).

isSecure
Specifies whether or not SSL is enabled on the server.

Constructor of the WAIWebApplicationService Base Class
WAIWebApplicationService
Creates an instance of this class.

Methods of the WAIWebApplicationService Base Class
ActivateWAS
Activates the object (if the object has not already been activated by the constructor).

getServiceInfo
(This is a method that you need to implement.) Provides information about the author, version, and copyright of the web application service that you are writing.

RegisterService
Registers your WAI application with the web server running on the specified host.

Run
(This is a method that you need to implement.) Executes your web application service (this is called whenever the server receives an HTTP request for your service).

StringAlloc
Allocates memory for a string.

StringDelete
Frees a string from memory.

StringDup
Copies a string into a newly allocated buffer in memory.

Constructor of the FormHandler Class
FormHandler
Creates an instance of this class.

Methods of the FormHandler Base Class
IsValid
Specifies whether or not the submitted data was successfully parsed by the FormHandler class.

GetQueryString
Gets the query part of the URI (the name-value pairs after the question mark) from the request.

ParseQueryString
Parses the query part of the URI (the name-value pairs after the question mark) from the request.

Get (C++ only)
Gets the value of a specified name-value pair from the parsed form data.

Add (C++ only)
Adds a name-value pair to the parsed form data.

Delete (C++ only)
Removes a name-value pair from the parsed form data.

InitIterator (C++ only)
Sets up a pointer to the beginning of the list of name-value pairs in the parsed form data so that the Next method gets the first name-value pair in the list.

Next (C++ only)
Getst the next name-value pair from the parsed form data.

GetHashTable (Java only)
Returns a hashtable containing the parsed form data.

The following table summarizes the C functions available in WAI.

Table 9.1 C Functions in WAI
Function Name Description For More Information, See...
WAIaddResponseHeader()
Adds a header to the HTTP response to be sent back to the client.

"addResponseHeader"

WAIBuildURL()
Builds an absolute URL from the

"BuildURL"

WAIcreateWebAppService()
Creates a new web application service, assigns it an instance name, and associates it with a function for processing HTTP requests.

"WAIWebApplicationService"

WAIdeleteService()
Deletes a web application service.

WAIdelResponseHeader()
Removes a header from the HTTP response to be sent back to the client.

"delResponseHeader"

WAIgetConfigParameter()
Gets the value of a parameter of the iiopexec function in the Service directive of the obj.conf file.

"getConfigParameter"

WAIgetCookie()
Retrieves any cookies sent by the client.

"getCookie"

WAIgetHost()
Gets the hostname of the machine where the web server is running.

"getHost"

WAIgetInfo()
Retrieves information about the web server (such as the value of CGI 1.1 environment variables that describe the server).

"getInfo"

WAIgetName()
Gets the server ID (for example, https-myhost) of the web server.

"getName"

WAIgetPort()
Gets the port number that the web server listens to.

"getPort"

WAIgetRequestHeader()
Gets a header from the HTTP request sent by the client.

"getRequestHeader"

WAIgetRequestInfo()
Gets information about the client request (such as the value of a CGI 1.1 environment variable).

"getRequestInfo"

WAIgetResponseContentLength()
Gets the content length (the value of the Content-length header) of the response.

"getResponseContentLength"

WAIgetResponseHeader()
Gets a header from the HTTP response you plan to send to the client.

"getResponseHeader"

WAIgetServerSoftware()
Gets the type and version of the server software.

"getServerSoftware"

WAIimplIsReady()
Prepares your WAI application to receive requests.

"Registering Your Web Application Service"

WAIisSecure()
Specifies whether or not the server is run with SSL enabled.

"isSecure"

WAILogError()
Logs an entry to the server's error log file (server_root/server_id/logs/errors on UNIX and server_root\server_id\logs\errors on Windows NT).

"LogError"

WAIReadClient()
Reads data from the client (for example, for data sent through the HTTP POST method).

"ReadClient"

WAIregisterService()
Registers the WAI application with the web server.

"RegisterService"

WAIRespondRedirect()
Redirects the client to a different URL.

"RespondRedirect"

(*WAIRunFunction)()
Type definition for the function that processes HTTP requests.

"Run"

WAIsetCookie()
Sets a cookie in the response header to be sent to the client.

"setCookie"

WAIsetRequestInfo()
(This method has no functional use at this time.)

"setRequestInfo"

WAIsetResponseContentLength()
Sets the content length (the value of the Content-length header) of the response to be sent to the client.

"setResponseContentLength"

WAIsetResponseContentType()
Sets the content type (the value of the Content-type header) of the response to be sent to the client.

"setResponseContentType"

WAIsetResponseStatus()
Sets the HTTP response code (for example, 404 for "File Not Found") of the response to be sent to the client.

"setResponseStatus"

WAIStartResponse()
Starts sending the response back to the client.

"StartResponse"

WAIstringFree()
Frees a string from memory.

"StringDelete"

WAIWriteClient()
Writes data to the client.

"WriteClient"


How to Use This Reference

The methods in this section are documented in Interface Definition Language, or IDL. The C, C++, and Java syntax for each method is listed under the IDL syntax for the method.

The following section is an example of the documentation for a WAI method. The syntax for the interface is described first. Next, the prototypes for the methods that implement this operation are documented.

...

Syntax

HttpServerReturnType addResponseHeader(in string header, 
   in string value);
C Prototype:
NSAPI_PUBLIC WAIReturnType_t WAIaddResponseHeader(ServerSession_t p, const char *header,
   const char *value);

C++ Prototype:
WAIReturnType addResponseHeader(const char *header,
   const char *value);

Java Prototype:
public netscape.WAI.HttpServerReturnType addResponseHeader(java.lang.String header,
   java.lang.String value);

...
Use the prototype for the language that you are using to write your application. Note that the parameters may differ between languages. For example, the C functions have an extra parameter (of the type ServerSession_t) that represents the HTTP request object.


Interfaces

The methods for the interfaces in this section are described in terms of their signatures. The interfaces described in WAI are:

WAI also includes the following base class:

The rest of this chapter documents these interfaces and classes. Note that although in C, there is no concept of classes, the C API functions are documented here among the interfaces and classes for convenience.


netscape::WAI::HttpServerRequest

The HttpServerRequest interface declares methods for processing HTTP requests. It provides access to the data in an HTTP request sent from the client to your server.

This interface is implemented by the following classes:

When you write your own WAI class (which should derive from the Netscape base class WAIWebApplicationService; for details, see "WAIWebApplicationService"), you pass in a reference to an WAIServerRequest object (in C++) or an HTTPServerRequest object (in Java) as an argument to the Run method.

Using methods in these classes, you can get HTTP headers from a client request, set HTTP headers in a response to the request, get and set cookies in the client, write entries to the server's error log, and read and write data to the client.

Member Summary

The netscape::WAI::HttpServerRequest interface describes the following members:

Methods
addResponseHeader
Adds a header to the response to be sent back to the client.

BuildURL
Builds a URL from the prefix of a URI and the suffix of a URI.

delResponseHeader
Deletes a header from the response to be sent to the client.

getConfigParameter
Gets the value of a parameter of the iiopexec function in the Service directive of the obj.conf file.

getContext
Gets the HTTPServerContext object for the server.

getCookie
Gets a cookie from the request headers sent by the client.

getRequestHeader
Gets a specified header from the client's request.

getRequestInfo
Gets information about the client request (such as the value of a CGI 1.1 environment variable).

getResponseContentLength
Gets the value of the Content-length header from the response to be sent to the client.

getResponseHeader
Gets the specified header from the response to be sent to the client.

LogError
Logs an entry to the server's error log file

(server_root/server_id/logs/errors 
on UNIX and

server_root\server_id\logs\errors
on Windows NT).

ReadClient
Reads data from the client (for example, for data sent through the HTTP POST method).

RespondRedirect
Redirects the client to a specified URL.

setCookie
Sets a cookie in the response header to be sent to the client.

setRequestInfo
(This method has no functional use at this time.)

setResponseContentLength
Sets the content length (the value of the Content-length header) of the response to be sent to the client.

setResponseContentType
Sets the content type (the value of the Content-type header) of the response to be sent to the client.

setResponseStatus
Sets the HTTP response code (for example, 404 for "File Not Found") of the response to be sent back to the client.

StartResponse
Starts to send the response to the client.

WriteClient
Writes data to the client.


addResponseHeader

Adds a specified header to the response to be sent to the client.

Syntax

HttpServerReturnType addResponseHeader(in string header, 
   in string value);
C Prototype:
NSAPI_PUBLIC WAIReturnType_t WAIaddResponseHeader(ServerSession_t p, const char *header,
   const char *value);

C++ Prototype:
WAIReturnType addResponseHeader(const char *header,
   const char *value);

Java Prototype:
public netscape.WAI.HttpServerReturnType addResponseHeader(java.lang.String header,
   java.lang.String value);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

header
Name of the header to add.

value
Content of the header.

Returns

HttpServerReturnType::Success if the header was successfully added. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if the header could not be added. The actual return value differs, depending on the language you are using:

Example

The following example in Java adds a Pragma: no-cache header to the response sent to the client.

...
/* Define a class for your service. */
class MyWebApplicationService extends WAIWebApplicationService { 
...
/* Define the Run method, which is called whenever the client requests your service. */
   public int Run(HttpServerRequest request){ 
/* Create an output stream for the content that you are delivering to the client. */
      ByteArrayOutputStream streamBuf = new ByteArrayOutputStream(); 
      PrintStream content = new PrintStream(streamBuf);
      HttpServerReturnType rc; 
...
/* Insert code to write the content to the stream. */
...
/* Prepare to send the content back to the client.*/
      byte[] outbuff = streamBuf.toByteArray(); 
      try { 
/* Add the Pragma: no-cache header to the response. */
         rc = request.addResponseHeader("Pragma", "no-cache"); 
/* Specify the length of the data to be sent.*/
         rc = request.setResponseContentLength(outbuff.length); 
/* Start sending the response. */
         request.StartResponse(); 
      } 
         catch(org.omg.CORBA.SystemException e){ 
      } 
...
   }
...
}
...

See Also

delResponseHeader, getResponseHeader.


BuildURL

Using a specified URI prefix and URI suffix, creates a full URL of the form http://server:port prefix suffix.

If you do not want to specify a prefix or a suffix, use the empty string ("") instead of a NULL pointer.

Syntax

string BuildURL(in string prefix, in string suffix); 
C Prototype:
NSAPI_PUBLIC char *WAIBuildURL(ServerSession_t p,
   const char *prefix, const char *suffix);

C++ Prototype:
char *BuildURL(const char *prefix, const char *suffix);

Java Prototype:
public java.lang.String
BuildURL(java.lang.String prefix, java.lang.String suffix);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

prefix
URI prefix that you want to use in the URL.

suffix
URI suffix that you want to use in the URL.

Returns

The full URL containing the prefix and suffix.

Example

The following example in C++ uses the suffix /index.html to build the URL http://server_name:port_number/index.html.

...
/* Define a class for your service. */
long 
WebApplicationServicePrototype::Run(WAIServerRequest_ptr session) 
{ 
...
   char *url; 
/* Build the complete URL from the specified suffix. */
   url = session-BuildURL("", "/index.html");
...
}
...

delResponseHeader

Deletes a specified header from the response to be sent to the client. You use this method to remove a header that added when calling the addResponseHeader method.

Syntax

HttpServerReturnType delResponseHeader(in string header); 
C Prototype:
NSAPI_PUBLIC WAIReturnType_t WAIdelResponseHeader(ServerSession_t p, const char *header);

C++ Prototype:
WAIReturnType delResponseHeader(const char *header);

Java Prototype:
public netscape.WAI.HttpServerReturnType delResponseHeader(java.lang.String header);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

header
Name of the header that you want to delete.

Returns

HttpServerReturnType::Success if header was successfully deleted. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if header could not be deleted. The actual return value differs, depending on the language you are using:

Example

The following example in Java removes a header added through the addResponseHeader method.

...
/* Add the Pragma: no-cache header to the response. */
rc = request.addResponseHeader("Pragma", "no-cache"); 
...
/* Remove the Pragma: no-cache header.*/
rc = request.deleteResponseHeader("Pragma"); 
...
/* Start sending the response. */
request.StartResponse(); 
...

See Also

addResponseHeader, getResponseHeader.


getConfigParameter

Obtains the current value of a parameter in the web service's object in the obj.conf file.

For example, if you specify the name-value pair Flavor=Peach in the web service's object:

<Object name="iiopexec"> 
Service fn="IIOPexec" Flavor="Peach"
</Object>
you can get the value Peach by specifying the name Flavor as an argument to this method.

Syntax

HttpServerReturnType getConfigParameter(in string name, 
   out string value);
C Prototype:
NSAPI_PUBLIC WAIReturnType_t WAIgetConfigParameter(ServerSession_t p, const char *name,
   char ** value);

C++ Prototype:
WAIReturnType getConfigParameter(const char *name,
   char *& value);

Java Prototype:
public netscape.WAI.HttpServerReturnType getConfigParameter(java.lang.String name,
   org.omg.CORBA.StringHolder value);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

name
Name of the parameter to retrieve.

value
Value retrieved by this method.

Note for Java Programmers: StringHolder is a class in the org.omg.CORBA package. Holder classes support the passing of out and inout parameters associated with operation requests. For details on this and other Holder classes, see the Netscape ISB for Java Reference Guide.

Returns

HttpServerReturnType::Success if the variable exists and is accessible. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if the variable cannot be found or is not accessible. The actual return value differs, depending on the language you are using:

Example

The following example in Java gets the value of the Flavor parameter in the iiopexec object in the obj.conf file.

...
/* Define a class for your service. */
class MyWebApplicationService extends WAIWebApplicationService { 
...
/* Define the Run method, which is called whenever the client requests your service. */
   public int Run(HttpServerRequest request){ 
   ...
      /* Get the Flavor parameter from the iiopexec object. */
      if (request.getConfigParameter("Flavor", value) == 
         HttpServerReturnType.Success) {
         System.out.println("Flavor: " + value.value + "\n"); 
      }
   ...
   }
...
}

getContext

Retrieves the WAIServerContext object (in C++) or the HTTPServerContext object (in Java) for the server. (For details on this object, see "netscape::WAI::HttpServerContext".) This object holds server information, such as the server's hostname and port number.

Call this function if you want to get information about the server (for example, if you want to get the name and version of the server software, or if you want to determine if the server is running SSL).

Syntax

HttpServerContext getContext(); 
C Prototype:
N/A (you don't need to get the object to call the functions/methods associated with the object)

C++ Prototype:
WAIServerContext_ptr getContext();

Java Prototype:
public netscape.WAI.HttpServerContext getContext();

Returns

The HttpServerContext object for the server.

Example

The following example in C++ gets the WAIServerContext object for the web server and uses that object to get the server's version information.

long 
WebApplicationServicePrototype::Run(WAIServerRequest_ptr session) 
{ 
   ...
   /* Get the WAIServerContext object for the web server. */
   WAIServerContext_ptr context = session->getContext(); 
   ...
   /* Use WAIServerContext to get info on the web server version. */
   char *var;
   if ((var = context->getServerSoftware()) && *var){ 
      printf("Web Server software: %s", var); 
      /* Free the string from memory when done. */
      StringDelete(var); 
   } 
   ...
}

See Also

netscape::WAI::HttpServerContext.


getCookie

Retrieves the cookie from the request headers sent by the client.

Syntax

HttpServerReturnType getCookie(out string cookie); 
C Prototype:
NSAPI_PUBLIC WAIReturnType_t
WAIgetCookie(ServerSession_t p, char ** cookie);

C++ Prototype:
WAIReturnType getCookie(char *& cookie);

Java Prototype:
public netscape.WAI.HttpServerReturnType getCookie(org.omg.CORBA.StringHolder cookie);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

cookie
Value of the cookie.

Note for Java Programmers: StringHolder is a class in the org.omg.CORBA package. Holder classes support the passing of out and inout parameters associated with operation requests. For details on this and other Holder classes, see the Netscape ISB for Java Reference Guide..

Returns

HttpServerReturnType::Success if the cookie was retrieved successfully. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if the cookie could not be retrieved. The actual return value differs, depending on the language you are using:

Description

When requesting a URL from an HTTP server, the client matches the URL against all cookies it has. If the client has cookies from the same domain as the URL, the client includes a line containing the name/value pairs of all matching cookies in the HTTP request headers. The format of that line is as follows:

Cookie: name1=string1; name2=string2... 
For more information on cookies, see "setCookie", the preliminary Netscape cookie specification at http://home.netscape.com/newsref/std/cookie_spec.html, and RFC 2109 ("HTTP State Management Mechanism") at http://www.internic.net/rfc/rfc2109.txt.

Example

The following example in Java checks to see if a cookie is already set on a client before setting a new cookie on the client.

public int Run(HttpServerRequest request){ 
   ...
   org.omg.CORBA.StringHolder 
   cookiebuff = new org.omg.CORBA.StringHolder();
   /* Check to see if the client is returning any cookies. */
   if (request.getCookie(cookiebuff)== HttpServerReturnType.Failure)   
      /* If no cookies have been returned, set a new cookie. */
      request.setCookie("MY_NAME", "MY_VALUE", "", "", "/iiop", false);  
   ...
}

See Also

setCookie.


getRequestHeader

Retrieves a specified header from the client request.

Syntax

HttpServerReturnType getRequestHeader(in string header, 
   out string value);
C Prototype:
NSAPI_PUBLIC WAIReturnType_t WAIgetRequestHeader(ServerSession_t p, const char *name,
   char ** value);

C++ Prototype:
WAIReturnType getRequestHeader(const char *header,
   char *& value);

Java Prototype:
public netscape.WAI.HttpServerReturnType getResponseHeader(java.lang.String header,
   org.omg.CORBA.StringHolder value);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

header
Name of the header to retrieve.

value
The current content of the header retrieved by this method.

Returns

HttpServerReturnType::Success if the header was successfully retrieved. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if the header could not be retrieved. The actual return value differs, depending on the language you are using:

Example

The following example in C++ gets the value of the user-agent header in a client's request.

long 
WebApplicationServicePrototype::Run(WAIServerRequest_ptr session) 
{
   ...
   char *var; 
   /* Get the value of the user-agent header. */
   if (session->getRequestHeader("user-agent", var) == WAISPISuccess){ 
      printf("User agent: %s", var); 
      /* Free the string from memory when done. */
      StringDelete(var); 
   } 
   ...
}

getRequestInfo

Accesses information about the server and a specific HTTP request.

Syntax

HttpServerReturnType getRequestInfo(in string name, 
   out string value);
C Prototype:
NSAPI_PUBLIC WAIReturnType_t
WAIgetRequestInfo(ServerSession_t p, const char *name,
   char ** value);

C++ Prototype:
WAIReturnType getRequestInfo(const char *name,
   char *& value);

Java Prototype:
public netscape.WAI.HttpServerReturnType getRequestInfo(java.lang.String name,
   org.omg.CORBA.StringHolder value);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

name
Name of the variable to retrieve.

value
The current value of the variable.

Note for Java Programmers: StringHolder is a class in the org.omg.CORBA package. Holder classes support the passing of out and inout parameters associated with operation requests. For details on this and other Holder classes, see the Netscape ISB for Java Reference Guide.

The following table lists the names of the variables that you can specify for the name argument.

Table 9.2 getRequestInfo variables and the types of information they represent
Variable Name Description
AUTH_TYPE
Authentication scheme for the request (found from the auth-scheme token in the request).

CLIENT_CERT
Base-64 DER-encoded certificate received from the client if the PathCheck built-in function get-client-cert is called. (See the NSAPI Programmer's Guide for details on this function.)

CONTENT_LENGTH
Length of the content of the client request.

CONTENT_TYPE
MIME type of the content of the client request.

HOST
Name of the client's host machine.

HTTPS
Specifies whether or not SSL is "ON" or "OFF".

HTTPS_KEYSIZE
Number of bits in the session key used to encrypt the session (if SSL is enabled).

HTTPS_SECRETKEYSIZE
Number of bits used to generate the server's private key (if SSL is enabled).

HTTP_*
Value of the specified HTTP_* header (headers with names that begin with the prefix HTTP_).

PATH_INFO
Trailing part of the URI that follows the SCRIPT_NAME part of the path.

PATH_TRANSLATED
The filesystem path to the file requested by the URI.

QUERY_STRING, 
QUERY
The query part of the URI (the name-value pairs following the question mark).

REMOTE_ADDR
IP address of the client sending the request.

REMOTE_HOST
Fully qualified domain name of the client sending the request.

REMOTE_USER
If the client is using the basic authentication scheme, the user ID sent by the client for authentication.

REQUEST_METHOD
Method in which the request was made (for example, GET or POST or HEAD).

SCRIPT_NAME
Part of the URI that identifies the script being executed.

SERVER_PROTOCOL
Name and revision number of the information protocol of the incoming request.

URI
URI requested by the client.

Returns

HttpServerReturnType::Success if the information exists and is accessible. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if the information does not exist or is not accessible. The actual return value differs, depending on the language you are using:

Example

The following example in Java gets the IP address of the client that sent the request.

public int Run(HttpServerRequest request){ 
   ...
   org.omg.CORBA.StringHolder value = new org.omg.CORBA.StringHolder(); 
   /* Get the value of the client's IP address. */
   if (request.getRequestInfo("REMOTE_ADDR", value) == 
      HttpServerReturnType.Success){
      System.out.println("Client addr: %s", value.value + "\n"); 
   }
   ...
}
NOTE: The C function, WAIgetRequestInfo, internally allocates memory for the value string. To free the memory, call WAIstringFree (see StringDelete).

See Also

setRequestInfo


getResponseContentLength

Retrieves the content length of the response to be sent to the client. You use this method to get the value that you set when calling the setResponseContentLength method.

Syntax

HttpServerReturnType getResponseContentLength(
   out unsigned long Length);
C Prototype:
NSAPI_PUBLIC WAIReturnType_t WAIgetResponseContentLength(ServerSession_t p,
   unsigned long *Length);

C++ Prototype:
WAIReturnType
getResponseContentLength(unsigned long& Length);

Java Prototype:
public netscape.WAI.HttpServerReturnType getResponseContentLength(org.omg.CORBA.IntHolder Length);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

Length
Content length of the response.

Note to Java Programmers: IntHolder is a class in the org.omg.CORBA package. Holder classes support the passing of out and inout parameters associated with operation requests. For details on this and other Holder classes, see the Netscape ISB for Java Reference Guide.

Returns

HttpServerReturnType::Success if the content length was successfully fetched. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if the content length could not be determined. The actual return value differs, depending on the language you are using:

Example

The following example in C gets the value of the content length set through the setResponseContentLength method.

long 
MyRunFunction(ServerSession_t obj) 
{
long *length;
...
/* Specify the content to send back to the client. */
char *buffer = "Hello World\n"; 
size_t bufflen = strlen(buffer); 
/* Set the length of this content in the content-length header. */
WAIsetResponseContentLength(obj, bufflen); 
...
/* Get the content-length. */
WAIgetResponseContentLength(obj, &length);
...
}

See Also

setResponseContentLength.


getResponseHeader

Gets a specific header from the response to be sent to the client. You use this method to get the value of a header that added when calling the addResponseHeader method.

Syntax

HttpServerReturnType getResponseHeader(in string header, 
   out string value);
C Prototype:
NSAPI_PUBLIC WAIReturnType_t WAIgetResponseHeader(ServerSession_t p, const char *header,
   char ** value);

C++ Prototype:
WAIReturnType getResponseHeader(const char *header,
   char *& value);

Java Prototype:
public netscape.WAI.HttpServerReturnType getResponseHeader(java.lang.String header,
   org.omg.CORBA.StringHolder value);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

header
Name of the header that you want to retrieve.

value
The current value of the header.

Note for Java Programmers: StringHolder is a class in the org.omg.CORBA package. Holder classes support the passing of out and inout parameters associated with operation requests. For details on this and other Holder classes, see the Netscape ISB for Java Reference Guide.

Returns

HttpServerReturnType::Success if the header was successfully retrieved. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if the header could not be retrieved. The actual return value differs, depending on the language you are using:

Example

The following example in Java gets the value of a header added through the addResponseHeader method.

...
/* Add the Pragma: no-cache header to the response. */
rc = request.addResponseHeader("Pragma", "no-cache"); 
...
/* Get the value of the Pragma header.*/
org.omg.CORBA.StringHolder value = new org.omg.CORBA.StringHolder(); 
rc = request.getResponseHeader("Pragma", value); 
...
/* Start sending the response. */
request.StartResponse(); 
...

See Also

addResponseHeader, delResponseHeader.


LogError

Logs messages to the server error log (server_root/https-server_id/logs/errors).

Syntax

HttpServerReturnType LogError(in long degree, in string func, 
   in string msg, in boolean clientinfo);
C Prototype:
NSAPI_PUBLIC WAIReturnType_t WAILogError(ServerSession_t p,
   long degree, const char *func, const char *msg,
   WAIBool clientinfo);

C++ Prototype:
WAIReturnType LogError(long degree, const char *func,
   const char *msg, WAIBool clientinfo);

Java Prototype:
public
netscape.WAI.HttpServerReturnType LogError(int degree,
   java.lang.String func, java.lang.String msg,
   boolean clientinfo);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

degree
Degree of severity of the error. (This is included in the log entry.)

The degree of severity can be one of the following values:

If you are writing a C/C++ application, you can include the nsapi.h header file and use the defined values for the degree of severity.

func
Name of the function reporting the error. (This function name is included in the log entry. You can use this to help identify which function caused the log entry to be written.)

msg
Message that you want logged.

clientinfo
If true, information about the session (such as the IP address of the client) and request (such as the requested URI) are included in the log entry.

Returns

HttpServerReturnType::Success if the message was successfully logged. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if the message could not be logged. The actual return value differs, depending on the language you are using:

Example

The following lines of code log informational and warning messages.

public int myMethod(HttpServerRequest request){
...
request.LogError(5, "myMethod()", "An informational message.\n", true); 
request.LogError(0, "myMethod()", "A warning message.\n", false); 
...
These lines of code generate the following messages in the server's error log:

[15/May/1997:07:53:49] info: for host 198.95.249.43 trying to GET /iiop/JavaWASP, myMethod() reports: An informational message.
[15/May/1997:07:53:49] warning: myMethod() reports: A warning message. 
Note that in the first entry, the IP address of the client, the method used to access the resource, and the URI of the resource are logged to the entry because LogError is called with the clientinfo argument set to true.


ReadClient

Reads data from the client.

Syntax

long ReadClient(inout HttpServerBuffer buffer);
C Prototype:
NSAPI_PUBLIC long WAIReadClient(ServerSession_t p,
   unsigned char *buffer, unsigned buffsize);

C++ Prototype:
long ReadClient(unsigned char *buffer,
   unsigned buffsize);

Java Prototype:
public int
ReadClient(netscape.WAI.HttpServerBufferHolder buffer);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

buffer
Buffer to receive data from the client.

Note for Java Programmers: HttpServerBufferHolder is a class in the netscape.WAI package. When you construct an object of this class, you need to pass a byte array to the constructor (see the example below).

buffsize
(C/C++ only) Size of the buffer of data.

Returns

Number of bytes read.

Example

The following example in C++ gets data posted from the client (through the HTTP POST method and displays the posted data back to the client in its raw form (in other words, as an unparsed string of name/value pairs).

long 
WebApplicationServicePrototype::Run(WAIServerRequest_ptr session) 
{ 
   ostrstream outstr; 
   char *var = NULL; 
   unsigned contentLength; 
   long status; 
   char *myBuffer = NULL; 
   outstr << "<P><FONT SIZE=+3>Resulting Posted Data</FONT></P>"; 
   /* Get the value of the content-length header.*/
   if (session->getRequestHeader("content-length", var) == 
      WAISPIFailure){
      return 1; 
   } 
   /* Use the content length to allocate memory for the data. */
   contentLength = atoi(var); 
   StringDelete(var); 
   /* Allocate memory for the content plus one byte for the trailing 0. */
   myBuffer = StringAlloc(contentLength+1); 
   if (myBuffer==NULL) { 
      return 1; 
   } 
   myBuffer[contentLength] = '\0'; 
   /* Read the posted data from the client.*/
   status = session->ReadClient((unsigned char*)myBuffer, contentLength); 
   /* Print the raw posted data back to the client. */
   outstr << "\n<PRE>\n<B>Output of the Form:</B>\n\n" << (const char*)myBuffer << "\n</PRE>\n<P>"; 
   StringDelete(myBuffer); 
   outstr << endl; 
   session->setResponseContentLength(outstr.pcount()); 
   session->StartResponse(); 
   session->WriteClient((const unsigned char *)outstr.str(), outstr.pcount()); 
   outstr.rdbuf()->freeze(0); 
   return 0; 
} 
The following example in Java gets data posted from the client (through the HTTP POST method and displays the posted data back to the client in its raw form (in other words, as an unparsed string of name/value pairs).

public int Run(HttpServerRequest request){
/* Set up an output stream to send data back to the client. */
   org.omg.CORBA.StringHolder value = new org.omg.CORBA.StringHolder();
   request.getRequestHeader("content-length", value);
   ByteArrayOutputStream contentStream = new ByteArrayOutputStream();
   /* Create the buffer holder and initialize it the number of bytes to receive.*/
   netscape.WAI.HttpServerBufferHolder inbuff = new netscape.WAI.HttpServerBufferHolder(new byte[1024]);
   Integer content_length = new Integer(value.value);
   int cnt;
   int data_left;
   /* Read the posted data into the buffer holder. */
   for (data_left = content_length.intValue(); data_left > 0; 
      data_left -= cnt){
      cnt = request.ReadClient(inbuff);
      if (cnt == 0)
         data_left = 0;
      else
         contentStream.write(inbuff.value, 0, cnt);
      }
   HttpServerReturnType rc;
   byte[] outbuff = contentStream.toByteArray();
   try {
      rc = request.setResponseContentLength(outbuff.length);
      request.StartResponse();
   }
   catch(org.omg.CORBA.SystemException e){
   }
   catch(java.lang.Exception e) {
      System.err.println(e);
   }
   int write_cnt = request.WriteClient(outbuff);
   return 0;
}

See Also

WriteClient.


RespondRedirect

Sends a page back to the client to notify the client that the page has moved.

Syntax

HttpServerReturnType RespondRedirect (in string url); 
C Prototype:
NSAPI_PUBLIC WAIReturnType_t WAIRespondRedirect(ServerSession_t p, const char *url);

C++ Prototype:
WAIReturnType RespondRedirect(const char *url);

Java Prototype:
public netscape.WAI.HttpServerReturnType RespondRedirect(java.lang.String url);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

url
URL to redirect the client to.

Returns

HttpServerReturnType::Success if redirect was successful. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if the response failed to redirect the client. The actual return value differs, depending on the language you are using:

Description

When you call this method (followed by StartResponse), the server returns the following page to the client:

Moved Temporarily
This document has moved to a new location. Please update your documents and hotlists accordingly.
The word "location" on this page is a link pointing to the new location of the page. The user can choose to click on this link to go to the new location.

If instead you want the client to be automatically redirected to the new location, call addResponseHeader to add the Location header, call setResponseStatus to set a response code of 301 or 302, then call StartResponse to send the response back to the client. For an example of this scenario, see the following sections:


setCookie

Creates a cookie and sends it to the client.

Syntax

HttpServerReturnType setCookie(in string name, in string value,
   in string expires, in string domain, in string path,
   in boolean secure);
C Prototype:
NSAPI_PUBLIC WAIReturnType_t WAIsetCookie(ServerSession_t p,
   const char *name, const char *value, const char *expires,
   const char *domain, const char *path, WAIBool secure);

C++ Prototype:
WAIReturnType setCookie(const char *name, const char *value,
   const char *expires, const char *domain, const char *path,
   WAIBool secure);

Java Prototype:
public netscape.WAI.HttpServerReturnType setCookie(java.lang.String name, java.lang.String value,
   java.lang.String expires, java.lang.String domain,
   java.lang.String path, boolean secure);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

name
A sequence of characters excluding semicolon, comma, and white space. If there is a need to place such data in the name, some encoding method such as URL-style %XX encoding is recommended, though no encoding is defined or required.

value
A sequence of characters excluding semicolon, comma, and white space. If there is a need to place such data in the value, some encoding method such as URL-style %XX encoding is recommended, though no encoding is defined or required. This is the only required attribute of the Set-Cookie header.

expires
Specifies a date string that defines the valid life time of the cookie. Once the expiration date has been reached, the cookie will no longer be stored or given out.

The date string is formatted as: Wdy, DD-Mon-YYYY HH:MM:SS GMT. This is based on RFC 822, RFC 850, RFC 1036, and RFC 1123, with the variations that the only legal time zone is GMT and the separators between the elements of the date must be dashes. expires is an optional attribute. If expires is not specified, the cookie expires when the user's session ends.

domain
Specifies a domain from which cookies can be set. When searching the cookie list for valid cookies, a comparison of the domain attributes of the cookie is made with the Internet domain name of the host from which the URL will be fetched.

If there is a tail match, then the cookie will go through path matching to see if it should be sent. Tail matching means that domain attribute is matched against the tail of the fully qualified domain name of the host. A domain attribute of acme.com would match host names anvil.acme.com as well as shipping.crate.acme.com.

Only hosts within the specified domain can set a cookie for a domain, and domains must have at least two or three periods in them to prevent domains of the form: .com , .edu , and va.us. Any domain that fails within one of seven special top level domains only requires two periods. Any other domain requires at least three. The seven special top level domains are: com, edu, net, org, gov, mil, and int.

The default value of domain is the host name of the server that generated the cookie response.

path
Specifies the subset of URLs in a domain for which the cookie is valid. If a cookie has already passed domain matching, then the pathname component of the URL is compared with the path attribute, and if there is a match, the cookie is considered valid and is sent along with the URL request. The path /sales would match /saleswest and /sales/west.html. The path "/" is the most general path.

If you don't specify a value for path, setCookie uses the path described by the header that contains the cookie.

secure
If secure is set to True, the cookie is transmitted only if the communications channel with the host is a secure one. Currently, this means that secure cookies are sent only to HTTPS (HTTP over SSL) servers. If secure is False, a cookie is considered safe to send in the clear over unsecured channels.

Returns

HttpServerReturnType::Success if cookie was set successfully. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if the cookie could not be set. The actual return value differs, depending on the language you are using:

Examples

See .

See Also

getCookie.


setRequestInfo

This method has no functional use at this time.


setResponseContentLength

Sets the length of the response content.

Syntax

HttpServerReturnType setResponseContentLength(
   in unsigned long Length);
C Prototype:
NSAPI_PUBLIC WAIReturnType_t WAIsetResponseContentLength(ServerSession_t p,
   unsigned long Length);

C++ Prototype:
WAIReturnType setResponseContentLength(unsigned long Length);

Java Prototype:
public netscape.WAI.HttpServerReturnType setResponseContentLength(int Length);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

Length
Content length that you want to set for the response.

Returns

HttpServerReturnType::Success if the content length was successfully set. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if the content length could not be set. The actual return value differs, depending on the language you are using:

Example

The following example in C sets the content-length header for a response before sending the response back to the client.

long 
MyRunFunction(ServerSession_t obj) 
{
...
/* Specify the content to send back to the client. */
char *buffer = "Hello World\n"; 
size_t bufflen = strlen(buffer); 
/* Set the length of this content in the content-length header. */
WAIsetResponseContentLength(obj, bufflen); 
...
}

See Also

getResponseContentLength.


setResponseContentType

Adds a header for the content type for the response. The default content type is text/html.

Syntax

HttpServerReturnType setResponseContentType(
   in string ContentType);
C Prototype:
NSAPI_PUBLIC WAIReturnType_t WAIsetResponseContentType(ServerSession_t p,
   const char *ContentType);

C++ Prototype:
WAIReturnType setResponseContentType(const char *ContentType);

Java Prototype:
public netscape.WAI.HttpServerReturnType setResponseContentType(java.lang.String ContentType);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

Length
Content type that you want to assign to the response.

Returns

HttpServerReturnType::Success if the content type was successfully set. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if the content type could not be set. The actual return value differs, depending on the language you are using:


setResponseStatus

Sets status to the request status code.

Syntax

HttpServerReturnType setResponseStatus(in long status, 
   in string reason);
C Prototype:
NSAPI_PUBLIC WAIReturnType_t WAIsetResponseStatus(ServerSession_t p, long status,
   const char *reason);

C++ Prototype:
WAIReturnType setResponseStatus(long status,
   const char * reason);

Java Prototype:
public netscape.WAI.HttpServerReturnType
setResponseStatus(int status, java.lang.String reason);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

status
Status that you want to assign to the response.

reason
Message that you want associated with the status that you've set. If this argument is NULL, the server attempts to find the standard message for the status code (for example, "File Not Found" for the status code 404).

If no message is found for the status code, the message "Unknown Reason" is used.

Returns

HttpServerReturnType::Success if the status was successfully set. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if the status could not be set. The actual return value differs, depending on the language you are using:


StartResponse

Starts the HTTP response.

If the incoming request specifies that it follows the HTTP 0.9 standard (which does not specify that headers can be included in requests and responses), StartResponse does nothing.

If the request specifies that it follows the HTTP 1.0 (or later) standard (which allows headers in requests and responses), StartResponse sends a header.

Syntax

long StartResponse();

C Prototype:
NSAPI_PUBLIC long WAIStartResponse(ServerSession_t p);

C++ Prototype:
long StartResponse();

Java Prototype:
public int StartResponse();

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

Returns

REQ_NOACTION if the request used the HEAD method (meaning that the body of the resource should not be sent).

REQ_PROCEED otherwise.

Example

The following example in C starts sending a response back to the client after setting the content-length header in the response.

long 
MyRunFunction(ServerSession_t obj) 
{ 
   ...
   /* Specify the length of the content you want to send. */
   WAIsetResponseContentLength(obj, contentLength); 
   /* Start sending the response. */
   WAIStartResponse(obj); 
   ...
} 

WriteClient

Writes data to the client.

Syntax

long WriteClient(in HttpServerBuffer buffer); 
C Prototype:
NSAPI_PUBLIC long WAIWriteClient(ServerSession_t p,
   const unsigned char *buffer, unsigned buffsize);

C++ Prototype:
long WriteClient(const unsigned char *buffer,
   unsigned buffsize);

Java Prototype:
public int WriteClient(byte [] buffer);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

buffer
Buffer of data to write to the client.

buffsize
(C/C++ only) Size of the buffer of data.

Returns

1 if successful or -1 if an error occurs.

Example

The following example in C writes an HTML page containing the words "Hello World" back to the client.

long 
MyRunFunction(ServerSession_t obj) 
{ 
   /* Specify the content to be written. */
   char *buffer = "Hello World\n"; 
   size_t bufflen = strlen(buffer); 
   /* Set the content-length header in the response to be sent to the client.*/
   WAIsetResponseContentLength(obj, bufflen); 
   /* Start sending the response. */
   WAIStartResponse(obj); 
   /* Write the data to the client. */
   WAIWriteClient(obj, (const unsigned char *)buffer, bufflen); 
   return 0; 
} 

See Also

ReadClient.


netscape::WAI::HttpServerContext

The HttpServerContext interface provides access to information about the web server.

This interface is implemented as the following classes:

In C++, you can get access to an WAIServerContext object by calling the getContext method of a WAIServerRequest object. In Java, you can get access to an HTTPServerContext object by calling the getContext method of a HTTPServerRequest object. (See the section "netscape::WAI::HttpServerRequest" for details on these objects.)

You can use the methods of these classes to get the following information on the web server:

Member Summary

The netscape::WAI::HttpServerContext interface describes the following members:

Methods
getHost
Retrieves the host name of the machine running the web server.

getInfo
Retrieves information about the web server (such as the value of CGI 1.1 environment variables that describe the server).

getName
Retrieves the server ID (for example, https-myhost).

getPort
Retrieves the port number that the server listens to.

getServerSoftware
Retrieves the product name and version of the web server (for example, Netscape Enterprise/3.0).

isSecure
Specifies whether or not SSL is enabled on the server.


getHost

Retrieves the hostname of the machine where the web server is running.

Syntax

string getHost(); 
C Prototype:
NSAPI_PUBLIC char *WAIgetHost(ServerSession_t p);

C++ Prototype:
char *getHost();

Java Prototype:
public java.lang.String getHost();

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

Returns

The name of the machine where the web server is running.


getInfo

Retrieves information about the server, such as the server's ID or the value of CGI 1.1 environment variables that describe the server (for example, SERVER_NAME and SERVER_PORT).

Syntax

HttpServerReturnType getInfo(in string name, out string value);  
C Prototype:
WAIBool WAIgetInfo(ServerSession_t p, const char *name,
   char **value);

C++ Prototype:
WAIReturnType getInfo(const char *name, char *&value);

Java Prototype:
public netscape.WAI.HttpServerReturnType getInfo(java.lang.String name,
   org.omg.CORBA.StringHolder value);

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

name
Name of the variable to retrieve.

value
The current value of the variable.

Note for Java Programmers: StringHolder is a class in the org.omg.CORBA package. Holder classes support the passing of out and inout parameters associated with operation requests. For details on this and other Holder classes, see the Netscape ISB for Java Reference Guide.

The following table lists the names of the variables that you can specify for the name argument.

Table 9.3 getInfo variables and the types of information they represent
Variable Name Description
GATEWAY_INTERFACE
CGI version supported by the web server (for example, CGI/1.1).

HTTPS
Specifies whether or not SSL is enabled on the server.

SERVER_ID
Server identifier (for example, https-myhost). Currently, this only works on Windows NT.

SERVER_NAME
Name of the machine running the web server.

SERVER_PORT
Port number that the server listens to.

SERVER_SOFTWARE
Type and version of web server software (for example, Netscape-Enterprise/3.0).

Returns

HttpServerReturnType::Success if the information exists and is accessible. The actual return value differs, depending on the language you are using:

HttpServerReturnType::Failure if the information does not exist or is not accessible. The actual return value differs, depending on the language you are using:


getName

Retrieves the server ID (for example, https-myhost).

Syntax

string getName(); 
C Prototype:
NSAPI_PUBLIC char *WAIgetName(ServerSession_t p);

C++ Prototype:
char *getName();

Java Prototype:
public java.lang.String getName();

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

Returns

The server ID, or an empty string if the information is not accessible.


getPort

Retrieves the number of the port the server listens to.

Syntax

long getPort(); 
C Prototype:
NSAPI_PUBLIC long WAIgetPort(ServerSession_t p);

C++ Prototype:
long getPort();

Java Prototype:
public int getPort();

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

Returns

Port number that the web server listens to.


getServerSoftware

Retrieves the server type and version number (for example, Netscape-Enterprise/3.0).

Syntax

string getServerSoftware();

C Prototype:
NSAPI_PUBLIC char *WAIgetServerSoftware(ServerSession_t p);

C++ Prototype:
char *getServerSoftware();

Java Prototype:
public java.lang.String getServerSoftware();

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

Returns

A string containing the server type and version number.


isSecure

Specifies whether or not SSL is enabled on the server.

Syntax

boolean isSecure(); 
C Prototype:
NSAPI_PUBLIC WAIBool WAIisSecure(ServerSession_t p);

C++ Prototype:
int isSecure();

Java Prototype:
public boolean isSecure();

Parameters

This method has the following parameters:

p
(C only) Handle to the server session object, which is passed as an argument to your callback function.

Returns

True if this server has SSL enabled.


netscape::WAI::WebApplicationService

WebApplicationService is one of the interfaces that represent web services.

Typically, you do not need to use this interface; instead, you work directly with the WAIWebApplicationService base class, which implements netscape::WAI::WebApplicationBasicService interface.


netscape::WAI::WebApplicationBasicService

WebApplicationBasicService is one of the interfaces that represent web services.

Typically, you do not need to use this interface; instead, you work directly with the WAIWebApplicationService base class, which implements this interface.

WebApplicationBasicService is derived from the netscape::WAI::WebApplicationService interface.


WAIWebApplicationService

The WAIWebApplicationService base class represents a web service. You derive your own web service class from this base class.

Member Summary

The WAIWebApplicationService base class contains the following members:

Constructor
WAIWebApplicationService
Creates an instance of this class.

Methods
ActivateWAS
Activates the object (if the object has not already been activated by the constructor).

getServiceInfo
(This is a method that you need to implement.) Provides information about the author, version, and copyright of the web application service that you are writing.

RegisterService
Registers your WAI application with the web server running on the specified host.

Run
(This is a method that you need to implement.) Executes your web application service (this is called whenever the server receives an HTTP request for your service).

StringAlloc
Allocates memory for a string.

StringDelete
Frees a string from memory.

StringDup
Copies a string into a newly allocated buffer in memory.


WAIWebApplicationService

Creates an instance of the WAIWebApplicationService class. Note that in the 3.01 version of the server, the C++ constructor has an additional parameter to allow you to specify whether or not the object is activated when constructed.

If you want to activate the object at a later time, you can call the ActivateWAS method.

Syntax

C Prototype:
WAIcreateWebAppService(const char *name, WAIRunFunction func,
   int argc, char **argv);

C++ Prototype (3.0 version of the server):
WAIWebApplicationService(const char *name);
WAIWebApplicationService(const char *name, int argc,
   char **argv);

C++ Prototype (3.01 version of the server):
WAIWebApplicationService(const char *name);
WAIWebApplicationService(const char *name, WAIBool activateObj);
WAIWebApplicationService(const char *name, int argc,
   char **argv);
WAIWebApplicationService(const char *name, int argc,
   char **argv, WAIBool activateObj);

Java Prototype:
public WAIWebApplicationService(java.lang.String name);

Parameters

This constructor has the following parameters:

name
Name of the instance of the service that you want to create.

WAIRunFunction
(C only) Callback function invoked when an HTTP request for your service is received. This is the function that you define for processing the HTTP request.

For details, see "Run".

argc, argv
(C/C++ only) Allows you to pass command-line arguments into your application. argc is the number of command-line arguments and argv is an array of the arguments.

activateObj
(C++ only) If WAI_TRUE, specifies that the object should be immediately activated upon creation. If WAI_FALSE, you need to activate the object by calling the ActivateWAS method.


ActivateWAS

(3.01 servers only) Allows you to activate the web application service object at some later point in time after the object is constructed. In your application, you can call this method when you are ready to activate the object.

Syntax

C Prototype:
No equivalent function.

C++ Prototype:
void ActivateWAS();

Java Prototype:
No equivalent method.


getServiceInfo

Provides information about the author, version, and copyright of the web application service that you are writing.

This is a virtual/abstract method. You need to define this method when deriving your own class from the WAIWebApplicationService base class.

Syntax

C Prototype:
No equivalent function.

C++ Prototype:
virtual char *getServiceInfo();

Java Prototype:
public abstract java.lang.String getServiceInfo();

Returns

A string containing author, version, and copyright. For example, you might define this function to return the string My Web Application Service v1.0.


RegisterService

Registers your WAI application with the web server running on the specified host.

Syntax

C Prototype:
NSAPI_PUBLIC WAIBool WAIregisterService(IIOPWebAppService_t p,
   const char *host);

C++ Prototype:
WAIBool RegisterService(const char *host);

Java Prototype:
public boolean RegisterService(java.lang.String host);

Parameters

This method has the following parameters:

p
(C only) Handle to the IIOP web application service structure.

host
Name of the host machine where the web server is running. Your WAI application will be registered as a web service on this server.

Returns

WAI_True if your application was successfully registered to the web server.

WAI_False if your application could not be registered to the web server.


Run

Executes the web application service. This method is called by the server when an HTTP request for your service is received.

This is a virtual/abstract method. You need to define this method when deriving your own class from the WAIWebApplicationService base class.

Syntax

C Prototype:
typedef long (*WAIRunFunction)(ServerSession_t session);

C++ Prototype:
virtual long Run(WAIServerRequest_ptr session);

Java Prototype:
public abstract int Run(netscape.WAI.HttpServerRequest session);

Parameters

This method has the following parameters:

session
Reference to the HTTPServerRequest object representing the client's HTTP request (see "netscape::WAI::HttpServerRequest").

Returns:

Status code representing the result of processing the HTTP request.


StringAlloc

Allocates memory for a string.

Syntax

C Prototype:
N/A

C++ Prototype:
char *StringAlloc(size_t size);

Java Prototype:
N/A

Parameters

This method has the following parameters:

size
Size of the string that you want to allocate memory for.

Returns

A buffer for the specified size of string.


StringDelete

Frees a string from memory.

Syntax

C Prototype:
NSAPI_PUBLIC void WAIstringFree(char *s);

C++ Prototype:
void *StringDelete(char *s);

Java Prototype:
N/A

Parameters

This method has the following parameters:

s
String that you want to free from memory.


StringDup

Copies a string into a newly allocated buffer in memory.

Syntax

C Prototype:
N/A

C++ Prototype:
char *StringDup(const char *s);

Java Prototype:
N/A

Parameters

This method has the following parameters:

s
String that you want to copy.

Returns

Copy of the specified string.


netscape::WAI::FormHandler

The FormHandler class handles WAI application submissions through HTML forms. Using the FormHandler class you can write a WAI applications that receives and interprets data submitted through an HTML form.

FormHandler

The FormHandler class defines methods for processing data submitted through HTML forms sent from clients to your server. This class in new in the 3.01 releases of Netscape web servers.

Member Summary

The FormHandler class contains the following members:

Constructor
FormHandler
Creates an instance of this class.

Methods
IsValid
Specifies whether or not the submitted data was successfully parsed by the FormHandler class.

GetQueryString
Gets the query part of the URI (the name-value pairs after the question mark) from the request.

ParseQueryString
Parses the query part of the URI (the name-value pairs after the question mark) from the request.

Get (C++ only)
Gets the value of a specified name-value pair from the parsed form data.

Add (C++ only)
Adds a name-value pair to the parsed form data.

Delete (C++ only)
Removes a name-value pair from the parsed form data.

InitIterator (C++ only)
Sets up a pointer to the beginning of the list of name-value pairs in the parsed form data so that the Next method gets the first name-value pair in the list.

Next (C++ only)
Gets the next name-value pair from the parsed form data.

GetHashTable (Java only)
Returns a hashtable containing the parsed form data.


FormHandler

Creates an instance of the FormHandler class. This constructor reads in and parses the posted form data from the specified request.

Syntax

C++ Prototype:
FormHandler::FormHandler(WAIServerRequest_ptr request);

Java Prototype:
public FormHandler(HttpServerRequest request);

Parameters

This constructor has the following parameters:

request
Reference to the HTTPServerRequest object representing the client's HTTP request.


IsValid

Specifies whether or not the posted data is in a valid format that the server can parse.

You can call this method after creating an instance of the FormHandler class to determine if the constructor sucessfully read and parsed the posted form data.

Syntax

C++ Prototype:
WAIBool IsValid();

Java Prototype:
public boolean IsValid();

Returns

The actual return value differs, depending on the language you are using:


GetQueryString

Gets the query part of the URI (the name-value pairs following the question mark) from an HTTP GET request.

Syntax

C++ Prototype:
char* GetQueryString();

Java Prototype:
public String GetQueryString();

Returns

The query part of the URI (the name-value pairs following the question mark in the URI).


ParseQueryString

Parses the query part of the URI (the name-value pairs following the question mark) from an HTTP GET request. Note that this method does not directly return the parsed data. You need to call one of the following methods to access the parsed data:

Syntax

C++ Prototype:
WAIBool ParseQueryString();

Java Prototype:
public boolean ParseQueryString();

Returns

The actual return value differs, depending on the language you are using:


Get

Gets the value associated with the specified name in the submitted form data. If a name is associated with multiple values, you can call this method in iterations until the method returns NULL.

Syntax

C++ Prototype:
const char* Get(const char* name);

Java Prototype:
N/A

Parameters

This method has the following parameters:

name
Name of the form input that you want to get the value of.

Returns

The value of the specified form input, or NULL if no other values are associated with that input.


Add

Adds a new name-value pair to the parsed form data.

Syntax

C++ Prototype:
WAIBool Add(const char* name, const char* value);

Java Prototype:
N/A

Parameters

This method has the following parameters:

name
Name of the name-value pair that you want to add to the parsed form data.

value
Value of the name-value pair that you want to add to the parsed form data.

Returns

WAI_True if the name-value pair was successfully added, or WAI_False if an error occurred.


Delete

Removes a name-value pair from the parsed form data.

Syntax

C++ Prototype:
WAIBool Delete(const char* name);

Java Prototype:
N/A

Parameters

This method has the following parameters:

name
Name of the name-value pair that you want to remove from the parsed form data.

Returns

WAI_True if the name-value pair was successfully removed, or WAI_False if an error occurred.


InitIterator

Sets up a pointer to the beginning of the list of name-value pairs in the parsed form data so that the Next method gets the first name-value pair in the list.

If you want to iterate through each name-value pair in the parsed form data, call this method before iteratively calling the Next method.

Syntax

C++ Prototype:
WAIBool InitIterator();

Java Prototype:
N/A

Returns

WAI_True if the pointer to the list is successfully set to the beginning of the list, or WAI_False if an error occurred.


Next

Returns the name and value of the next name-value pair in the parsed form data.

To start at the beginning of the list of name-value pairs, call the InitIterator method. To iterate through the entire list, call this method iteratively until it returns the value WAI_False.

Syntax

C++ Prototype:
WAIBool Next(const char* &name, const char* &value);

Java Prototype:
N/A

Parameters

This method has the following parameters:

name
Name of the next name-value pair in the parsed form data.

value
Value of the next name-value pair in the parsed form data.

Returns

WAI_True if the next name-value pair is successfully retrieved, or WAI_False if there are no more name-value pairs or if an error occurred.


GetHashTable

Returns the hashtable containing the parsed form data.

You can call the methods of the java.util.Hashtable class to get data from this hashtable.

Syntax

C++ Prototype:
N/A

Java Prototype:
public Hashtable GetHashTable();

Returns

The hashtable containing the parsed form data.


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

Last Updated: 12/04/97 16:12:55


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