Class MappedInterceptor
java.lang.Object
com.codename1.backend.web.MappedInterceptor
- All Implemented Interfaces:
HandlerInterceptor
An interceptor limited to some paths, as Spring's
registry.addInterceptor(x).addPathPatterns(...).excludePathPatterns(...).
Declare it as the bean in place of the interceptor it wraps:
@Bean
HandlerInterceptor audit() {
return new MappedInterceptor(new AuditInterceptor())
.addPathPatterns("/api/**")
.excludePathPatterns("/api/health");
}
A pattern is a path in which * matches within one segment and a final
/** matches the rest of the path, the prefix itself included. With no
include pattern every path is included. Paths are matched as the routers
match them, without the query and with unreserved escapes decoded.
-
Constructor Summary
ConstructorsConstructorDescriptionMappedInterceptor(HandlerInterceptor delegate) Limitsdelegateto the patterns added next. -
Method Summary
Modifier and TypeMethodDescriptionaddPathPatterns(String... patterns) Runs the interceptor on these paths.voidafterCompletion(HttpServer.Request request, HandlerMethod handler, HttpServer.Response response, Throwable failure) Called once the request is finished with, on success, on a refusal by a later interceptor, on a binding or validation failure and on a failure nothing handled.excludePathPatterns(String... patterns) Never runs the interceptor on these paths, even when included.booleanWhether the interceptor runs forpath.voidpostHandle(HttpServer.Request request, HandlerMethod handler, HttpServer.Response response) Called after the controller method returned normally; not after a refusal, and not after an exception, handled or not.preHandle(HttpServer.Request request, HandlerMethod handler) Called before binding.
-
Constructor Details
-
MappedInterceptor
Limitsdelegateto the patterns added next.- Parameters:
delegate- the interceptor to run on matching paths
-
-
Method Details
-
addPathPatterns
Runs the interceptor on these paths.- Parameters:
patterns- path patterns- Returns:
- this interceptor
-
excludePathPatterns
Never runs the interceptor on these paths, even when included.- Parameters:
patterns- path patterns- Returns:
- this interceptor
-
matches
Whether the interceptor runs forpath.- Parameters:
path- a request path, without its query- Returns:
- true when it is included and not excluded
-
preHandle
public HttpServer.Response preHandle(HttpServer.Request request, HandlerMethod handler) throws Exception Description copied from interface:HandlerInterceptorCalled before binding. Return null to let the request through, or a response to answer with instead -- the controller method is then not called, andHandlerInterceptor.afterCompletion(HttpServer.Request, HandlerMethod, HttpServer.Response, Throwable)runs only for the interceptors before this one.- Specified by:
preHandlein interfaceHandlerInterceptor- Parameters:
request- the requesthandler- the route it matched- Returns:
- null to proceed, or the response to answer with
- Throws:
Exception- routed to the exception handlers like the controller's own
-
postHandle
public void postHandle(HttpServer.Request request, HandlerMethod handler, HttpServer.Response response) throws Exception Description copied from interface:HandlerInterceptorCalled after the controller method returned normally; not after a refusal, and not after an exception, handled or not.- Specified by:
postHandlein interfaceHandlerInterceptor- Parameters:
request- the requesthandler- the route it matchedresponse- the response about to be written- Throws:
Exception- fails the request
-
afterCompletion
public void afterCompletion(HttpServer.Request request, HandlerMethod handler, HttpServer.Response response, Throwable failure) Description copied from interface:HandlerInterceptorCalled once the request is finished with, on success, on a refusal by a later interceptor, on a binding or validation failure and on a failure nothing handled. This is the place for cleanup. A throw from here is logged and does not change the response.- Specified by:
afterCompletionin interfaceHandlerInterceptor- Parameters:
request- the requesthandler- the route it matchedresponse- the response, or null when the request failed unhandledfailure- what failed and was not handled, or null
-