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
-
servlets
-
-
Serve()
- Constructor, default port and log stream.
-
Serve(int)
- Constructor, default log stream.
-
Serve(int, PrintStream)
- Constructor.
-
addDefaultServlets(boolean)
- Register a standard set of Servlets.
-
addDefaultServlets(boolean, String)
- Register a standard set of Servlets, with throttles.
-
addServlet(String, Servlet)
- Register a Servlet.
-
addServlet(String, String)
- Register a Servlet by class name.
-
destroyAllServlets()
- Destroys all currently-loaded servlets.
-
getAttribute(String)
- Returns the value of the named attribute of the network service, or
null if the attribute does not exist.
-
getMimeType(String)
- Returns the MIME type of the specified file.
-
getRealPath(String)
- Applies alias rules to the specified virtual path and returns the
corresponding real path.
-
getServerInfo()
- Returns the name and version of the web server under which the servlet
is running.
-
getServlet(String)
- Gets a servlet by name.
-
getServletNames()
- Enumerates the names of the servlets in this context (server).
-
getServlets()
- Enumerates the servlets in this context (server).
-
log(Exception, String)
- Write a stack trace to the servlet log.
-
log(String)
- Write information to the servlet log.
-
main(String[])
- Main routine, if you want to run this directly as an application.
-
serve()
- Run the server.
servlets
protected Hashtable servlets
Serve
public Serve(int port,
PrintStream logStream)
- Constructor.
Serve
public Serve(int port)
- Constructor, default log stream.
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.
main
public static void main(String args[])
- Main routine, if you want to run this directly as an application.
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.
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.
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:
- If enabled, *.cgi goes to CgiServlet, and gets run as a CGI program.
- * goes to FileServlet, and gets served up as a file or directory.
- Parameters:
- cgi - whether to run CGI programs
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
serve
public void serve()
- Run the server. Returns only on errors.
getServlet
public Servlet getServlet(String name)
- Gets a servlet by name.
- Parameters:
- name - the servlet name
- Returns:
- null if the servlet does not exist
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.
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.
destroyAllServlets
public void destroyAllServlets()
- Destroys all currently-loaded servlets.
log
public void log(String message)
- Write information to the servlet log.
- Parameters:
- message - the message to log
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
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
getMimeType
public String getMimeType(String file)
- Returns the MIME type of the specified file.
- Parameters:
- file - file name whose MIME type is required
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.
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