Package ninja
Class NinjaDefault
- java.lang.Object
-
- ninja.NinjaDefault
-
-
Field Summary
Fields Modifier and Type Field Description protected LifecycleServicelifecycleServiceprotected Messagesmessagesprotected NinjaPropertiesninjaPropertiesprotected ResultHandlerresultHandlerprotected Routerrouter
-
Constructor Summary
Constructors Constructor Description NinjaDefault()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected MessagebuildErrorMessage(Context context, String errorTextKey, String errorTextDefault, Optional<Throwable> exception, Optional<Result> underlyingResult)ResultgetBadRequestResult(Context context, BadRequestException exception)Should handle cases where the client sent strange date that led to an error.ResultgetForbiddenResult(Context context)Should handle cases where access is forbidden Should lead to a html error 403 - forbidden (and be used with the same mindset).ResultgetForbiddenResult(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).ResultgetInternalServerErrorResult(Context context, Exception exception)Deprecated.ResultgetInternalServerErrorResult(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.ResultgetNotFoundResult(Context context)Should handle cases where no route can be found for a given request.ResultgetNotFoundResult(Context context, RequestNotFoundException exception)Should handle cases where no route can be found for a given request.ResultgetRenderingExceptionResult(Context context, RenderingException exception, Result underlyingResult)Should handle cases where aRenderingExceptionis thrown when handling the rendering of a Result.ResultgetUnauthorizedResult(Context context)Should handle cases where access is unauthorized Should lead to a html error 401 - unauthorized (and be used with the same mindset).booleanisDiagnosticsEnabled()Whether diagnostics are enabled.ResultonException(Context context, Exception exception)This result should be used when an error occurs.ResultonException(Context context, Exception exception, Result underlyingResult)voidonFrameworkShutdown()Invoked when the server hosting Ninja is being stopped.voidonFrameworkStart()Invoked when the framework starts.voidonRouteRequest(Context.Impl context)When a route is requested this method is called.voidrenderErrorResultAndCatchAndLogExceptions(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:NinjaWhen a route is requested this method is called.- Specified by:
onRouteRequestin interfaceNinja
-
renderErrorResultAndCatchAndLogExceptions
public void renderErrorResultAndCatchAndLogExceptions(Result result, Context context)
Description copied from interface:NinjaShould 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:
renderErrorResultAndCatchAndLogExceptionsin interfaceNinja
-
onFrameworkStart
public void onFrameworkStart()
Description copied from interface:NinjaInvoked when the framework starts. Usually inits stuff like the scheduler and so on.- Specified by:
onFrameworkStartin interfaceNinja
-
onFrameworkShutdown
public void onFrameworkShutdown()
Description copied from interface:NinjaInvoked when the server hosting Ninja is being stopped. Usually shuts down the guice injector and stopps all services.- Specified by:
onFrameworkShutdownin interfaceNinja
-
onException
public Result onException(Context context, Exception exception)
Description copied from interface:NinjaThis result should be used when an error occurs.- Specified by:
onExceptionin 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:NinjaShould handle cases where aRenderingExceptionis 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:
getRenderingExceptionResultin 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:NinjaShould 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:
getInternalServerErrorResultin interfaceNinja
-
getNotFoundResult
public Result getNotFoundResult(Context context)
Description copied from interface:NinjaShould 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:
getNotFoundResultin interfaceNinja
-
getNotFoundResult
public Result getNotFoundResult(Context context, RequestNotFoundException exception)
Description copied from interface:NinjaShould 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:
getNotFoundResultin interfaceNinja
-
getBadRequestResult
public Result getBadRequestResult(Context context, BadRequestException exception)
Description copied from interface:NinjaShould 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:
getBadRequestResultin interfaceNinja
-
getUnauthorizedResult
public Result getUnauthorizedResult(Context context)
Description copied from interface:NinjaShould 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:
getUnauthorizedResultin interfaceNinja
-
getForbiddenResult
public Result getForbiddenResult(Context context)
Description copied from interface:NinjaShould 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:
getForbiddenResultin interfaceNinja
-
getForbiddenResult
public Result getForbiddenResult(Context context, ForbiddenRequestException exception)
Description copied from interface:NinjaShould 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:
getForbiddenResultin interfaceNinja
-
-