Skip to content

Commit 99b2988

Browse files
committed
Merge branch '3.0.x' into 3.1.x
2 parents 3dfdd14 + b0dc0f8 commit 99b2988

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

grails-plugin-interceptors/src/main/groovy/grails/artefact/Interceptor.groovy

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

grails-plugin-interceptors/src/test/groovy/grails/artefact/InterceptorSpec.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class InterceptorSpec extends Specification {
3939
void "Test the default interceptor mappings"() {
4040
given:"A test interceptor"
4141
def i = new TestInterceptor()
42-
i.setGrailsApplication(null)
4342
def webRequest = GrailsWebMockUtil.bindMockWebRequest()
4443
HttpServletRequest request = webRequest.request
4544
when:"The current request is for a controller called test"

0 commit comments

Comments
 (0)