org.webmacro.servlet
Interface 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:

  1. . Define a name for your new Handler. It must be alphanumeric.
  2. . 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)
  3. . Set the script prefix to be the prefix added by servletrunner in the config file. eg: "ScriptName = /servlet/"
  4. . 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

Method Summary
 Template accept(WebContext contextData)
          This is the primary method you override to create a new handler.
 void destroy()
          You may use this method to save persistent state on exit.
 void init()
          Use this method to run any startup initialization that you need to perform.
 java.lang.String toString()
          You SHOULD override this method and provide a short name by which your handler is known.
 

Method Detail

accept

public 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 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 java.lang.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 java.lang.Object

destroy

public void destroy()
You may use this method to save persistent state on exit. It will be called whenever the servlet is shut down.