Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class ControllerHooks
- Object
- 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
- A failure security owns –
AccessDeniedExceptionorAuthenticationException, CSRF failures included – and anyErrorare 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. - The controller’s own
@ExceptionHandlermethods; among those that apply, the one declaring the closest superclass of what was thrown. - Each
@ControllerAdvice, in@Orderorder (unordered ones last, by bean name), each again choosing its closest match. The first that answers wins. - A
ValidationExceptionnothing handled answers 400 with its field errors as JSON. - 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.Invocation | What 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
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
interceptorsHandlerInterceptor[]- in the order they run
resolversExceptionResolver[]- 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
requestHttpServer.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 existsnotFound
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. Null when none answers,
which leaves the server’s own 404. Security failures and Errors are not
asked here, as nothing threw them.Parameters
requestHttpServer.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 ExceptionRuns one matched route through the interceptors and exception handlers.
Parameters
requestHttpServer.Request- the request
handlerHandlerMethod- the route it matched
callControllerHooks.Invocation- the router
routeint- the route’s index in the router
boundString[]- the path variables, or null
localExceptionResolver- the controller’s own exception handlers, or null
Returns
the response
Throws
Exception- a failure nothing handled