sunlabs.brazil.handler
Class ConfigFileHandler

java.lang.Object
  extended by sunlabs.brazil.handler.ConfigFileHandler (view source)
All Implemented Interfaces:
Handler

public class ConfigFileHandler
extends Object
implements 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 (not implemented).
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.
If "%" is specified in the file name, a new session file is created only if 1) a property is changed from the default, and 2) A cookie was received by the browser.

See also: SetTemplate which is preferrable in most cases, providing a templated based (instead of URL based) mechanism for maintaining persistent properties.


Constructor Summary
ConfigFileHandler()
           
 
Method Summary
 boolean init(Server server, String prefix)
          Make sure default properties exist before starting this handler, or that "match" is specified".
 boolean respond(Request request)
          Extract the session state into the request object, optionally modifying the properties.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConfigFileHandler

public ConfigFileHandler()
Method Detail

init

public boolean init(Server server,
                    String prefix)
Make sure default properties exist before starting this handler, or that "match" is specified".

Specified by:
init in interface Handler
Parameters:
server - The HTTP server that created this Handler. Typical Handlers will use Server.props to obtain run-time configuration information.
prefix - The handlers name. The string this Handler may prepend to all of the keys that it uses to extract configuration information from Server.props. This is set (by the Server and ChainHandler) to help avoid configuration parameter namespace collisions.
Returns:
true if this Handler initialized successfully, false otherwise. If false is returned, this Handler should not be used.

respond

public boolean respond(Request request)
                throws IOException
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 interface Handler
Parameters:
request - The Request 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 calling Request.sendResponse() or Request.sendError.
Throws:
IOException - if there was an I/O error while sending the response to the client. Typically, in that case, the Server 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 a FileNotFoundException due to not being able to open a file). In that case, the Handler's duty is to turn that IOException into a HTTP response indicating, in this case, that a file could not be found.


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