All Packages Class Hierarchy This Package Previous Next Index
Interface org.webmacro.servlet.Handler
- public interface Handler
Framework for handling template requests, requested by reactor.
Anything which implements this interface can be used as a handler
to process web requests.
How to use:
- . Define a name for your new Handler. It must be alphanumeric.
- . Set that to be a valid servlet name for WebMacro in your
servlet.properties file (if using servletrunner, otherwise
name your servlet this using the interface in your runner)
- . Set the script prefix to be the prefix added by servletrunner
in the config file. eg: "ScriptName = /servlet/"
- . Register your Handler against the Reactor class by calling
Reactor.register(handler)
When a request comes in, WebMacro loads the handler that matches
the script name of the request. It will search the ClassPath looking
for a script with the same fully qualified name as the script name,
which more or less means your handler should probably not be in any
particular package.
- See Also:
- GenericHandler
-
accept(WebContext)
- This is the primary method you override to create a new handler.
-
destroy()
- You may use this method to save persistent state on exit.
-
init()
- Use this method to run any startup initialization that you need
to perform.
-
toString()
- You SHOULD override this method and provide a short name by
which your handler is known.
accept
public abstract Template accept(WebContext contextData) throws HandlerException
- This is the primary method you override to create a new handler.
Incoming requests ultimately get passed to this method of your
handler, at which point it is up to you to decide what to do.
You must return a template--which will be used to format the
data you have inserted into the supplied WebContext.
If you throw an Exception it will be used to provide an explanation
to the user of why the failure occurred. The HandlerException class
provides you with numerous options for reporting errors.
- Parameters:
- contextData - contains information about this connection
- Returns:
- A Template which can be used to interpret the connection
- Throws: HandlerException
- if something went wrong with the handler
init
public abstract void init() throws HandlerException
- Use this method to run any startup initialization that you need
to perform. It will be called just before the first use of your
Handler.
- Throws: HandlerException
- if the handler failed to initialize
toString
public abstract String toString()
- You SHOULD override this method and provide a short name by
which your handler is known. This will help you out in logging
and debugging messages if for some reason WebMacro needs to
identify the handler in a log message.
- Overrides:
- toString in class Object
destroy
public abstract void destroy()
- You may use this method to save persistent state on exit.
It will be called whenever the servlet is shut down.
All Packages Class Hierarchy This Package Previous Next Index