public class TemplateActionExceptionHandler extends AbstractModule implements ActionExceptionHandler
An implementation of ActionExceptionHandler, a module that handles exceptions thrown by other actions. This handler uses a template to produce the result, much like GeneritTemplateAction. This behaves much the same way as GenericTemplateHandler, but does not extend from it, the reason being a circular dependency problem (See ActionExceptionHandler documentation for more about this).
This uses initialisation parameters templateKey, forwardRequestParameters and prefixes context. and defaultRequestParameter. in exactly the same way as GenericTemplateAction does, refer to its documentation.
Three additional variables are added to the template context. exception contains the exception that was caught, errorMessage contains the error message from the exception, this may or may not be user friendly. Finally, trace contains a stack trace of the exception.
Modifier and Type | Field and Description |
---|---|
protected java.util.HashMap<java.lang.String,java.lang.String> |
defaultRequestParameters |
static java.lang.String |
EXCEPTION_ACTION |
protected java.util.ArrayList<java.lang.String> |
forwardRequestParameters |
protected java.lang.String |
requestContextKey |
protected java.util.HashMap<java.lang.String,java.lang.Object> |
staticContext |
protected java.lang.String |
templateKey |
protected TemplateManager |
templateManager |
autoStart, isInitialized, isRunning, logging, loggingModule, moduleManager
Constructor and Description |
---|
TemplateActionExceptionHandler() |
Modifier and Type | Method and Description |
---|---|
java.util.Collection<Module> |
getDependencies(ModuleManager manager)
Returns all the modules this module depends on.
|
protected java.util.LinkedHashMap<java.lang.String,java.lang.String> |
getForwardedParameters(javax.servlet.http.HttpServletRequest req) |
protected java.util.HashMap<java.lang.String,java.lang.Object> |
getStaticTemplateContext() |
protected Template |
getTemplate(javax.servlet.http.HttpServletRequest req,
ModulesServlet.HttpMethod method,
ActionException exception) |
protected Template |
getTemplate(javax.servlet.http.HttpServletRequest req,
ModulesServlet.HttpMethod method,
java.lang.String action) |
protected java.util.HashMap<java.lang.String,java.lang.Object> |
getTemplateContext(Template template,
javax.servlet.http.HttpServletRequest req,
ModulesServlet.HttpMethod method,
User user,
ActionException ae) |
boolean |
handleActionException(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
ModulesServlet.HttpMethod method,
User user,
ActionException ae)
Handles an exception that occurred when handling an HTTP request.
|
void |
init(ModuleManager manager,
java.util.HashMap<java.lang.String,java.lang.Object> settings)
Initialises the module.
|
void |
putStaticContext(java.lang.String key,
java.lang.Object o) |
void |
start(ModuleManager manager)
Starts the module.
|
void |
stop(ModuleManager manager)
Stops the module.
|
isInitialized, isRunning, requireLogging, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isInitialized, isRunning
public static final java.lang.String EXCEPTION_ACTION
protected java.lang.String requestContextKey
protected TemplateManager templateManager
protected java.lang.String templateKey
protected java.util.ArrayList<java.lang.String> forwardRequestParameters
protected java.util.HashMap<java.lang.String,java.lang.String> defaultRequestParameters
protected final java.util.HashMap<java.lang.String,java.lang.Object> staticContext
public void putStaticContext(java.lang.String key, java.lang.Object o)
protected Template getTemplate(javax.servlet.http.HttpServletRequest req, ModulesServlet.HttpMethod method, java.lang.String action)
public java.util.Collection<Module> getDependencies(ModuleManager manager) throws ModuleException
Module
getDependencies
in interface Module
getDependencies
in class AbstractModule
manager
- The module manager handling this module.ModuleException
public void init(ModuleManager manager, java.util.HashMap<java.lang.String,java.lang.Object> settings) throws ModuleException
Module
Initialises the module. After constructor, this is the first method called in the life cycle of a module. It should not perform anything time consuming or anything with notable outside side effects. It should only read the parameters and initialise the module so that it can later be started. Note that a module being initialised doesn't mean that it necessarily will ever be started.
A ModuleException may be thrown if something vital is missing from the parameters or they are not sensible. In some cases you may not want to throw an exception even if vital initialisation information is missing. If, for example, it is possible that the module is initialised in some other way between the init and the start method calls. A ModuleException may also be thrown at the start method if the module is still not initialised.
init
in interface Module
init
in class AbstractModule
manager
- The module manager handling this module. You may keep a
reference to it if needed.ModuleException
public void start(ModuleManager manager) throws ModuleException
Module
start
in interface Module
start
in class AbstractModule
manager
- The module manager handling this module.ModuleException
public void stop(ModuleManager manager)
Module
stop
in interface Module
stop
in class AbstractModule
manager
- The module manager handling this module.protected java.util.HashMap<java.lang.String,java.lang.Object> getStaticTemplateContext()
protected java.util.LinkedHashMap<java.lang.String,java.lang.String> getForwardedParameters(javax.servlet.http.HttpServletRequest req)
protected Template getTemplate(javax.servlet.http.HttpServletRequest req, ModulesServlet.HttpMethod method, ActionException exception)
protected java.util.HashMap<java.lang.String,java.lang.Object> getTemplateContext(Template template, javax.servlet.http.HttpServletRequest req, ModulesServlet.HttpMethod method, User user, ActionException ae)
public boolean handleActionException(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, ModulesServlet.HttpMethod method, User user, ActionException ae) throws javax.servlet.ServletException, java.io.IOException, ActionException
ActionExceptionHandler
handleActionException
in interface ActionExceptionHandler
req
- The HTTP request.resp
- The HTTP request where the response can be written.method
- The HTTP method used with the request.user
- The authenticated user, or null if not applicable.ae
- The ActionException that caused this to be called.javax.servlet.ServletException
java.io.IOException
ActionException
Copyright 2004-2015 Wandora Team