Class ControllerHooks
java.lang.Object
com.codename1.backend.web.ControllerHooks
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 Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceWhat a generated router implements: running routerouteof itself. -
Constructor Summary
ConstructorsConstructorDescriptionControllerHooks(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. -
Method Summary
Modifier and TypeMethodDescriptioninvoke(HttpServer.Request request, HandlerMethod handler, ControllerHooks.Invocation call, int route, String[] bound, ExceptionResolver local) Runs one matched route through the interceptors and exception handlers.booleanisEmpty()Whether there is nothing to run.static ControllerHooksnone()No interceptors and no global resolvers.
-
Constructor Details
-
ControllerHooks
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 runresolvers- the global resolvers, in the order they are asked
-
-
Method Details
-
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 requesthandler- the route it matchedcall- the routerroute- the route's index in the routerbound- the path variables, or nulllocal- the controller's own exception handlers, or null- Returns:
- the response
- Throws:
Exception- a failure nothing handled
-