The DynamicConfigHandler allows the user to change the
configuration of the server and its handlers on the fly. This handler
can therefore be used to swap in and out functionality, for example,
by dynamically adding a new AuthHandler to add a new
form of authentication to a running server.
This handler uses a special set of URLs to allow a new set of
configuration properties to be uploaded. The new configuration
replaces the old configuration.
The name of another Handler is supplied when this
DynamicConfigHandler is initialized. This Handler
is the helper or sub-handler for the DynamicConfigHandler .
When the DynamicConfigHandler receives a regular HTTP
request (that matches the URL prefix described below), it redirects
that request to the respond method of the sub-handler.
The uploaded configuration properties are kept in a separate properties
object from the server's properties. The server's properties
are in fact not accessible from the sub-handler; the sub-handler can
only access and/or change the properties owned by the
DynamicConfigHandler .
This handler uses the following configuration properties:
- handler
- The name of the initial sub-handler that this
DynamicConfigHandler will use to process requests. When
new properties are uploaded, the sub-handler will be replaced with
whatever is specified in the newly uploaded handler
property.
- prefix
- Only URLs beginning with this string will be redirected to the
sub-handler. This property belongs to the
DynamicConfigHandler and is not changed when
new properties are uploaded. The default is "/".
- config
- URLs beginning with this prefix can be used to upload or download
new configuration properties to this handler, which will also
dynamically change which sub-handler is installed. This property
belongs to the
DynamicConfigHandler and is not
changed when new properties are uploaded. The default
is "/config/".
Properties may be uploaded by sending them as "name=value" pairs in
the body of a POST or in the "?" query parameters. The URL for
uploading properties is "config/set".
The current set of properties may be retrieved from this handler by
sending the URL "config/get"
A sample set of configuration parameters illustrating how to use this
handler follows:
handler=sunlabs.brazil.server.ChainHandler
port=8081
log=5
handlers=dyn cgi
dyn.class=sunlabs.brazil.server.DynamicConfigHandler
dyn.prefix=/sparky/
dyn.config=/config-sparky/
dyn.handler=chain
chain.class=sunlabs.brazil.server.ChainHandler
chain.handlers=foo baz garply
foo.class=sunlabs.brazil.handler.HomeDirHandler
foo.home=/home/users/
baz.class=sunlabs.brazil.handler.FileHandler
garply.class=sunlabs.brazil.handler.NotFoundHandler
garply.root="/errors/"
garply.fileName="nofile.html"
cgi.class = sunlabs.brazil.handler.CgiHandler
.
.
.
These parameters set up a normal Server on port 8081,
running a ChainHandler which dispatches to a
DynamicConfigHandler and a CgiHandler .
The DynamicConfigHandler will listen for HTTP requests
beginning with "/sparky/" and dispatch to its dynamically generated
list of handlers, and listen for requests beginning with "/config-sparky/"
to dynamically change that set of handlers.
To give this DynamicConfigHandler something to do, an initial
set of handlers is provided with the same prefix ("dyn") as the
DynamicConfigHandler itself. The prefix is stripped off
those properties and the revised set of properties is passed to the
DynamicConfigHandler to initialize its dynamically
configurable world.
author: Colin Stevens (colin.stevens@sun.com) version: 1.5, 00/12/11 |