java.lang.Object | +----netscape.server.applet.ServerApplet | +----netscape.server.applet.HttpAppletThis class extends ServerApplet, and implements HTTP-specific features of server applets. You should subclass this class, and implement the run method to create server-side Java scripts.
public final static int BAD_REQUEST
protected int boundaryCount
protected static int boundaryGen
protected Vector boundaryStack
public final static int FORBIDDEN
protected Hashtable formData
public final static int NO_RESPONSE
public final static int NOT_FOUND
public final static int NOT_IMPLEMENTED
public final static int NOT_MODIFIED
public final static int OK
public final static int REDIRECT
public final static int SERVER_ERROR
public final static int UNAUTHORIZED
public HttpApplet()
method
request property.
public String getMethod()
"GET"
, "HEAD"
, "POST"
)
public URL getURI() throws MalformedURLException
protocol
request property.
public String getProtocol()
query
request property.
public String getQuery()
path
server property.
public String getPath()
Content-Type
response property.
public void setContentType(String type)
url
server property.
public URL getURL() throws MalformedURLException
OK
.
public boolean returnNormalResponse(String contentType) throws IOExceptionCalls to the returnNormalResponse method may be nested within returnMultipartResponse/endMultipartResponse blocks and will output the appropriate boundary and header information as needed.
if (returnNormalResponse("text/html")) { PrintStream out = getOutputStream(); out.println("<html>< title>Dinner</title>is served</html>"); }
OK
.
public boolean returnNormalResponse(String contentType, File statFile) throws IOException
public void returnFile(String contentType, File file) throws IOException
movie.gif
will be returned as type image/gif
).
public void returnFile(File file) throws IOException
public boolean returnErrorResponse(String contentType, int status, String reason) throws IOException
try { ... } catch (Exception e) { if (returnErrorResponse("text/html", BAD_REQUEST, "advise user: " + e)) { PrintStream out = getOutputStream(); out.println("<html>< title>Wrong!< /title>We're so sorry. Please try again.< /html>"); } }
public boolean returnErrorResponse(String contentType, int status) throws IOException
public synchronized boolean returnMultipartResponse(String subtype) throws IOException
if (returnMultipartResponse("x-mixed-replace")) { PrintStream out = getOutputStream(); // first part is html: returnNormalResponse("text/html"); out.println("<b>Hello< /b> "); // second part is an image returnNormalResponse("image/gif"); String vpath = getConfigProperty("vpath"); File file = new File(translateURI(vpath) + "/movie.gif"); returnFile(file); } endMultipartResponse(); // always end the multipart response
public boolean returnMultipartResponse(String subtype, String boundary) throws IOException
multipart
/" is prepended to this string),
boundary--a String to be used as a boundary marker
public void endMultipartResponse() throws IOException
protected int startResponse() throws IOException
NOACTION
if the request was a HEAD request and thus no body should be sent
PROCEED
if the request was a GET or POST request
public void setStatus(int n, String reason)
reason--a description of the status
public void setStatus(int n)
ABORTED
to indicate that the calling function should not proceed with the request.
public int setFileInfo(File file)
ABORTED
if the file has not changed
PROCEED
otherwise
public String translateURI(String uri)
http://host:port
part. Either prefix or suffix can be null.
public static String uri2url(String prefix, String suffix)
public Hashtable getFormData() throws IOException
if the request does not have form data attached, or any of the parameters the client gave are not valid.
public String getFormField(String fieldName) throws IOException
if the request does not have form data attached, or any of the parameters the client gave are not valid.
text/plain
if left unspecified by the user.
protected int handleRequest(int rq)
java.lang.Object | +----netscape.server.applet.ServerThe public class Server extends Object, and embodies properties of the server.
public InetAddress getAddress()
public InetAddress getListeningAddress()
public int getListeningPort()
public boolean securityActive()
java.lang.Object | +----netscape.server.applet.ServerAppletThis public class extends Object, and specifies the protocol-independent functionality of server applets. Server applets are the Java equivalent of CGI scripts. Subclasses of ServerApplet provide protocol-specific features to client requests (e.g. HttpApplet). Servers instantiate subclasses of ServerApplet to respond to client requests (e.g.
ns-httpd
constructs an HttpApplet for each client request). A server applet corresponds to a session, and the invocation of its run method corresponds to a particular request made during that session.
protected final static int ABORTED
protected final static int EXIT
protected String name
protected final static int NOACTION
protected final static int PROCEED
protected boolean responseStarted
inbuf
netbuf of the Session structure.
protected Socket socket
public ServerApplet()
public Socket getClientSocket()
client
pblock of the Session structure. Of note are the properties:ip
--the IP address of the client
dns
--the DNS name of the remote machine
public String getClientProperty(String name)
pb
pblock parameter of the server application function.
public String getConfigProperty(String name)
headers
pblock of the Request structure.
HTTP requests have RFC822 headers attached, which are actually name-value pairs. Convert the header name you want to access to lowercase, and this function will return its value if the client sent it.
public String getHeader(String name)
User-agent: Mozilla/1.1N
Then: getHeader("user-agent") == "Mozilla/1.1N"
public InputStream getInputStream() throws IOException
public PrintStream getOutputStream() throws IOException
reqpb
pblock of the Request structure.
For HTTP, the request properties include:method
--HTTP method used in the request (usually GET or POST)
uri
--the URI originally requested
protocol
--the protocol identifier sent by the client
query
--any query string (data following a '?'
) sent in the URI
public String getRequestProperty(String name)
srvhdrs
pblock of the Request structure.
public String getResponseProperty(String name)
public static Server getServer()
vars
pblock of the Request structure. The set of active variables is different depending on which step of the request the server is processing.
public String getServerProperty(String name)
protected int handleRequest(int rq)
PROCEED
on success, or if an exception is thrown
EXIT
if the applet has started a response
ABORTED
if the applet has not yet started a response
NOACTION
otherwise
public void inform(String error)
public void reportMisconfiguration(String error)
public void reportCatastrophe(String error)
public void reportFailure(String error)
public void reportSecurity(String error)
public void run() throws Exception
srvhdrs
pblock of the Request structure.
public void setResponseProperty(String name, String value)
public void warn(String error)
java.lang.Object | +----netscape.server.applet.URIUtilThe public class URIUtil extends Object, and provides utilities for dealing with URIs in ways a typical server application might need to. The terms used in this section are as follows:
Example: http://engine.org/valve/
Example: /valve/
../
./
or //
in the URI. Although such URIs are legal, the Netscape server will not allow them, and will not parse them into other forms because it wants to make sure that only one URL can refer to each document.
public static boolean isEvil(String uri)
public static Hashtable splitFormData(String data)
?
, #
, and :
characters will be escaped, which is why this function should not be used for URLs. Returns a new String with characters that should be encoded replaced with %xx
according to URL conventions.
public static String uriEscape(String uri)
?
, #
, and :
escaped
?
, #
, and :
characters are not escaped, making this function suitable for URLs. Returns a new String with characters that should be encoded replaced with %xx according to URL conventions.
public static String urlEscape(String url)
?
, #
, and :
escaped
%xx
characters into their character equivalents. Returns a new String with the decoded message.
public static String urlUnescape(String url) throws NumberFormatException
?
, #
, and :
restored
when given a String with %
characters but no number after it, such as
foo%bar
.