@Trait @CompileStatic trait Interceptor extends java.lang.Object implements DataBinder, RequestForwarder, ResponseRedirector, ResponseRenderer, ServletAttributes, WebAttributes, Ordered
An interceptor can be used to intercept requests to controllers and URIs They replace the notion of filters from earlier versions of Grails, prior to Grails 3.0
| Type | Name and description |
|---|---|
java.util.Map<java.lang.String, java.lang.Object> |
model |
ModelAndView |
modelAndView |
int |
order |
java.lang.String |
view |
| Type Params | Return Type | Name and description |
|---|---|---|
|
boolean |
after()Executed after the action executes but prior to view rendering |
|
void |
afterView()Executed after view rendering completes |
|
boolean |
before()Executed before a matched action |
|
boolean |
doesMatch()
|
|
boolean |
doesMatch(HttpServletRequest request)Whether this interceptor matches the given request. |
|
java.util.Collection<Matcher> |
getMatchers()The matchers defined by this interceptor |
|
java.util.Map<java.lang.String, java.lang.Object> |
getModel()
|
|
ModelAndView |
getModelAndView()Obtains the ModelAndView for the currently executing controller |
|
int |
getOrder()The order the interceptor should execute in |
|
java.lang.Throwable |
getThrowable()Obtains the exception thrown by an action execution |
|
java.lang.String |
getView()
|
|
void |
header(java.lang.String headerName, java.lang.Object headerValue)Sets a response header for the given name and value |
|
Matcher |
match(java.util.Map arguments)Used to define a match. |
|
Matcher |
matchAll()Matches all requests |
|
void |
render(java.util.Map argMap)Overridden render method that renders the view directly inside before() |
|
void |
setModel(java.util.Map<java.lang.String, java.lang.Object> model)Sets the model |
|
void |
setModelAndView(ModelAndView mav)Sets the ModelAndView of the current controller |
|
void |
setOrder(int order)The order the interceptor should execute in |
|
void |
setView(java.lang.String view)Sets the view name |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
Executed after the action executes but prior to view rendering
Executed after view rendering completes
t - The exception instance if an exception was thrown, null otherwiseExecuted before a matched action
Whether this interceptor matches the given request.
URI matchers see the same path that URL mappings route on, resolved with the same UrlPathHelper
call: path parameters (;name=value) are removed per segment before percent-decoding, as Jakarta
Servlet 6.0 section 3.5.2 requires of containers, so an encoded semicolon (%3B) stays a literal
character (RFC 3986 section 2.2); the path is decoded exactly once (RFC 3986 section 2.4); and the context
path is stripped. Two points follow Spring, and therefore dispatch, rather than the URI specification: the
context path is compared case-insensitively although RFC 3986 section 6.2.2.1 defines paths as case-sensitive,
and during a RequestDispatcher include the included path is matched, which is also the path the
include is dispatched on. A matcher that disagreed with dispatch on either point would let a request reach a
controller without its interceptors, so dispatch wins.
The path is canonicalized once per call and passed to every Matcher. A request whose URI contains an illegal percent escape, which a Servlet 6.0 container rejects with 400 before dispatch, is matched undecoded rather than failing.
request - The request to match
Obtains the ModelAndView for the currently executing controller
The order the interceptor should execute in
Obtains the exception thrown by an action execution
t - The exception or null if none was thrown
Sets a response header for the given name and value
headerName - The header nameheaderValue - The header valueUsed to define a match. Example: match(controller:'book', action:'*')
arguments - The match argumentsOverridden render method that renders the view directly inside before()
Sets the model
model - The model to setSets the ModelAndView of the current controller
mav - The ModelAndViewThe order the interceptor should execute in
Sets the view name
view - The name of the view