Class ControllerHooks

java.lang.Object
com.codename1.backend.web.ControllerHooks

public final class ControllerHooks extends Object

The interceptors and global exception resolvers every generated router runs a matched request through.

The generated wiring builds one from the application's HandlerInterceptor beans and @ControllerAdvice beans and hands it to each router. A router whose controller declares no exception handler and whose route validates nothing skips it entirely while it isEmpty(), so an application with none of these pays one field read per request.

Exception handling precedence
  1. A failure security owns -- AccessDeniedException or AuthenticationException, CSRF failures included -- and any Error are never offered to a handler. They go straight back to the server and the security chain, so a broad @ExceptionHandler(Exception.class) cannot turn a refusal into a success.
  2. The controller's own @ExceptionHandler methods; among those that apply, the one declaring the closest superclass of what was thrown.
  3. Each @ControllerAdvice, in @Order order (unordered ones last, by bean name), each again choosing its closest match. The first that answers wins.
  4. A ValidationException nothing handled answers 400 with its field errors as JSON.
  5. Anything else is rethrown, and the server answers it as before: the status of a ResponseStatusException, otherwise a 500 that reveals nothing about the failure.
  • Constructor Details

    • ControllerHooks

      public ControllerHooks(HandlerInterceptor[] interceptors, ExceptionResolver[] resolvers)
      Null entries are dropped: a conditional bean that was not created is null in the wiring, and leaving the hole in would fail every request.
      Parameters:
      interceptors - in the order they run
      resolvers - the global resolvers, in the order they are asked
  • Method Details

    • none

      public static ControllerHooks none()
      No interceptors and no global resolvers.
      Returns:
      the shared empty instance
    • isEmpty

      public boolean isEmpty()
      Whether there is nothing to run.
      Returns:
      true with no interceptors and no global resolvers
    • invoke

      public HttpServer.Response invoke(HttpServer.Request request, HandlerMethod handler, ControllerHooks.Invocation call, int route, String[] bound, ExceptionResolver local) throws Exception
      Runs one matched route through the interceptors and exception handlers.
      Parameters:
      request - the request
      handler - the route it matched
      call - the router
      route - the route's index in the router
      bound - the path variables, or null
      local - the controller's own exception handlers, or null
      Returns:
      the response
      Throws:
      Exception - a failure nothing handled