Package ninja
Class NinjaDefault
- java.lang.Object
-
- ninja.NinjaDefault
-
-
Field Summary
Fields Modifier and Type Field Description protected LifecycleService
lifecycleService
protected Messages
messages
protected NinjaProperties
ninjaProperties
protected ResultHandler
resultHandler
protected Router
router
-
Constructor Summary
Constructors Constructor Description NinjaDefault()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected Message
buildErrorMessage(Context context, String errorTextKey, String errorTextDefault, Optional<Throwable> exception, Optional<Result> underlyingResult)
Result
getBadRequestResult(Context context, BadRequestException exception)
Should handle cases where the client sent strange date that led to an error.Result
getForbiddenResult(Context context)
Should handle cases where access is forbidden Should lead to a html error 403 - forbidden (and be used with the same mindset).Result
getForbiddenResult(Context context, ForbiddenRequestException exception)
Should handle cases where access is forbidden Should lead to a html error 403 - forbidden (and be used with the same mindset).Result
getInternalServerErrorResult(Context context, Exception exception)
Deprecated.Result
getInternalServerErrorResult(Context context, Exception exception, Result underlyingResult)
Should handle cases where an exception is thrown when handling a route that let to an internal server error.Result
getNotFoundResult(Context context)
Should handle cases where no route can be found for a given request.Result
getNotFoundResult(Context context, RequestNotFoundException exception)
Should handle cases where no route can be found for a given request.Result
getRenderingExceptionResult(Context context, RenderingException exception, Result underlyingResult)
Should handle cases where aRenderingException
is thrown when handling the rendering of a Result.Result
getUnauthorizedResult(Context context)
Should handle cases where access is unauthorized Should lead to a html error 401 - unauthorized (and be used with the same mindset).boolean
isDiagnosticsEnabled()
Whether diagnostics are enabled.Result
onException(Context context, Exception exception)
This result should be used when an error occurs.Result
onException(Context context, Exception exception, Result underlyingResult)
void
onFrameworkShutdown()
Invoked when the server hosting Ninja is being stopped.void
onFrameworkStart()
Invoked when the framework starts.void
onRouteRequest(Context.Impl context)
When a route is requested this method is called.void
renderErrorResultAndCatchAndLogExceptions(Result result, Context context)
Should be used to render an error.
-
-
-
Field Detail
-
lifecycleService
@Inject protected LifecycleService lifecycleService
-
router
@Inject protected Router router
-
resultHandler
@Inject protected ResultHandler resultHandler
-
messages
@Inject protected Messages messages
-
ninjaProperties
@Inject protected NinjaProperties ninjaProperties
-
-
Method Detail
-
isDiagnosticsEnabled
public boolean isDiagnosticsEnabled()
Whether diagnostics are enabled. If enabled then the default system/views will be skipped and a detailed diagnostic error result will be returned by the various methods in this class. You get precise feedback where an error occurred including original source code.- Returns:
- True if diagnostics are enabled otherwise false.
-
onRouteRequest
public void onRouteRequest(Context.Impl context)
Description copied from interface:Ninja
When a route is requested this method is called.- Specified by:
onRouteRequest
in interfaceNinja
-
renderErrorResultAndCatchAndLogExceptions
public void renderErrorResultAndCatchAndLogExceptions(Result result, Context context)
Description copied from interface:Ninja
Should be used to render an error. Any errors should be catched and not reported in any way to the request. For instance if your application catches a sever internal computation error use this method and its implementations to render out an error html page.- Specified by:
renderErrorResultAndCatchAndLogExceptions
in interfaceNinja
-
onFrameworkStart
public void onFrameworkStart()
Description copied from interface:Ninja
Invoked when the framework starts. Usually inits stuff like the scheduler and so on.- Specified by:
onFrameworkStart
in interfaceNinja
-
onFrameworkShutdown
public void onFrameworkShutdown()
Description copied from interface:Ninja
Invoked when the server hosting Ninja is being stopped. Usually shuts down the guice injector and stopps all services.- Specified by:
onFrameworkShutdown
in interfaceNinja
-
onException
public Result onException(Context context, Exception exception)
Description copied from interface:Ninja
This result should be used when an error occurs.- Specified by:
onException
in interfaceNinja
- Parameters:
context
- The context for this requestexception
- The exception to handle. Can be used to customize error message.- Returns:
- a result you can use to render the error.
-
onException
public Result onException(Context context, Exception exception, Result underlyingResult)
-
getRenderingExceptionResult
public Result getRenderingExceptionResult(Context context, RenderingException exception, Result underlyingResult)
Description copied from interface:Ninja
Should handle cases where aRenderingException
is thrown when handling the rendering of a Result. Should lead to an html error 500 -- internal server error. If no special handling is required, simply:return getInternalServerErrorResult(context, exception, underlyingResult);
- Specified by:
getRenderingExceptionResult
in interfaceNinja
-
getInternalServerErrorResult
@Deprecated public Result getInternalServerErrorResult(Context context, Exception exception)
Deprecated.Deprecated. CheckNinja.getInternalServerErrorResult(Context, Exception, Result)
.
-
getInternalServerErrorResult
public Result getInternalServerErrorResult(Context context, Exception exception, Result underlyingResult)
Description copied from interface:Ninja
Should handle cases where an exception is thrown when handling a route that let to an internal server error. Should lead to a html error 500 - internal sever error (and be used with the same mindset). Usually used by onRouteRequest(...).- Specified by:
getInternalServerErrorResult
in interfaceNinja
-
getNotFoundResult
public Result getNotFoundResult(Context context)
Description copied from interface:Ninja
Should handle cases where no route can be found for a given request. Should lead to a html error 404 - not found (and be used with the same mindset). Usually used by onRouteRequest(...).- Specified by:
getNotFoundResult
in interfaceNinja
-
getNotFoundResult
public Result getNotFoundResult(Context context, RequestNotFoundException exception)
Description copied from interface:Ninja
Should handle cases where no route can be found for a given request. Should lead to a html error 404 - not found (and be used with the same mindset). Usually used by onRouteRequest(...).- Specified by:
getNotFoundResult
in interfaceNinja
-
getBadRequestResult
public Result getBadRequestResult(Context context, BadRequestException exception)
Description copied from interface:Ninja
Should handle cases where the client sent strange date that led to an error. Should lead to a html error 400 - bad request (and be used with the same mindset). Usually used by onRouteRequest(...).- Specified by:
getBadRequestResult
in interfaceNinja
-
getUnauthorizedResult
public Result getUnauthorizedResult(Context context)
Description copied from interface:Ninja
Should handle cases where access is unauthorized Should lead to a html error 401 - unauthorized (and be used with the same mindset). By default, WWW-Authenticate is set to None. Usually used by BasicAuthFilter for instance(...).- Specified by:
getUnauthorizedResult
in interfaceNinja
-
getForbiddenResult
public Result getForbiddenResult(Context context)
Description copied from interface:Ninja
Should handle cases where access is forbidden Should lead to a html error 403 - forbidden (and be used with the same mindset). Usually used by SecureFilter for instance(...).- Specified by:
getForbiddenResult
in interfaceNinja
-
getForbiddenResult
public Result getForbiddenResult(Context context, ForbiddenRequestException exception)
Description copied from interface:Ninja
Should handle cases where access is forbidden Should lead to a html error 403 - forbidden (and be used with the same mindset). Usually used by onRouteRequest(...).- Specified by:
getForbiddenResult
in interfaceNinja
-
-