Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public interface HandlerInterceptor
Known subtypesMappedInterceptor
Runs around every controller method, for cross-cutting work that is not security: timing, auditing, tenant selection, request-scoped cleanup.
Declare one as a bean – a @Component class implementing this interface, or
a @Bean method returning one – and the build hands it to every generated
router. Several run in @Order order, and the ones without an order last in
bean-name order.
Where it runs
- The security filter chain: authentication, CSRF, the URL rules. A request it refuses never reaches an interceptor.
- Route selection. Only a request that matched a controller route is intercepted; a 404 is not.
preHandle, in order.- Binding, validation and the controller method, with its method security.
- Exception handlers, when 3 or 4 threw.
postHandle, in reverse order, only when the controller method returned normally.afterCompletion, in reverse order, for every interceptor whosepreHandlelet the request through – whatever happened after it.
Because the chain sits inside the security layer, an interceptor cannot
admit a request security refused, and the failures security owns –
AccessDeniedException, AuthenticationException and their subclasses,
CSRF included – pass every interceptor and exception handler untouched on
their way back to it.
Methods
Method details
preHandle
public default HttpServer.Response preHandle(HttpServer.Request request, HandlerMethod handler)
throws ExceptionafterCompletion runs only for the interceptors before this
one.Parameters
requestHttpServer.Request- the request
handlerHandlerMethod- the route it matched
Returns
Throws
Exception- routed to the exception handlers like the controller’s own
postHandle
public default void postHandle(HttpServer.Request request, HandlerMethod handler, HttpServer.Response response)
throws ExceptionParameters
requestHttpServer.Request- the request
handlerHandlerMethod- the route it matched
responseHttpServer.Response- the response about to be written
Throws
Exception- fails the request
afterCompletion
public default void afterCompletion(HttpServer.Request request, HandlerMethod handler, HttpServer.Response response, Throwable failure)Parameters
requestHttpServer.Request- the request
handlerHandlerMethod- the route it matched
responseHttpServer.Response- the response, or null when the request failed unhandled
failureThrowable- what failed and was not handled, or null