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 Handler
The 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 thisHandler
processes 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 individualRequest
object.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 theRequest
object, 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 manager
should 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 boolean
init(Server server, java.lang.String prefix)
Initializes the handler.boolean
respond(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
. 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
boolean respond(Request request) throws java.io.IOException
Responds to an HTTP request.- 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:
java.io.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.
-
-