| 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 .)
- -h(andler)
- The document handler class
(defaults to
FileHandler sunlabs.brazil.handler.FileHandler )
- -c(onfig)
- 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.
- -S(ubstitute)
- Perform ${..} substitutions on the current
values.
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"
|