The following table summarizes the C functions available in WAI.
...
C Prototype:HttpServerReturnType addResponseHeader(in string header,
in string value);
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.
netscape::WAI::HttpServerRequestProvides access to the data in an HTTP request sent from the client to your
server.
netscape::WAI::HttpServerContextProvides access to data about the web server, such as the server's host
name and port number.
netscape::WAI::WebApplicationServicenetscape::WAI::WebApplicationBasicService
Represent the web service that you want to write. Typically, you do not
need to deal with these two interfaces; instead, you work directly from the
WAIWebApplicationService base class, which implements these interfaces.
WAIWebApplicationServiceBase class from which you derive your web service that processes HTTP
requests.
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:
C Prototype:HttpServerReturnType addResponseHeader(in string header,
in string value);
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);
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:
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){
}
...
}
...
}
...
delResponseHeader, getResponseHeader.
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.
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);
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");
...
}
...
addResponseHeader method.
Syntax
C Prototype: HttpServerReturnType delResponseHeader(in string header); 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:
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.
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.
HttpServerReturnType getConfigParameter(in string name,C Prototype:
out string value);
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);
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:
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");
}
...
}
...
}
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.
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);
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:
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.Cookie:name1=string1;name2=string2...
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.
HttpServerReturnType getRequestHeader(C Prototype:instring header,
out string value);
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);
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:
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);
}
...
}
HttpServerReturnType getRequestInfo(C Prototype:instring name,
out string value);
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);
The following table lists the names of the variables that you can specify for the
Table 9.2 getRequestInfo variables and the types of information they representname argument.
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:
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 thevaluestring. To free the memory, callWAIstringFree(seeStringDelete).
setRequestInfo
setResponseContentLength method.
Syntax
HttpServerReturnType getResponseContentLength(
C Prototype:
out unsigned long Length); NSAPI_PUBLIC WAIReturnType_t WAIgetResponseContentLength(ServerSession_t p,
C++ Prototype:
unsigned long *Length);WAIReturnType
Java Prototype:
getResponseContentLength(unsigned long& Length);public netscape.WAI.HttpServerReturnType getResponseContentLength(org.omg.CORBA.IntHolder Length);
Parameters
This method has the following parameters:
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:
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.
addResponseHeader method.
Syntax
HttpServerReturnType getResponseHeader(in string header,
C Prototype:
out string value); NSAPI_PUBLIC WAIReturnType_t WAIgetResponseHeader(ServerSession_t p, const char *header,
C++ Prototype:
char ** value);WAIReturnType getResponseHeader(const char *header,
Java Prototype:
char *& value);public netscape.WAI.HttpServerReturnType getResponseHeader(java.lang.String header,
org.omg.CORBA.StringHolder value); Parameters
This method has the following parameters:
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:
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.
server_root/https-server_id/logs/errors).
HttpServerReturnType LogError(in long degree, in string func,C Prototype:
in string msg, in boolean clientinfo);
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);
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:
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.
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);
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.
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);
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:
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:
HttpServerReturnType setCookie(in string name, in string value,C Prototype:
in string expires, in string domain, in string path,
in boolean secure);
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);
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:
getCookie.
HttpServerReturnType setResponseContentLength(C Prototype:
in unsigned long Length);
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);
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:
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);
...
}
getResponseContentLength.
text/html.
HttpServerReturnType setResponseContentType(C Prototype:
instringContentType);
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);
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:
HttpServerReturnType setResponseStatus(in long status,C Prototype:
in string reason);
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);
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:
NSAPI_PUBLIC long WAIStartResponse(ServerSession_t p);
C++ Prototype: long StartResponse();
Java Prototype: public int StartResponse();
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);
...
}
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);
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.
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:
netscape::WAI::HttpServerContext interface describes the following members:
string getHost();C Prototype:
NSAPI_PUBLIC char *WAIgetHost(ServerSession_t p);
C++ Prototype: char *getHost();
Java Prototype: public java.lang.String getHost();
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.
SERVER_NAME and SERVER_PORT).
HttpServerReturnType getInfo(C Prototype:instringname,outstringvalue);
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);
The following table lists the names of the variables that you can specify for the
Table 9.3 getInfo variables and the types of information they representname argument.
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:
https-myhost).
string getName();C Prototype:
NSAPI_PUBLIC char *WAIgetName(ServerSession_t p);
C++ Prototype: char *getName();
Java Prototype: public java.lang.String getName();
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.
long getPort();C Prototype:
NSAPI_PUBLIC long WAIgetPort(ServerSession_t p);
C++ Prototype: long getPort();
Java Prototype: public int getPort();
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.
Netscape-Enterprise/3.0).
string getServerSoftware();
C Prototype: NSAPI_PUBLIC char *WAIgetServerSoftware(ServerSession_t p);
C++ Prototype: char *getServerSoftware();
Java Prototype: public java.lang.String getServerSoftware();
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.
boolean isSecure();C Prototype:
NSAPI_PUBLIC WAIBool WAIisSecure(ServerSession_t p);
C++ Prototype: int isSecure();
Java Prototype: public boolean isSecure();
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.
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.
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 base class represents a web service. You derive your own web service class from this base class.
WAIWebApplicationService base class contains the following members:
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,
C++ Prototype (3.0 version of the server):
int argc, char **argv);WAIWebApplicationService(const char *name); WAIWebApplicationService(const char *name, int argc,
C++ Prototype (3.01 version of the server):
char **argv);WAIWebApplicationService(const char *name);
Java Prototype:
WAIWebApplicationService(const char *name, WAIBool activateObj);
WAIWebApplicationService(const char *name, int argc,
char **argv);
WAIWebApplicationService(const char *name, int argc,
char **argv, WAIBool activateObj);public WAIWebApplicationService(java.lang.String name);
Parameters
This constructor has the following parameters:
void ActivateWAS();
Java Prototype: 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.
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);
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.
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.
char *StringAlloc(size_t size);
Java Prototype:
size | Size of the string that you want to allocate memory for. |
Returns
A buffer for the specified size of string.
NSAPI_PUBLIC void WAIstringFree(char *s);
C++ Prototype: void *StringDelete(char *s);
Java Prototype:
s | String that you want to free from memory. |
char *StringDup(const char *s);
Java Prototype:
s | String that you want to copy. |
Returns
Copy of the specified string.
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.
FormHandler class contains the following members:
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.
|
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:
char* GetQueryString();
Java Prototype: public String GetQueryString();
Get method to
get the value of a specific name-value pair, or you can call
the InitIterator method and
the Next method to iterate through all
name-value pairs in the parsed data.You can also call theAddmethod to add a new name-value pair to the parsed form data and theDeletemethod to remove a name-value pair from the parsed form data.
GetHashTable method
to get a Java hash table containing the parsed data. Then, you can call methods of the
java.util.Hashtable class to access the data.The names serve as keys in the hashtable. The values are stored as Java
vectors (for details, see your Java documentation on java.util.Vector).
The values are implemented as Java vectors because a given name may be associated with multiple values. For example, if the form contains multiple- selection input, the submitted form data can contain several name-value pairs with the same name but different values.
Syntax
C++ Prototype: WAIBool ParseQueryString();
Java Prototype: public boolean ParseQueryString();
Returns
The actual return value differs, depending on the language you are using:
NULL.
const char* Get(const char* name);
Java Prototype:
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.
WAIBool Add(const char* name, const char* value);
Java Prototype:
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.
WAIBool Delete(const char* name);
Java Prototype:
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.
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.
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.
java.util.Hashtable class to get data from this hashtable.
public Hashtable GetHashTable();
Last Updated: 12/04/97 16:12:55
Any sample code included above is provided for your use on an "AS IS" basis, under the Netscape License Agreement - Terms of Use