Skip to content

Commit 93fe14d

Browse files
committed
Merge branch '2.3.x' into 2.4.x
Conflicts: gradle/assemble.gradle grails-plugin-filters/src/main/groovy/org/codehaus/groovy/grails/plugins/web/filters/FilterToHandlerAdapter.groovy grails-plugin-filters/src/test/groovy/org/codehaus/groovy/grails/web/filters/FilterToHandlerAdapterTests.groovy grails-resources/src/grails/grails-app/conf/BuildConfig.groovy
2 parents 2606470 + 29d10be commit 93fe14d

File tree

5 files changed

+118
-89
lines changed

5 files changed

+118
-89
lines changed

grails-bootstrap/src/main/groovy/grails/util/BuildSettings.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,7 @@ class BuildSettings extends AbstractBuildSettings {
15111511
String syspropDebugArgs = System.getProperty("grails.project.fork.run.debugArgs")
15121512
boolean debugFork = Boolean.getBoolean(ForkedGrailsProcess.DEBUG_FORK)
15131513
if (syspropDebugArgs || debugFork) {
1514-
if (result.run instanceof Boolean) {
1514+
if (!(result.run instanceof Map)) {
15151515
result.run = [:]
15161516
}
15171517
result.run.debug = true
@@ -1521,7 +1521,7 @@ class BuildSettings extends AbstractBuildSettings {
15211521
}
15221522
syspropDebugArgs = System.getProperty("grails.project.fork.test.debugArgs")
15231523
if (syspropDebugArgs || debugFork) {
1524-
if (result.test instanceof Boolean) {
1524+
if (!(result.test instanceof Map)) {
15251525
result.test = [:]
15261526
}
15271527
result.test.debug = true

grails-bootstrap/src/main/groovy/org/codehaus/groovy/grails/cli/fork/ForkedGrailsProcess.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,18 @@ abstract class ForkedGrailsProcess {
332332
ServerSocket parentAvailabilityServer = new ServerSocket(0)
333333
def parentPort = parentAvailabilityServer.localPort
334334
System.setProperty(PARENT_PROCESS_PORT, String.valueOf(parentPort))
335+
336+
337+
Thread.start {
338+
while(!parentAvailabilityServer.isClosed()) {
339+
try {
340+
// simply accept and close the socket
341+
parentAvailabilityServer.accept().close()
342+
} catch (e) {
343+
// ignore
344+
}
345+
}
346+
}
335347
Runtime.addShutdownHook {
336348
try {
337349
parentAvailabilityServer?.close()

grails-plugin-filters/src/main/groovy/org/codehaus/groovy/grails/plugins/web/filters/FilterConfig.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import org.springframework.web.servlet.ModelAndView
3737
*/
3838
class FilterConfig extends ControllersApi {
3939
String name
40-
Map scope
40+
Map scope = [:]
4141
Closure before
4242
Closure after
4343
Closure afterView

grails-plugin-filters/src/main/groovy/org/codehaus/groovy/grails/plugins/web/filters/FilterToHandlerAdapter.groovy

Lines changed: 82 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
*/
1616
package org.codehaus.groovy.grails.plugins.web.filters
1717

18+
import groovy.transform.CompileDynamic
19+
import groovy.transform.CompileStatic
20+
import org.codehaus.groovy.grails.commons.GrailsControllerClass
21+
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
22+
1823
import java.util.regex.Pattern
1924

2025
import javax.servlet.http.HttpServletRequest
2126
import javax.servlet.http.HttpServletResponse
2227

23-
import groovy.lang.GroovyObject;
2428
import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes
2529
import org.codehaus.groovy.grails.web.servlet.view.NullView
2630
import org.codehaus.groovy.grails.web.util.WebUtils
@@ -38,24 +42,27 @@ import org.codehaus.groovy.grails.commons.GrailsApplication
3842
* @author mike
3943
* @author Graeme Rocher
4044
*/
45+
@CompileStatic
4146
class FilterToHandlerAdapter implements HandlerInterceptor, InitializingBean, GrailsApplicationAware {
42-
def filterConfig
47+
FilterConfig filterConfig
4348
def configClass
4449

45-
def controllerRegex
46-
def controllerExcludeRegex
47-
def controllerNamespaceRegex
48-
def controllerNamespaceExcludeRegex
49-
def actionRegex
50-
def actionExcludeRegex
51-
def uriPattern
52-
def uriExcludePattern
53-
def urlPathHelper = new UrlPathHelper()
54-
def pathMatcher = new AntPathMatcher()
55-
def useRegex // standard regex
56-
def invertRule // invert rule
57-
def useRegexFind // use find instead of match
58-
def dependsOn = [] // any filters that need to be processed before this one
50+
Pattern controllerRegex
51+
Pattern controllerExcludeRegex
52+
Pattern controllerNamespaceRegex
53+
Pattern controllerNamespaceExcludeRegex
54+
55+
Pattern actionRegex
56+
Pattern actionExcludeRegex
57+
String uriPattern
58+
String uriExcludePattern
59+
UrlPathHelper urlPathHelper = new UrlPathHelper()
60+
AntPathMatcher pathMatcher = new AntPathMatcher()
61+
boolean useRegex // standard regex
62+
boolean invertRule // invert rule
63+
boolean useRegexFind // use find instead of match
64+
List dependsOn = [] // any filters that need to be processed before this one
65+
5966
GrailsApplication grailsApplication
6067

6168
void afterPropertiesSet() {
@@ -65,73 +72,89 @@ class FilterToHandlerAdapter implements HandlerInterceptor, InitializingBean, Gr
6572
invertRule = scope.invert
6673
useRegexFind = scope.find
6774

68-
if (scope.controller) {
69-
controllerRegex = Pattern.compile((useRegex)?scope.controller:scope.controller.replaceAll("\\*", ".*"))
75+
76+
def controller = scope.controller
77+
if (controller) {
78+
controllerRegex = Pattern.compile( useRegex ? controller.toString() : controller.toString().replaceAll("\\*", ".*") )
7079
}
7180
else {
7281
controllerRegex = Pattern.compile(".*")
7382
}
7483

75-
if (scope.controllerExclude) {
76-
controllerExcludeRegex = Pattern.compile((useRegex)?scope.controllerExclude:scope.controllerExclude.replaceAll("\\*", ".*"))
84+
85+
def controllerExclude = scope.controllerExclude
86+
if (controllerExclude) {
87+
controllerExcludeRegex = Pattern.compile( useRegex ? controllerExclude.toString() : controllerExclude.toString().replaceAll("\\*", ".*") )
7788
}
7889

79-
if(scope.namespace) {
80-
controllerNamespaceRegex = Pattern.compile((useRegex)?scope.namespace:scope.namespace.replaceAll("\\*", ".*"))
90+
91+
def namespace = scope.namespace
92+
if(namespace) {
93+
controllerNamespaceRegex = Pattern.compile( useRegex ? namespace.toString() : namespace.toString().replaceAll("\\*", ".*"))
8194
} else {
8295
controllerNamespaceRegex = Pattern.compile(".*")
8396
}
8497

85-
if(scope.namespaceExclude) {
86-
controllerNamespaceExcludeRegex = Pattern.compile((useRegex)?scope.namespaceExclude:scope.namespaceExclude.replaceAll("\\*", ".*"))
98+
99+
def namespaceExclude = scope.namespaceExclude
100+
if(namespaceExclude) {
101+
controllerNamespaceExcludeRegex = Pattern.compile( useRegex ? namespaceExclude.toString() : namespaceExclude.toString().replaceAll("\\*", ".*"))
87102
}
88103

89-
if (scope.action) {
90-
actionRegex = Pattern.compile((useRegex)?scope.action:scope.action.replaceAll("\\*", ".*"))
104+
105+
def action = scope.action
106+
if (action) {
107+
actionRegex = Pattern.compile( useRegex ? action.toString() : action.toString().replaceAll("\\*", ".*") )
91108
}
92109
else {
93110
actionRegex = Pattern.compile(".*")
94111
}
95112

96-
if (scope.actionExclude) {
97-
actionExcludeRegex = Pattern.compile((useRegex)?scope.actionExclude:scope.actionExclude.replaceAll("\\*", ".*"))
113+
114+
def actionExclude = scope.actionExclude
115+
if (actionExclude) {
116+
actionExcludeRegex = Pattern.compile(useRegex ? actionExclude.toString() : actionExclude.toString().replaceAll("\\*", ".*") )
98117
}
99118

100-
if (scope.uri) {
101-
uriPattern = scope.uri.toString()
119+
120+
def uri = scope.uri
121+
if (uri) {
122+
uriPattern = uri.toString()
102123
}
103-
if (scope.uriExclude) {
104-
uriExcludePattern = scope.uriExclude.toString()
124+
125+
def uriExclude = scope.uriExclude
126+
if (uriExclude) {
127+
uriExcludePattern = uriExclude.toString()
105128
}
106129
}
107130

108131
/**
109132
* Returns the name of the controller targeted by the given request.
110133
*/
111-
String controllerName(request) {
134+
String controllerName(HttpServletRequest request) {
112135
return request.getAttribute(GrailsApplicationAttributes.CONTROLLER_NAME_ATTRIBUTE)?.toString()
113136
}
114137

115-
def controllerClass(request) {
116-
return request.getAttribute(GrailsApplicationAttributes.CONTROLLER)
138+
GrailsControllerClass controllerClass(HttpServletRequest request) {
139+
return (GrailsControllerClass) request.getAttribute(GrailsApplicationAttributes.GRAILS_CONTROLLER_CLASS)
117140
}
118141

119142
/**
120143
* Returns the namespace of the controller targeted by the given request.
121144
**/
122-
String controllerNamespace(request) {
145+
String controllerNamespace(HttpServletRequest request) {
123146
return request.getAttribute(GrailsApplicationAttributes.CONTROLLER_NAMESPACE_ATTRIBUTE)?.toString()
124147
}
125148

126149
/**
127150
* Returns the name of the action targeted by the given request.
128151
*/
129-
String actionName(request) {
152+
String actionName(HttpServletRequest request) {
130153
return request.getAttribute(GrailsApplicationAttributes.ACTION_NAME_ATTRIBUTE)?.toString()
131154
}
132155

133156
String uri(HttpServletRequest request) {
134-
def uri = request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE)
157+
String uri = request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE)?.toString()
135158
if (!uri) uri = request.getRequestURI()
136159
return uri.substring(request.getContextPath().length())
137160
}
@@ -147,7 +170,7 @@ class FilterToHandlerAdapter implements HandlerInterceptor, InitializingBean, Gr
147170

148171
if (!accept(controllerName, actionName, uri, controllerNamespace, controllerClass)) return true
149172

150-
def callable = filterConfig.before.clone()
173+
def callable = (Closure)filterConfig.before.clone()
151174
def result = callable.call()
152175
if (result instanceof Boolean) {
153176
if (!result && filterConfig.modelAndView) {
@@ -161,6 +184,7 @@ class FilterToHandlerAdapter implements HandlerInterceptor, InitializingBean, Gr
161184
}
162185

163186
void postHandle(HttpServletRequest request, HttpServletResponse response, o, ModelAndView modelAndView) {
187+
final filterConfig = this.filterConfig
164188
if (!filterConfig.after) {
165189
return
166190
}
@@ -173,7 +197,7 @@ class FilterToHandlerAdapter implements HandlerInterceptor, InitializingBean, Gr
173197

174198
if (!accept(controllerName, actionName, uri, controllerNamespace, controllerClass)) return
175199

176-
def callable = filterConfig.after.clone()
200+
def callable = (Closure) filterConfig.after.clone()
177201
def currentModel = modelAndView?.model
178202
if (currentModel == null) {
179203
final templateModel = request.getAttribute(GrailsApplicationAttributes.TEMPLATE_MODEL)
@@ -182,26 +206,29 @@ class FilterToHandlerAdapter implements HandlerInterceptor, InitializingBean, Gr
182206
}
183207
}
184208
def result = callable.call(currentModel)
209+
final filterConfigModel = filterConfig.modelAndView
185210
if (result instanceof Boolean) {
186211
// if false is returned don't render a view
187212
if (!result) {
188213
modelAndView.viewName = null
189214
modelAndView.view = new NullView(response.contentType)
190215
}
191216
}
192-
else if (filterConfig.modelAndView && modelAndView) {
193-
if (filterConfig.modelAndView.viewName) {
194-
modelAndView.viewName = filterConfig.modelAndView.viewName
217+
else if (filterConfigModel && modelAndView) {
218+
if (filterConfigModel.viewName) {
219+
modelAndView.viewName = filterConfigModel.viewName
195220
}
196-
modelAndView.model.putAll(filterConfig.modelAndView.model)
221+
modelAndView.model.putAll(filterConfigModel.model)
197222
}
198-
else if (filterConfig.modelAndView?.viewName) {
223+
else if (filterConfigModel?.viewName) {
199224
renderModelAndView(filterConfig, request, response, controllerName)
200225
}
201226
}
202227

203-
private renderModelAndView(delegate, request, response, controllerName) {
204-
def viewResolver = WebUtils.lookupViewResolver(delegate.servletContext)
228+
@CompileDynamic
229+
private renderModelAndView(delegate, HttpServletRequest request, HttpServletResponse response, String controllerName) {
230+
def webRequest = GrailsWebRequest.lookup(request)
231+
def viewResolver = WebUtils.lookupViewResolver(webRequest.servletContext)
205232
def view
206233
ModelAndView modelAndView = delegate.modelAndView
207234
if (modelAndView.viewName) {
@@ -220,19 +247,21 @@ class FilterToHandlerAdapter implements HandlerInterceptor, InitializingBean, Gr
220247

221248
String controllerName = controllerName(request)
222249
String controllerNamespace = controllerNamespace(request)
223-
def controllerClass = controllerClass(request)
250+
def controller = this.controllerClass(request)
224251
String actionName = actionName(request)
225252
String uri = uri(request)
226253

227-
if (!accept(controllerName, actionName, uri, controllerNamespace, controllerClass)) return
254+
if (!accept(controllerName, actionName, uri, controllerNamespace, controller)) return
228255

229-
def callable = filterConfig.afterView.clone()
256+
def callable = (Closure)filterConfig.afterView.clone()
230257
callable.call(e)
231258
}
232259

233-
boolean accept(String controllerName, String actionName, String uri, String controllerNamespace, controllerClass) {
260+
boolean accept(String controllerName, String actionName, String uri, String controllerNamespace, GrailsControllerClass controllerClass) {
234261
boolean matched=true
235262

263+
uri = uri.replace(';', '')
264+
final pathMatcher = this.pathMatcher
236265
if (uriPattern) {
237266
matched = pathMatcher.match(uriPattern, uri)
238267
if (matched && uriExcludePattern) {
@@ -263,8 +292,8 @@ class FilterToHandlerAdapter implements HandlerInterceptor, InitializingBean, Gr
263292
}
264293
if (matched && (filterConfig.scope.action)) {
265294
if (!actionName && controllerName) {
266-
if(controllerClass && controllerClass.respondsTo("getDefaultAction")) {
267-
actionName = controllerClass?.getDefaultAction()
295+
if(controllerClass) {
296+
actionName = controllerClass.defaultAction
268297
}
269298
}
270299
matched = doesMatch(actionRegex, actionName)

0 commit comments

Comments
 (0)