sunlabs.brazil.server
Class Main

java.lang.Object
  extended by sunlabs.brazil.server.Main (view source)

public class Main
extends Object

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 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.
-D(elay) n
delay "n" seconds. This is useful in conjuction with "-s" to allow the previous server to initialize before proceeding.
-S(ubstitute)
Perform ${..} substitutions on the current values.
-x
Don't read the default resource config (only if first).

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 precedence.

The "serverClass" property may be set to the string to use as the server's class, instead of "sunlabs.brazil.server.Server"


Constructor Summary
Main()
           
 
Method Summary
static Object initObject(Server server, String name)
           
static void 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.
static void main(String[] args)
           
static boolean startServer(Properties config)
          Start a server using the supplied properties.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Main

public Main()
Method Detail

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception

startServer

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)
maxRequests
max number of requests for a single socket (default 25) when using persistent connections.
listenQueue
max size of the OS's listen queue for server sockets
maxPost
max size of a content-length for a Post or Put in bytes. (defaults to 2Meg). The absolute limit is 2GB.
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)
timeout
The maximum time to wait for a client to send a complete request. Defaults to 30 seconds.
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
defaultUrlPrefix
overrides the default URL prefix of "/" used by MatchString. In normal (e.g. non proxy) servers, URL's (e.g. the part specified in the first line of the HTTP request) always starts with "/".

Parameters:
config - The configuration properties for the server

initObject

public static Object initObject(Server server,
                                String name)

initProps

public static void 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. The server is started with the suffixes: .html, .txt, .gif, .jpg, pdf, .png, .css, .class, and .jar predefined. If additional types are required, they should be supplied as command line arguments.


Version Kenai-svn-r24, Generated 08/18/09
Copyright (c) 2001-2009, Sun Microsystems.