Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class ControllerHooks

  1. Object
  2. ControllerHooks

ImplementsHttpServer.Handler

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.

Nested types

interface ControllerHooks.InvocationWhat a generated router implements: running route route of itself.

Constructors

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.

Methods

public static ControllerHooks none()No interceptors and no global resolvers.
public boolean isEmpty()Whether there is nothing to run.
public HttpServer.Response handle(HttpServer.Request request)Never a router: always null.
public boolean hasResolvers()Whether any global resolver could answer an unmatched path.
public HttpServer.Response notFound(HttpServer.Request request) throws ExceptionThe answer for a request nothing served: the global resolvers are offered a NoHandlerFoundException, with a null handler.
public HttpServer.Response invoke(HttpServer.Request request, HandlerMethod handler, ControllerHooks.Invocation call, int route, String[] bound, ExceptionResolver local) throws ExceptionRuns one matched route through the interceptors and exception handlers.

Inherited methods

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 HandlerInterceptor[]
in the order they run
resolvers ExceptionResolver[]
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

handle

public HttpServer.Response handle(HttpServer.Request request)
Never a router: always null. The wiring hands these hooks to the server among its handlers, and the server takes them out of the chain and asks notFound only once every router and static file has passed.

Parameters

request HttpServer.Request
the request

Returns

null

hasResolvers

public boolean hasResolvers()
Whether any global resolver could answer an unmatched path.

Returns

true when a @ControllerAdvice or resolver bean exists

notFound

public HttpServer.Response notFound(HttpServer.Request request) throws Exception
The answer for a request nothing served: the global resolvers are offered a NoHandlerFoundException, with a null handler. Null when none answers, which leaves the server’s own 404. Security failures and Errors are not asked here, as nothing threw them.

Parameters

request HttpServer.Request
the request

Returns

the response, or null

Throws

Exception
what a resolver threw

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 HttpServer.Request
the request
handler HandlerMethod
the route it matched
call ControllerHooks.Invocation
the router
route int
the route’s index in the router
bound String[]
the path variables, or null
local ExceptionResolver
the controller’s own exception handlers, or null

Returns

the response

Throws

Exception
a failure nothing handled