Package ninja

Class NinjaDefault

  • All Implemented Interfaces:
    Ninja

    public class NinjaDefault
    extends Object
    implements Ninja
    • Constructor Detail

      • NinjaDefault

        public NinjaDefault()
    • 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 interface Ninja
      • 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 interface Ninja
      • 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 interface Ninja
      • 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 interface Ninja
      • 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 interface Ninja
        Parameters:
        context - The context for this request
        exception - The exception to handle. Can be used to customize error message.
        Returns:
        a result you can use to render the error.
      • getRenderingExceptionResult

        public Result getRenderingExceptionResult​(Context context,
                                                  RenderingException exception,
                                                  Result underlyingResult)
        Description copied from interface: Ninja
        Should handle cases where a RenderingException 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 interface Ninja
      • 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 interface Ninja
      • 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 interface Ninja
      • 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 interface Ninja
      • 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 interface Ninja
      • 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 interface Ninja
      • 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 interface Ninja
      • 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 interface Ninja