All Packages  Class Hierarchy  This Package  Previous  Next  Index


Class Acme.Serve.Serve

java.lang.Object
   |
   +----Acme.Serve.Serve

public class Serve
extends Object
implements ServletContext
Minimal Java HTTP server class.

This class implements a very small embeddable HTTP server. It runs Servlets compatible with the API used by JavaSoft's JavaServer server. It comes with default Servlets which provide the usual httpd services, returning files and directory listings.

This is not in any sense a competitor for JavaServer. JavaServer is a full-fledged HTTP server and more. Acme.Serve is tiny, about 1500 lines, and provides only the functionality necessary to deliver an Applet's .class files and then start up a Servlet talking to the Applet. They are both written in Java, they are both web servers, and they both implement the Servlet API; other than that they couldn't be more different.

This is actually the second HTTP server I've written. The other one is called thttpd, it's written in C, and is also pretty small although much more featureful than this.

Other Java HTTP servers:

A June 1997 BYTE magazine article mentioning this server.
A December 1997 BYTE magazine article giving it an Editor's Choice Award of Distinction.
Fetch the software.
Fetch the entire Acme package.

See Also:
HttpServlet, FileServlet, CgiServlet

Variable Index

 o servlets

Constructor Index

 o Serve()
Constructor, default port and log stream.
 o Serve(int)
Constructor, default log stream.
 o Serve(int, PrintStream)
Constructor.

Method Index

 o addDefaultServlets(boolean)
Register a standard set of Servlets.
 o addDefaultServlets(boolean, String)
Register a standard set of Servlets, with throttles.
 o addServlet(String, Servlet)
Register a Servlet.
 o addServlet(String, String)
Register a Servlet by class name.
 o destroyAllServlets()
Destroys all currently-loaded servlets.
 o getAttribute(String)
Returns the value of the named attribute of the network service, or null if the attribute does not exist.
 o getMimeType(String)
Returns the MIME type of the specified file.
 o getRealPath(String)
Applies alias rules to the specified virtual path and returns the corresponding real path.
 o getServerInfo()
Returns the name and version of the web server under which the servlet is running.
 o getServlet(String)
Gets a servlet by name.
 o getServletNames()
Enumerates the names of the servlets in this context (server).
 o getServlets()
Enumerates the servlets in this context (server).
 o log(Exception, String)
Write a stack trace to the servlet log.
 o log(String)
Write information to the servlet log.
 o main(String[])
Main routine, if you want to run this directly as an application.
 o serve()
Run the server.

Variables

 o servlets
 protected Hashtable servlets

Constructors

 o Serve
 public Serve(int port,
              PrintStream logStream)
Constructor.

 o Serve
 public Serve(int port)
Constructor, default log stream.

 o Serve
 public Serve()
Constructor, default port and log stream. We don't use 80 as the default port because we don't want to encourage people to run a Java web server as root because Java currently has no way of giving up root privs! Instead, the current default port is 9090.

Methods

 o main
 public static void main(String args[])
Main routine, if you want to run this directly as an application.

 o addServlet
 public void addServlet(String urlPat,
                        String className)
Register a Servlet by class name. Registration consists of a URL pattern, which can contain wildcards, and the class name of the Servlet to launch when a matching URL comes in. Patterns are checked for matches in the order they were added, and only the first match is run.

 o addServlet
 public void addServlet(String urlPat,
                        Servlet servlet)
Register a Servlet. Registration consists of a URL pattern, which can contain wildcards, and the Servlet to launch when a matching URL comes in. Patterns are checked for matches in the order they were added, and only the first match is run.

 o addDefaultServlets
 public void addDefaultServlets(boolean cgi)
Register a standard set of Servlets. These will return files or directory listings, and run CGI programs, much like a standard HTTP server.

Because of the pattern checking order, this should be called after you've added any custom Servlets.

The current set of default servlet mappings:

Parameters:
cgi - whether to run CGI programs
 o addDefaultServlets
 public void addDefaultServlets(boolean cgi,
                                String throttles) throws IOException
Register a standard set of Servlets, with throttles.

Parameters:
cgi - whether to run CGI programs
throttles - filename to read FileServlet throttle settings from
 o serve
 public void serve()
Run the server. Returns only on errors.

 o getServlet
 public Servlet getServlet(String name)
Gets a servlet by name.

Parameters:
name - the servlet name
Returns:
null if the servlet does not exist
 o getServlets
 public Enumeration getServlets()
Enumerates the servlets in this context (server). Only servlets that are accesible will be returned. This enumeration always includes the servlet itself.

 o getServletNames
 public Enumeration getServletNames()
Enumerates the names of the servlets in this context (server). Only servlets that are accesible will be returned. This enumeration always includes the servlet itself.

 o destroyAllServlets
 public void destroyAllServlets()
Destroys all currently-loaded servlets.

 o log
 public void log(String message)
Write information to the servlet log.

Parameters:
message - the message to log
 o log
 public void log(Exception exception,
                 String message)
Write a stack trace to the servlet log.

Parameters:
exception - where to get the stack trace
message - the message to log
 o getRealPath
 public String getRealPath(String path)
Applies alias rules to the specified virtual path and returns the corresponding real path. It returns null if the translation cannot be performed.

Parameters:
path - the path to be translated
 o getMimeType
 public String getMimeType(String file)
Returns the MIME type of the specified file.

Parameters:
file - file name whose MIME type is required
 o getServerInfo
 public String getServerInfo()
Returns the name and version of the web server under which the servlet is running. Same as the CGI variable SERVER_SOFTWARE.

 o getAttribute
 public Object getAttribute(String name)
Returns the value of the named attribute of the network service, or null if the attribute does not exist. This method allows access to additional information about the service, not already provided by the other methods in this interface.


All Packages  Class Hierarchy  This Package  Previous  Next  Index

ACME Java  ACME Labs