Sample main program for starting an http server.
A new thread is started for each
Server,
listening on a socket for HTTP connections.
As each connection is accepted, a
Request object is constructed,
and the registered
Handler is called.
The configuration properties required by the server
and the handler (or handlers), are gathered
from command line arguments and configuration files specified on the
command line.
The command line arguments are processed in order from left to
right, with the results being accumulated in a properties object.
The server is then started with Server.props set to the
final value of the properties.
Some of the properties are interpreted directly by the server,
such as the port to listen on, or the handler to use
(see Server for the complete list). The rest
are arbitrary name/value pairs that may be used by the handler.
Although any of the options may be specified as name/value pairs,
some of them: the ones interpreted by the server, the default
handler (FileHandler, or Main,
may be prefixed with a "-".
Those options are explained below:
-p(ort)
The network port number to run the server on (defaults to 8080)
-r(oot)
The document root directory, used by the FileHandler (defaults to .)
A java properties file to add to the current properties.
There may be several -config options. Each
file is added to the current properties.
If the properties file contains a root
property, it is treated specially. See below.
If the config file is not found in the filesystem,
it is read from the jar file, with this class as the
virtual current directory if a relative path
is provided.
-i(p)
A space seperated list of hosts allowed to access this server
If none are supplied, any host may connect. The ip addresses
are resolved once, at startup time.
-l(og)
The log level (0->none, 5->max)
Causes diagnostic output on the standard output.
-s(tart)
Start a server.
Allows multiple servers to be started at once.
As soon as a -s is processed, as server is
started as if all the options had been processed,
then the current properties are cleared.
Any options that follow are used for the next server.
Following these options, any additional additional pairs of
names and values (no "-"'s allowed) are placed directly in
Server.props.
If the resource "/sunlabs/brazil/server/config" is found, it is used
to initialize the configuration.
If a non absolute root property is specified in a
configuration file, it is modified to resolve relative to the
directory containing the configuration file, and not the directory
in which the server was started. If multiple configuration files
with root properties (or -r options, or "root" properties)
are specified, the last one tekes precidence.
The "serverClass" property may be set to the string to use as the server's
class, instead of "sunlabs.brazil.server.server"
initProps(Properties config)
Initialize a properties file with some standard mime types
The FileHandler only delivers files whose suffixes
are known to map to mime types.
public static boolean startServer(Properties config)
Start a server using the supplied properties. The following
entries are treated. Specially:
handler
The name of the handler class (defaults to file handler)
host
The host name for this server
log
Diagnostic output level 0-5 (5=most output)
maxReqests
max number of requests for a single socket (default 25)
listenQueue
max size of the OS'slisten queue for server sockets
maxThreads
max number of threads allowed (defaults to 250)
port
Server port (default 8080)
defaultPrefix
prefix into the properties file, normally the empty string "".
restrict
list of hosts allowed to connect (defaults to no restriction)
interfaceHost
If specified, a host name that represents the network to server.
This is for hosts with multiple ip addresses. If no network
host is specified, then connections for all interfaces are
accepted
Parameters:
config - The configuration properties for the server
Initialize a properties file with some standard mime types
The FileHandler only delivers files whose suffixes
are known to map to mime types. The server is started with
the suffixes: .html, .txt, .gif, .jpg, .css, .class, and .jar
predefined. If additional types are required, they should be supplied as
command line arguments.