Skip to content

Commit 01b6ee0

Browse files
committed
Fix failing functional tests
1 parent 4ebcea9 commit 01b6ee0

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package grails.artefact
1818
import grails.artefact.controller.support.RequestForwarder
1919
import grails.artefact.controller.support.ResponseRedirector
2020
import grails.artefact.controller.support.ResponseRenderer
21+
import grails.core.GrailsApplication
2122
import grails.interceptors.Matcher
2223
import grails.util.GrailsNameUtils
2324
import grails.web.api.ServletAttributes
@@ -33,6 +34,7 @@ import org.grails.web.mapping.mvc.UrlMappingsHandlerMapping
3334
import org.grails.web.servlet.mvc.exceptions.ControllerExecutionException
3435
import org.grails.web.util.GrailsApplicationAttributes
3536
import org.grails.web.util.WebUtils
37+
import org.springframework.beans.factory.annotation.Autowired
3638
import org.springframework.core.Ordered
3739
import org.springframework.web.servlet.ModelAndView
3840
import org.springframework.web.servlet.ViewResolver
@@ -264,8 +266,8 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
264266
/**
265267
* Registers the default match strategy if non has been registered
266268
*/
267-
@PostConstruct
268-
void defaultMatcher() {
269+
@Autowired
270+
void setGrailsApplication(GrailsApplication grailsApplication) {
269271
if(matchers.isEmpty()) {
270272
// default to map just the controller by convention
271273
def matcher = new UrlMappingMatcher(this)

grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/mvc/UrlMappingsHandlerMapping.groovy

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.grails.web.mapping.mvc
1717

18+
import groovy.transform.CompileDynamic
1819
import groovy.transform.CompileStatic
1920
import grails.web.mapping.UrlMapping
2021
import grails.web.mapping.UrlMappingInfo
@@ -61,6 +62,15 @@ class UrlMappingsHandlerMapping extends AbstractHandlerMapping {
6162
setOrder(-5)
6263
}
6364

65+
@Autowired
66+
void setHandlerInterceptors(HandlerInterceptor[] handlerInterceptors) {
67+
for(hi in handlerInterceptors) {
68+
if(!(hi instanceof MappedInterceptor)) {
69+
setInterceptors(hi)
70+
}
71+
}
72+
}
73+
6474
@Autowired(required = false)
6575
void setWebRequestInterceptors(WebRequestInterceptor[] webRequestInterceptors) {
6676
webRequestHandlerInterceptors = webRequestInterceptors.collect( { WebRequestInterceptor wri ->
@@ -75,16 +85,42 @@ class UrlMappingsHandlerMapping extends AbstractHandlerMapping {
7585

7686
@Override
7787
protected HandlerExecutionChain getHandlerExecutionChain(Object handler, HttpServletRequest request) {
78-
def chain = super.getHandlerExecutionChain(handler, request)
88+
HandlerExecutionChain chain = (handler instanceof HandlerExecutionChain ?
89+
(HandlerExecutionChain) handler : new HandlerExecutionChain(handler))
7990

8091
// WebRequestInterceptor need to come first, as these include things like Hibernate OSIV
8192
if(webRequestHandlerInterceptors) {
8293
chain.addInterceptors webRequestHandlerInterceptors
8394
}
95+
96+
String lookupPath = this.urlPathHelper.getLookupPathForRequest(request)
97+
for (HandlerInterceptor interceptor in this.adaptedInterceptors) {
98+
if (interceptor instanceof MappedInterceptor) {
99+
MappedInterceptor mappedInterceptor = mappedInterceptor(interceptor)
100+
if (mappedInterceptor.matches(lookupPath, this.pathMatcher)) {
101+
chain.addInterceptor(mappedInterceptor.getInterceptor())
102+
}
103+
}
104+
else {
105+
chain.addInterceptor(interceptor)
106+
}
107+
}
108+
109+
for(MappedInterceptor mi in getMappedInterceptors()) {
110+
if (mi.matches(lookupPath, this.pathMatcher)) {
111+
chain.addInterceptor(mi.getInterceptor())
112+
}
113+
}
114+
84115
chain.addInterceptor(new ErrorHandlingHandler())
85116
return chain
86117
}
87118

119+
@CompileDynamic
120+
protected MappedInterceptor mappedInterceptor(HandlerInterceptor interceptor) {
121+
(MappedInterceptor) interceptor
122+
}
123+
88124
@Override
89125
protected Object getHandlerInternal(HttpServletRequest request) throws Exception {
90126

0 commit comments

Comments
 (0)