Class ChainHandler
java.lang.Object
sunlabs.brazil.server.ChainHandler
- All Implemented Interfaces:
Handler
- Direct Known Subclasses:
ChainSawHandler
Allows multiple handlers to be invoked sequentially for a single HTTP
request. A list of handlers is supplied when this
ChainHandler is initialized. When an HTTP request is
received by this ChainHandler, each of the handlers from the
list is called in turn until one of them responds and returns
true.
A useful trick is that some handlers can be run by a
ChainHandler for their side effects. The handler can modify
the Request object and then return false; the
next handler in the list will get a crack at the modified request.
The following configuration parameters eare used to initialize this
Handler:
-
handlers - A list of
Handlernames that will be invoked in the given order to handle the request. These are considered the "wrapped" handlers. These handlers will all be initialized at startup byinit(Server, String). For each name in the list, the propertyname.classis examined to determine which class to use for this handler. Thennameis used as the prefix in the handler's init() method. -
report - If set, this property will be set to the name of the handler that handled the request (e.g. returned true).
-
exitOnError - If set, the server's
initFailurewill set any of the handlers fail to initialize. No handler prefix is required. prefix, suffix, glob, match- Specify the URL that triggers this handler.
- Version:
- 2.5
- Author:
- Stephen Uhler (stephen.uhler@sun.com), Colin Stevens (colin.stevens@sun.com)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanA flag to require the successfull initialization of all handlers.Handler[]The array of handlers that will be invoked to handle the request.The URL that must match for this handler to runString[]The names of the abovehandlersas specified by the configuration parameters.The prefix used to initialize thisChainHandler, used for logging.The name (if any) of the property to receive the name of the handler that handled the request. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanInitializes thisChainHandlerby initializing all the "wrapped" handlers in the list of handlers.static HandlerinitHandler(Server server, String prefix, String name) Helper function that allocates and initializes a newHandler, given its name.booleanCalls each of theHandlers in turn until one of them returnstrue.
-
Field Details
-
handlers
The array of handlers that will be invoked to handle the request. -
names
The names of the abovehandlersas specified by the configuration parameters. Used for logging the names of eachHandleras it is invoked. -
prefix
The prefix used to initialize thisChainHandler, used for logging. -
isMine
The URL that must match for this handler to run -
report
The name (if any) of the property to receive the name of the handler that handled the request. -
exitOnError
public boolean exitOnErrorA flag to require the successfull initialization of all handlers.
-
-
Constructor Details
-
ChainHandler
public ChainHandler()
-
-
Method Details
-
init
Initializes thisChainHandlerby initializing all the "wrapped" handlers in the list of handlers. If a wrapped handler cannot be initialized, this method logs a message and skips it. If no handlers were specified, or no handlers were successfully initialized, then the initialization of thisChainHandleris considered to have failed. -
initHandler
Helper function that allocates and initializes a newHandler, given its name. In addition to theChainHandler, several other handlers contain embeddedHandlers -- this method can be used to initialize those embeddedHandlers.If there is an error initializing the specified
Handler, this method will log a dignostic message to the server and returnnull. This happens if the specified class cannot be found or instantiated, if the specified class is not actually aHandler, if theHandler.initmethod returnsfalse, or if there is any other exception.- Parameters:
server- The server that will own the newHandler. Mainly used for the server's properties, which contain the configuration parameters for the new handler.prefix- The prefix in the server's properties for the newHandler's configuration parameters. The prefix is prepended to the configuation parameters used by theHandler.name- The name of the newHandler. The name can be one of two forms:- The name of the Java class for the
Handler. ThisHandlerwill be initialized using theprefixspecified above. - A symbolic
name. The configuration parametername.classis the name of the Java class for theHandler. The aboveprefixwill be ignored and thisHandlerwill be initialized with the prefix "name." (the symbolic name followed by a ".").
- The name of the Java class for the
- Returns:
- The newly allocated
Handler, ornullif theHandlercould not be allocated.
-
respond
Calls each of theHandlers in turn until one of them returnstrue.- Specified by:
respondin interfaceHandler- Parameters:
request- The HTTP request.- Returns:
trueif one of theHandlers returnstrue,falseotherwise.- Throws:
IOException- if one of theHandlers throws anIOExceptionwhile responding.
-