Package sunlabs.brazil.handler
Class ConfigFileHandler
java.lang.Object
sunlabs.brazil.handler.ConfigFileHandler
- All Implemented Interfaces:
Handler
Handler for manipulating per-user session state that can be
represented as ASCII name/value pairs. The state for each session
is stored in a file, which is expected to be in java properties format.
If "prefix" is matched, the contents of the (usually cached) config file
for the current session is added to the request properties.
If the url matches the "set" property, the contents of the config
file are changed based on the supplied query parameters (either GET
of POST). If no config file exists for the session, one is created
from a default properties file. Only properties already in the
config file may be changed using the "set" method.
If a "%" is specified in the file name, it is replaced by the
SessionID property, if any, or "common" if sessions aren't used.
This should be replaced with something more general, so we can have
more arbitrary mappings between request and the session info.
The following request properties are used:
- prefix
- The URL prefix required for all documents
- set
- The url pattern to match setting properties. Currently, it must also match "prefix".
- noContent
- a url, matching the "set" pattern that causes a "204 no content" to be returned to the client (experimental).
- name
- The name of the config file. the first "%" is replaced by the current SessionID.
- default
- The default properties file to "seed" session properties
- glob
- Properties that match this "glob" pattern may be set using the "set" pattern. If this property is specified, the "default" property is optional.
- root
- The document root (no properties prefix required). If the "name" or "default" properties don't start with a "/", this is used as the current directory.
See also: SetTemplate
which is preferrable in most cases, providing a templated based
(instead of URL based)
mechanism for maintaining persistent properties.
- Version:
- 2.2, 04/08/30
- Author:
- Stephen Uhler
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
ConfigFileHandler
public ConfigFileHandler()
-
-
Method Details
-
init
Make sure default properties exist before starting this handler, or that "match" is specified".- Specified by:
init
in interfaceHandler
- Parameters:
server
- The HTTP server that created thisHandler
. TypicalHandler
s will useServer.props
to obtain run-time configuration information.prefix
- The handlers name. The string thisHandler
may prepend to all of the keys that it uses to extract configuration information fromServer.props
. This is set (by theServer
andChainHandler
) to help avoid configuration parameter namespace collisions.- Returns:
true
if thisHandler
initialized successfully,false
otherwise. Iffalse
is returned, thisHandler
should not be used.
-
respond
Extract the session state into the request object, optionally modifying the properties. If the properties are modified, they are stored in a file for safe keeping.- Specified by:
respond
in interfaceHandler
- Parameters:
request
- TheRequest
object that represents the HTTP request.- Returns:
true
if the request was handled. A request was handled if a response was supplied to the client, typically by callingRequest.sendResponse()
orRequest.sendError
.- Throws:
IOException
- if there was an I/O error while sending the response to the client. Typically, in that case, theServer
will (try to) send an error message to the client and then close the client's connection.The
IOException
should not be used to silently ignore problems such as being unable to access some server-side resource (for example getting aFileNotFoundException
due to not being able to open a file). In that case, theHandler
's duty is to turn thatIOException
into a HTTP response indicating, in this case, that a file could not be found.
-