Interface Handler
-
- All Known Subinterfaces:
Filter
- All Known Implementing Classes:
AclSwitchHandler,AsteriskAGIHandler,AsteriskHandler,BasicAuthHandler,CacheManager,CgiHandler,ChainHandler,ChainSawHandler,ChownHandler,ConfigFileHandler,CookieFilter,CookieSessionHandler,CopyContentFilter,DefaultFileHandler,DeferredHandler,DelayHandler,DialogHandler,DigestAuthHandler,DirectoryHandler,DirectoryTemplate,DynamicConfigHandler,ExecFilter,ExprPropsHandler,FileHandler,FilterHandler,GenericProxyHandler,HistoryFilter,HomeDirHandler,JunkBusterHandler,LogHandler,MD5Filter,MultiHostHandler,MultipartSetTemplate,MultiProxyHandler,NotFoundHandler,PlainFilter,PollHandler,PropertiesCacheManager,PropertiesHandler,ProxyHandler,ProxyPropertiesHandler,PublishHandler,PushHandler,PutHandler,ReFilter,ReflectHandler,ReplaceFilter,RePollHandler,ResourceHandler,ResourceLimitHandler,RestartHandler,RestartingMultiHostHandler,RestrictClientHandler,RolesHandler,SessionFilter,SetTemplate,SimpleSessionHandler,SMTPHandler,StunnelHandler,SubstPropsHandler,SunNetAuthHandler,SunProxy,SupplyHandler,TemplateFilter,TemplateHandler,UrlMapFilter,UrlMapperHandler,UrlSessionFilter,VirtualHostHandler
public interface HandlerThe interface for writing HTTP handlers. Provides basic functionality to accept HTTP requests and dispatch to methods that handle the request.The
init(Server, String)method is called before thisHandlerprocesses the first HTTP request, to allow it to prepare itself, such as by allocating any resources needed for the lifetime of theserver.The
respond(Request)method is called to handle an HTTP request. This method, and all methods it calls must be thread-safe since they may handle HTTP requests from multiple sockets concurrently. However, each concurrent request gets its own individualRequestobject.Any instance variables should be initialized in the
init(Server, String), and only referenced, but not set in therespond(Request)method. If any state needs to be retained, it should be done either by associating it with theRequestobject, or using thesession manager. Class statics should be avoided, as it is possible, and even common to run multiple unrelated Brazil servers in the same JVM. As above, thesession managershould be used instead.- Version:
- 2.3
- Author:
- Stephen Uhler (stephen.uhler@sun.com), Colin Stevens (colin.stevens@sun.com)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleaninit(Server server, java.lang.String prefix)Initializes the handler.booleanrespond(Request request)Responds to an HTTP request.
-
-
-
Method Detail
-
init
boolean init(Server server, java.lang.String prefix)
Initializes the handler.- Parameters:
server- The HTTP server that created thisHandler. TypicalHandlers will useServer.propsto obtain run-time configuration information.prefix- The handlers name. The string thisHandlermay prepend to all of the keys that it uses to extract configuration information fromServer.props. This is set (by theServerandChainHandler) to help avoid configuration parameter namespace collisions.- Returns:
trueif thisHandlerinitialized successfully,falseotherwise. Iffalseis returned, thisHandlershould not be used.
-
respond
boolean respond(Request request) throws java.io.IOException
Responds to an HTTP request.- Parameters:
request- TheRequestobject that represents the HTTP request.- Returns:
trueif the request was handled. A request was handled if a response was supplied to the client, typically by callingRequest.sendResponse()orRequest.sendError.- Throws:
java.io.IOException- if there was an I/O error while sending the response to the client. Typically, in that case, theServerwill (try to) send an error message to the client and then close the client's connection.The
IOExceptionshould not be used to silently ignore problems such as being unable to access some server-side resource (for example getting aFileNotFoundExceptiondue to not being able to open a file). In that case, theHandler's duty is to turn thatIOExceptioninto a HTTP response indicating, in this case, that a file could not be found.
-
-