@@ -64,7 +64,7 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
6464 /**
6565 * The matchers defined by this interceptor
6666 */
67- Collection<Matcher > matchers = new ConcurrentLinkedQueue<> ()
67+ final Collection<Matcher > matchers = new ConcurrentLinkedQueue<> ()
6868
6969 /**
7070 * @return Whether the current interceptor does match
@@ -76,6 +76,14 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
7676 * @return Whether the current interceptor does match
7777 */
7878 boolean doesMatch(HttpServletRequest request) {
79+ def allMatchers = matchers
80+ if (allMatchers. isEmpty()) {
81+ // default to map just the controller by convention
82+ def matcher = new UrlMappingMatcher (this )
83+ matcher. matches(controller :Pattern . compile(GrailsNameUtils . getLogicalPropertyName(getClass(). simpleName, InterceptorArtefactHandler . TYPE )))
84+ allMatchers << matcher
85+ }
86+
7987 String interceptorMatchKey = " ${ getClass().name}${ InterceptorArtefactHandler.MATCH_SUFFIX} "
8088 def existing = request. getAttribute(interceptorMatchKey)
8189 if (existing != null && ! WebUtils . isForward(request) && ! WebUtils . isInclude(request)) {
@@ -88,7 +96,7 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
8896 def matchedInfo = request. getAttribute(UrlMappingsHandlerMapping . MATCHED_REQUEST )
8997 UrlMappingInfo grailsMappingInfo = (UrlMappingInfo )matchedInfo
9098
91- for (Matcher matcher in matchers ) {
99+ for (Matcher matcher in allMatchers ) {
92100 if (matcher. doesMatch(uri, grailsMappingInfo)) {
93101 request. setAttribute(interceptorMatchKey, Boolean . TRUE )
94102 return true
@@ -263,17 +271,4 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
263271 }
264272 }
265273
266- /**
267- * Registers the default match strategy if non has been registered
268- */
269- @Autowired
270- void setGrailsApplication(GrailsApplication grailsApplication) {
271- if (matchers. isEmpty()) {
272- // default to map just the controller by convention
273- def matcher = new UrlMappingMatcher (this )
274- matcher. matches(controller :Pattern . compile(GrailsNameUtils . getLogicalPropertyName(getClass(). simpleName, InterceptorArtefactHandler . TYPE )))
275- matchers << matcher
276- }
277-
278- }
279274}
0 commit comments