Incorrect `controllerName` after "filter-before" and HTTP-status URL-mapping (7.0.0)
Symptom discovered during migration of web-application from Grails v2.4.4 to v3.3.5, symptom still present in Grails v3.3.9.
Task List
- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)
Steps to Reproduce
Grails 3
- clone Grails 3 example
- start application ~
run-app - open http://localhost:8339
- notice how "first" is reported as
controllerName, irregardless thatSecondControlleris the only one executingFooTagLib.
foo.controllerName=first
Grails 2
- clone Grails 2 example
- start application ~
run-app - open http://localhost:8244/my-webapp
- last
controlleris reflected inFooTagLib
foo.controllerName=second
Expected Behaviour
foo.controllerName=second
The controller executing FooTagLib is reflected consistently when using controllerName in taglib.
The examples are based on simplified steps for the following approach:
filter/interceptorcheck for access violation before proceeding tocontroller.- if access violation; send HTTP-status 403 (access denied)
- redirect 403 via
URL-mappingtocontroller, as described here. controllerrenders human-readable response viataglib.
Actual Behaviour
Unexpected:
foo.controllerName=first
Environment Information
- Operating System: Ubuntu 16.04 (64-bit)
- Grails Version: 3.3.9
- Grails 2 JDK Version: OpenJDK Runtime Environment (Zulu 7.23.0.1-linux64) (build 1.7.0_181-b01)
- Grails 3 JDK Version: OpenJDK Runtime Environment (Zulu 8.30.0.1-linux64) (build 1.8.0_172-b01)
Example Application
Further analysis has revealed that invoking controllerName after interceptor-before etc. in Grails 3 example grails-app/controllers/my/webapp/SecondController.groovy or grails-app/views/second/showError.gsp also returns "first", instead of the expected "second".
(This worked as expected in Grails 2)
The symptom seems to trace to grails.web.api.WebAttributes.getControllerName(), where currentRequestAttributes() state seems to mismatch expected state.
Hi Grails enthusiasts,
In celebration of the long-awaited Grails 7 release, I thought I'd revisit this old issue.
$ grails -version
| Grails Version: 7.0.0
| JVM Version: 21.0.8
Executing "Steps to Reproduce" for Grails 7 unfortunately reproduces the symptom, so I've created a reproducer.
Grails 7 Request and response
$ curl http://localhost:8700/first/index
foo.controllerName=first
Log excerpt
.. INFO 25643 --- [nio-8700-exec-1] my.webapp.AccessInterceptor : AccessInterceptor.before hit!
.. INFO 25643 --- [nio-8700-exec-1] my.webapp.SecondController : SecondController.showError hit!
.. INFO 25643 --- [nio-8700-exec-1] my.webapp.FooTagLib : whoIsCalling name=first
Leaving this issue open, as the symptom is still present in Grails 7.