public class Global extends Object
Provide lifecycle, instanciation, invocation and error handling hooks.
You are encouraged to subclass it in your Application code by setting the app.global
configuration property to the FQCN of your Global implementation.
Remeber you can call the super methods to leverage the default behaviour.
Constructor and Description |
---|
Global() |
Modifier and Type | Method and Description |
---|---|
void |
afterHttpBind(Application application)
Invoked after binding Http Server.
|
void |
afterHttpUnbind(Application application)
Invoked after unbinding Http Server.
|
void |
beforeHttpBind(Application application)
Invoked before binding Http Server.
|
void |
beforeHttpUnbind(Application application)
Invoked before unbinding Http Server.
|
List<Plugin<?>> |
extraPlugins()
Chance to provide extra Plugins instances programmatically.
|
<T> T |
getControllerInstance(Application application, Class<T> controllerType)
Get Controller instance.
|
<T> T |
getFilterInstance(Application application, Class<T> filterType)
Get Filter instance.
|
<T> T |
getPluginInstance(Application application, Class<T> pluginType)
Get Plugin instance.
|
Throwable |
getRootCause(Throwable throwable)
Give a chance to clean-up stacktraces of Throwables poping out of the Application.
|
Object |
invokeControllerMethod(Context context, Object controller)
Invoke Controller Method.
|
void |
onActivate(Application application)
Application activation.
|
void |
onApplicationError(Application application, Throwable cause)
Invoked when an uncaught exception pops out of the Application's threads.
|
void |
onHttpRequestComplete(Application application, RequestHeader requestHeader)
Invoked when a request completed successfully and all bytes are sent to the client.
|
void |
onPassivate(Application application)
Application passivation.
|
Outcome |
onRequestError(Application application, RequestHeader request, Outcomes outcomes, Throwable cause)
Invoked when an exception pops out of the Application while processing a request.
|
public List<Plugin<?>> extraPlugins()
Invoked before Application activation.
Default to no extra Plugins.
public void onActivate(Application application)
Invoked after all Plugins activation.
Default to NOOP.
application
- Application
public void onPassivate(Application application)
Invoked before all Plugins passivation.
Default to NOOP.
application
- Application
public void beforeHttpBind(Application application)
Invoked after onActivate(io.werval.api.Application)
.
Default to NOOP.
Reloads occuring in development mode do not trigger this call.
application
- Application
public void afterHttpBind(Application application)
Default to NOOP.
Reloads occuring in development mode do not trigger this call.
application
- Application
public void beforeHttpUnbind(Application application)
Default to NOOP.
Reloads occuring in development mode do not trigger this call.
application
- Application
public void afterHttpUnbind(Application application)
Invoked before onPassivate(io.werval.api.Application)
.
Default to NOOP.
Reloads occuring in development mode do not trigger this call.
application
- Application
public <T> T getPluginInstance(Application application, Class<T> pluginType)
Default to Class.newInstance()
.
T
- Plugin Parameterized Type
application
- Application
pluginType
- Plugin Type
public <T> T getFilterInstance(Application application, Class<T> filterType)
Default to Class.newInstance()
.
T
- Filter Parameterized Type
application
- Application
filterType
- Filter Type
public <T> T getControllerInstance(Application application, Class<T> controllerType)
Default to Class.newInstance()
.
T
- Controller Parameterized Type
application
- Application
controllerType
- Controller Type
public Object invokeControllerMethod(Context context, Object controller)
Default to Method.invoke(java.lang.Object, java.lang.Object[])
.
Acceptable return types are:
context
- Request Context
controller
- Controller Instance
public void onHttpRequestComplete(Application application, RequestHeader requestHeader)
Default to NOOP.
If this method throws an exception, it will be logged it but it won't be rethrown since the request has already completed.
application
- Application
requestHeader
- Request Header
public Throwable getRootCause(Throwable throwable)
Default to WervalException
>InvocationTargetException
cleanup in development mode.
Do nothing in test and production modes.
Default behaviour is to clean-up the stacktrace by removing stack elements introduced by the reflective calls done in invokeControllerMethod(io.werval.api.context.Context, java.lang.Object)
implementation.
If this method is overriden and throws an exception, the later will be added as suppressed to the original cause.
throwable
- A Throwable
public Outcome onRequestError(Application application, RequestHeader request, Outcomes outcomes, Throwable cause)
Happens right before Error
recording.
Default to logging the error and producing a minimal HTML page, JSON document or text/plain response advertising a 500 status code and the corresponding reason phrase. Response content-type depends on content negociation.
Stacktrace is disclosed in development mode only. In HTML mode, links to project sources are added when available.
If this method is overriden and throws an exception, the later is added as suppressed to the original cause and default behaviour is replayed. This mecanism is the Application
fault barrier.
application
- Application
request
- Request header
outcomes
- Outcomes utilities
cause
- Cause
public void onApplicationError(Application application, Throwable cause)
application
- Application
cause
- Cause