@@ -65,7 +65,7 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
6565 /**
6666 * The matchers defined by this interceptor
6767 */
68- Collection<Matcher > matchers = new ConcurrentLinkedQueue<> ()
68+ final Collection<Matcher > matchers = new ConcurrentLinkedQueue<> ()
6969
7070 /**
7171 * @return Whether the current interceptor does match
@@ -77,6 +77,14 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
7777 * @return Whether the current interceptor does match
7878 */
7979 boolean doesMatch(HttpServletRequest request) {
80+ def allMatchers = matchers
81+ if (allMatchers. isEmpty()) {
82+ // default to map just the controller by convention
83+ def matcher = new UrlMappingMatcher (this )
84+ matcher. matches(controller :Pattern . compile(GrailsNameUtils . getLogicalPropertyName(getClass(). simpleName, InterceptorArtefactHandler . TYPE )))
85+ allMatchers << matcher
86+ }
87+
8088 String interceptorMatchKey = " ${ getClass().name}${ InterceptorArtefactHandler.MATCH_SUFFIX} "
8189 def existing = request. getAttribute(interceptorMatchKey)
8290 if (existing != null && ! WebUtils . isForward(request) && ! WebUtils . isInclude(request)) {
@@ -89,7 +97,7 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
8997 def matchedInfo = request. getAttribute(UrlMappingsHandlerMapping . MATCHED_REQUEST )
9098 UrlMappingInfo grailsMappingInfo = (UrlMappingInfo )matchedInfo
9199
92- for (Matcher matcher in matchers ) {
100+ for (Matcher matcher in allMatchers ) {
93101 if (matcher. doesMatch(uri, grailsMappingInfo)) {
94102 request. setAttribute(interceptorMatchKey, Boolean . TRUE )
95103 return true
@@ -264,17 +272,4 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
264272 }
265273 }
266274
267- /**
268- * Registers the default match strategy if non has been registered
269- */
270- @Autowired
271- void setGrailsApplication(GrailsApplication grailsApplication) {
272- if (matchers. isEmpty()) {
273- // default to map just the controller by convention
274- def matcher = new UrlMappingMatcher (this )
275- matcher. matches(controller :Pattern . compile(GrailsNameUtils . getLogicalPropertyName(getClass(). simpleName, InterceptorArtefactHandler . TYPE )))
276- matchers << matcher
277- }
278-
279- }
280275}
0 commit comments