grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

Incorrect `controllerName` after "filter-before" and HTTP-status URL-mapping (7.0.0)

Open dlehammer opened this issue 6 years ago • 2 comments

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

  1. clone Grails 3 example
  2. start application ~ run-app
  3. open http://localhost:8339
  4. notice how "first" is reported as controllerName, irregardless that SecondController is the only one executing FooTagLib.
foo.controllerName=first

Grails 2

  1. clone Grails 2 example
  2. start application ~ run-app
  3. open http://localhost:8244/my-webapp
  4. last controller is reflected in FooTagLib
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:

  1. filter/interceptor check for access violation before proceeding to controller.
  2. if access violation; send HTTP-status 403 (access denied)
  3. redirect 403 via URL-mapping to controller, as described here.
  4. controller renders human-readable response via taglib.

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

dlehammer avatar Jan 07 '19 16:01 dlehammer

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.

dlehammer avatar Jan 08 '19 08:01 dlehammer

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.

dlehammer avatar Oct 26 '25 16:10 dlehammer