You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@grails.apache.org by "codeconsole (via GitHub)" <gi...@apache.org> on 2026/10/04 04:08:00 UTC

[PR] Show every container filter in chain order on the welcome page, and add a grails-compile-static Forge feature [grails-core]

codeconsole opened a new pull request, #16499:
URL: https://github.com/apache/grails-core/pull/16499

   ## Description
   
   The welcome page (`index.gsp`) that Forge and the `web` profile generate has a **Servlet Filters** panel built from the call stack of the request rendering `/`. It only listed the filters that ran for that one request, so a filter mapped to other paths never appeared: `assetPipelineFilter` (`/assets/*`) showed under **Filter Registrations** but not under **Servlet Filters**.
   
   ### Servlet Filters lists every filter in the container, in chain order
   
   Each row shows the URL patterns (or servlet names) the filter handles.
   
   - **Tomcat:** reads the context's filter maps (`findFilterMaps()`), the table Tomcat builds each request's chain from. It covers `FilterRegistrationBean`s, plain `Filter` beans Spring Boot adapts, and container-added filters such as `WsFilter`.
   - **Other containers:** replays the order Spring Boot registers its filters in (`ServletContextInitializerBeans`, `matchAfter` registrations last), then appends any other filters the Servlet API reports. Those are shown as `--` because no portable API exposes their position.
   - **Filter Registrations** is unchanged.
   - `welcome.filters.request` is renamed to `welcome.filters.description` in all 19 locales, since the panel no longer describes a single request.
   
   On an 8.0.0-RC2 starter app:
   
   | # | Filter | Paths |
   |---|---|---|
   | 01 | GrailsCorsFilter | `/*` |
   | 02 | ServerHttpObservationFilter | `/*` |
   | 03 | OrderedFormContentFilter | `/*` |
   | 04 | GrailsSecurityHeadersFilter | `/*` |
   | 05 | AssetPipelineFilter | `/assets/*` |
   | 06 | OrderedCharacterEncodingFilter | `/*` |
   | 07 | GrailsWebRequestFilter | `/*` |
   | 08 | WsFilter | `/*` |
   
   ### New `grails-compile-static` Forge feature
   
   The page compiles with static GSP compilation. An earlier draft of this change didn't, and nothing in the build caught it, because no test compiled the starter page statically. This PR adds a Forge feature that generates:
   
   ```groovy
   grails {
       compileStatic {
           all = true
           gsp = true   // only when the application uses GSP
       }
   }
   ```
   
   `CreateAppSpec` generates an application with the feature and runs `compileGroovyPages`, so a starter page that doesn't compile statically now fails the build. The test fails against that earlier draft of the template with the expected `[Static type checking]` errors.
   
   ### Testing
   
   - `GrailsGspSpec`, `GrailsDefaultPluginsSpec`, the new `GrailsCompileStaticSpec` and `CreateAppSpec` pass.
   - `./gradlew :grails-forge-core:codeStyle` passes.
   - Ran the template in 8.0.0-RC1 and RC2 starter apps with dynamic GSPs, and with static GSPs from a `bootJar`. Both the Tomcat path and a forced run of the other-container path render the full chain.
   
   ## Contributor Checklist
   
   ### Issue and Scope
   
   - [ ] This PR is linked to an existing issue that has been **acknowledged or approved** by the project team. If no approved issue exists, please give background on why this change is necessary.  Tickets are preferred for release change log history.
   - [ ] This PR addresses the **complete scope** of the linked issue. Partial implementations or unfinished work should not be submitted for review.
   - [ ] This PR contains a **single, focused change**. Unrelated changes should be submitted as separate pull requests.
   - [x] This PR targets the **correct branch** for the type of change:
       - **Patch release branches** (e.g., `7.0.x`): Bug fixes only. No new features or API changes.
       - **Minor release branches** (e.g., `7.1.x`): New features are welcome, but breaking existing APIs must be avoided.
       - **Major release branches** (e.g., `8.0.x`): Reserved for major changes. Breaking API changes are permitted.
   
   ### Code Quality
   
   - [x] I have **added or updated tests** that cover the changes introduced in this PR. All code contributions are expected to include appropriate test coverage.
   - [ ] I have verified that all existing tests pass by running `./gradlew build --rerun-tasks`.
   - [x] My code follows the project's **code style** guidelines. I have run `./gradlew codeStyle` and resolved any violations. See [Code Style](../CONTRIBUTING.md#code-style) for details.
   - [x] This PR does **not** include mass reformatting, style-only changes, or large-scale refactoring unless it was **explicitly approved** in the linked issue. Unsolicited reformatting will not be accepted.
   - [ ] If generative AI tooling was used in preparing this contribution, a quality model was used to ensure contributions are **consistent with the project's quality standards**.
   
   ### Licensing and Attribution
   
   - [ ] All contributed code is provided under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0), and new source files include the appropriate **Apache license header**.
   - [ ] I have the necessary rights to submit this contribution and confirm it is my own original work (see [Legal Notice](../CONTRIBUTING.md#i-want-to-contribute)).
   - [ ] If generative AI tooling was used in preparing this contribution, I have followed the [Apache Software Foundation's policy on generative tooling](https://www.apache.org/legal/generative-tooling.html) and have properly attributed its use.
   
   ### Documentation
   
   - [x] If this PR introduces user-facing changes, I have included or updated the relevant documentation.
   - [x] If this PR adds a new feature, I have updated the **What's New** section of the Grails Guide.
   - [ ] If this PR introduces breaking changes or changes that require user action during an upgrade, I have updated the **Upgrade Notes** for the corresponding version in the Grails Guide.
   - [x] The PR description clearly explains **what** was changed and **why**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.0 (fix): Show every container filter in chain order on the welcome page, and add a grails-compile-static Forge feature [grails-core]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #16499:
URL: https://github.com/apache/grails-core/pull/16499#issuecomment-5981668635

   ## 🚨 Jobs failed without executing tests 🚨
   
   ### Failed Jobs without Test Failures
   
   ❌ [Code Style / Gradle Plugin Projects](https://github.com/apache/grails-core/actions/runs/37213598411/job/111469591837?pr=16499)
   
   🏷️ Commit: cdc35cb97a82dbdd2091a15ac5989fac709ac5da
   ▶️ Tests:  0 executed
   🟡 Checks: 9/18 completed
   
   ### Rerun Controls
   
   Click the checkbox to trigger a rerun:
   
   🔲 **Rerun jobs**
   
   ---
   _Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.0 (fix): Show every container filter in chain order on the welcome page, and add a grails-compile-static Forge feature [grails-core]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #16499:
URL: https://github.com/apache/grails-core/pull/16499#issuecomment-5981243351

   ## 🔎 No tests executed 🔎
   
   🏷️ Commit: d85000de3a783baff308f9669967aad36b21a739
   ▶️ Tests:  0 executed
   ⚪️ Checks: 3/3 completed
   
   ---
   _Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.0 (fix): Show every container filter in chain order on the welcome page, and add a grails-compile-static Forge feature [grails-core]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #16499:
URL: https://github.com/apache/grails-core/pull/16499#issuecomment-5976736785

   ## [Codecov](https://app.codecov.io/gh/apache/grails-core/pull/16499?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 59.4048%. Comparing base ([`0bb1d89`](https://app.codecov.io/gh/apache/grails-core/commit/0bb1d891345d682f42e34ca788582693816f98e1?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`4bbf148`](https://app.codecov.io/gh/apache/grails-core/commit/4bbf14837e6e9874d17e76d38d42d3a0c67b4744?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 2 commits behind head on 8.0.x.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/grails-core/pull/16499/graphs/tree.svg?width=650&height=150&src=pr&token=qJrryhpk7u&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/grails-core/pull/16499?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##                8.0.x     #16499        +/-   ##
   ==================================================
   + Coverage     59.4039%   59.4048%   +0.0009%     
     Complexity      24859      24859                
   ==================================================
     Files            2171       2171                
     Lines          108237     108237                
     Branches        19744      19744                
   ==================================================
   + Hits            64297      64298         +1     
     Misses          35002      35002                
   + Partials         8938       8937         -1     
   ```
   [see 6 files with indirect coverage changes](https://app.codecov.io/gh/apache/grails-core/pull/16499/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.0 (fix): Show every container filter in chain order on the welcome page, and add a grails-compile-static Forge feature [grails-core]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #16499:
URL: https://github.com/apache/grails-core/pull/16499#issuecomment-5980635023

   ## 🔎 No tests executed 🔎
   
   🏷️ Commit: 61fa27129b800292d2b94c5d2d803aaf7341e382
   ▶️ Tests:  0 executed
   ⚪️ Checks: 2/2 completed
   
   ---
   _Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.0 (fix): Show every container filter in chain order on the welcome page, and add a grails-compile-static Forge feature [grails-core]

Posted by "jamesfredley (via GitHub)" <gi...@apache.org>.
jamesfredley commented on code in PR #16499:
URL: https://github.com/apache/grails-core/pull/16499#discussion_r4177989158


##########
grails-forge/grails-forge-core/src/main/resources/gsp/index.gsp:
##########
@@ -577,25 +577,57 @@
                 <g:def type="List" var="mimeTypeProviders"
                        value="${applicationContext.getBeansOfType(grails.web.mime.MimeTypeProvider)
                                .entrySet().toList().sort { it.key.toLowerCase() }}"/>
-                <%-- The filters still on the call stack ARE this request's pipeline, in
-                     execution order: walk the reversed stack, keep Filter classes, collapse
-                     the extra frames a filter contributes through its abstract bases, and
-                     number what remains. No registry can report this actual order. --%>
-                <g:def type="List" var="requestFilters"
-                       value="${Thread.currentThread().stackTrace.toList().reverse()
-                               .findResults { ste ->
-                                   def cls = null
-                                   try { cls = Class.forName(ste.className, false, Thread.currentThread().contextClassLoader) } catch (Throwable ignored) { }
-                                   (cls != null && jakarta.servlet.Filter.isAssignableFrom(cls)) ? cls : null
-                               }
-                               .inject([]) { acc, cls ->
-                                   Class prev = acc ? (Class) acc[-1] : null
-                                   if (prev == cls) { return acc }
-                                   if (prev != null && prev.isAssignableFrom(cls)) { acc[-1] = cls; return acc }
-                                   if (prev != null && cls.isAssignableFrom(prev)) { return acc }
-                                   acc << cls
-                               }
-                               .unique()}"/>
+                <%-- Every filter running in the container, in chain order. Tomcat's filter
+                     maps are the exact chain: FilterRegistrationBeans, plain Filter beans Boot
+                     adapted and container-added filters like WsFilter alike. Elsewhere, replay
+                     the order Boot registers its filters in (ServletContextInitializerBeans,
+                     disabled ones skipped, matchAfter ones last), then append what else the
+                     Servlet API reports, unnumbered because no portable API exposes its
+                     position. Either way the spec chains URL-pattern matches before
+                     servlet-name matches, hence the stable sorts. --%>
+                <g:set var="tomcatContext"
+                       value="${ { ->
+                           try {
+                               applicationContext.webServer.tomcat.host.findChildren().find { it.path == request.contextPath }
+                           } catch (Throwable ignored) {
+                               null
+                           }
+                       }() }"/>
+                <g:def type="List" var="servletFilters"
+                       value="${tomcatContext
+                               ? tomcatContext.findFilterMaps().toList()
+                                   .inject([:]) { Map acc, fm ->

Review Comment:
   Grouping by filter name before separating URL-pattern mappings from servlet-name mappings drops chain order. Tomcat builds the chain as URL-pattern matches first, then servlet-name matches. With maps ordered `A -> dispatcherServlet`, `B -> /*`, `A -> /*`, this page lists A then B, but Tomcat runs B then A. A filter with both kinds of mapping can also sit in different positions for different URLs, so one unconditional ordinal is not a universal chain.
   
   Preserve mapping-level order, apply the URL-then-servlet-name split before dedupe, and add that mixed-mapping case. The same block in `grails-profiles/web/skeleton/grails-app/views/index.gsp` has the same bug.



##########
grails-forge/grails-forge-core/src/main/resources/gsp/index.gsp:
##########
@@ -577,25 +577,57 @@
                 <g:def type="List" var="mimeTypeProviders"
                        value="${applicationContext.getBeansOfType(grails.web.mime.MimeTypeProvider)
                                .entrySet().toList().sort { it.key.toLowerCase() }}"/>
-                <%-- The filters still on the call stack ARE this request's pipeline, in
-                     execution order: walk the reversed stack, keep Filter classes, collapse
-                     the extra frames a filter contributes through its abstract bases, and
-                     number what remains. No registry can report this actual order. --%>
-                <g:def type="List" var="requestFilters"
-                       value="${Thread.currentThread().stackTrace.toList().reverse()
-                               .findResults { ste ->
-                                   def cls = null
-                                   try { cls = Class.forName(ste.className, false, Thread.currentThread().contextClassLoader) } catch (Throwable ignored) { }
-                                   (cls != null && jakarta.servlet.Filter.isAssignableFrom(cls)) ? cls : null
-                               }
-                               .inject([]) { acc, cls ->
-                                   Class prev = acc ? (Class) acc[-1] : null
-                                   if (prev == cls) { return acc }
-                                   if (prev != null && prev.isAssignableFrom(cls)) { acc[-1] = cls; return acc }
-                                   if (prev != null && cls.isAssignableFrom(prev)) { return acc }
-                                   acc << cls
-                               }
-                               .unique()}"/>
+                <%-- Every filter running in the container, in chain order. Tomcat's filter
+                     maps are the exact chain: FilterRegistrationBeans, plain Filter beans Boot
+                     adapted and container-added filters like WsFilter alike. Elsewhere, replay
+                     the order Boot registers its filters in (ServletContextInitializerBeans,
+                     disabled ones skipped, matchAfter ones last), then append what else the
+                     Servlet API reports, unnumbered because no portable API exposes its
+                     position. Either way the spec chains URL-pattern matches before
+                     servlet-name matches, hence the stable sorts. --%>
+                <g:set var="tomcatContext"
+                       value="${ { ->
+                           try {
+                               applicationContext.webServer.tomcat.host.findChildren().find { it.path == request.contextPath }
+                           } catch (Throwable ignored) {
+                               null
+                           }
+                       }() }"/>
+                <g:def type="List" var="servletFilters"
+                       value="${tomcatContext
+                               ? tomcatContext.findFilterMaps().toList()
+                                   .inject([:]) { Map acc, fm ->
+                                       Map row = acc.computeIfAbsent(fm.filterName) { n ->
+                                           [name: n, className: tomcatContext.findFilterDef(n)?.filterClass ?: '', urlPatterns: [], mappings: [], ordered: true]
+                                       }
+                                       row.urlPatterns.addAll(fm.URLPatterns)
+                                       row.mappings.addAll(fm.URLPatterns)
+                                       row.mappings.addAll(fm.servletNames)
+                                       acc
+                                   }
+                                   .values().toList()
+                                   .sort { it.urlPatterns ? 0 : 1 }
+                               : { ->
+                                   List springFilters = new org.springframework.boot.web.servlet.ServletContextInitializerBeans(
+                                               (org.springframework.beans.factory.ListableBeanFactory) applicationContext).toList()
+                                           .findAll { it instanceof org.springframework.boot.web.servlet.AbstractFilterRegistrationBean && it.enabled }
+                                           .collect { initializer ->
+                                               def rb = (org.springframework.boot.web.servlet.AbstractFilterRegistrationBean) initializer
+                                               List servletNames = (rb.servletNames as List) + rb.servletRegistrationBeans*.servletName
+                                               List urlPatterns = (rb.urlPatterns || servletNames) ? rb.urlPatterns as List : ['/*']
+                                               [name: rb.filterName, className: rb.filter?.getClass()?.name ?: '', urlPatterns: urlPatterns,
+                                                mappings: urlPatterns + servletNames, matchAfter: rb.matchAfter, ordered: true]
+                                           }
+                                           .sort { (it.urlPatterns ? 0 : 2) + (it.matchAfter ? 1 : 0) }

Review Comment:
   This fallback numbers reconstructed Spring registrations and then appends every other filter. That invents positions the Servlet API does not expose. A container mapping order of `external, springA, springB` displays as `springA, springB, external` with ordinals `1, 2, --`. This path also runs when the embedded-Tomcat lookup fails, including an external container.
   
   Do not assign global execution ordinals here. If Spring registration order is kept, label it as registration order, not the container chain. Same code in the profile skeleton.



##########
grails-profiles/web/skeleton/grails-app/views/index.gsp:
##########
@@ -577,25 +577,57 @@
                 <g:def type="List" var="mimeTypeProviders"
                        value="${applicationContext.getBeansOfType(grails.web.mime.MimeTypeProvider)
                                .entrySet().toList().sort { it.key.toLowerCase() }}"/>
-                <%-- The filters still on the call stack ARE this request's pipeline, in
-                     execution order: walk the reversed stack, keep Filter classes, collapse
-                     the extra frames a filter contributes through its abstract bases, and
-                     number what remains. No registry can report this actual order. --%>
-                <g:def type="List" var="requestFilters"
-                       value="${Thread.currentThread().stackTrace.toList().reverse()
-                               .findResults { ste ->
-                                   def cls = null
-                                   try { cls = Class.forName(ste.className, false, Thread.currentThread().contextClassLoader) } catch (Throwable ignored) { }
-                                   (cls != null && jakarta.servlet.Filter.isAssignableFrom(cls)) ? cls : null
-                               }
-                               .inject([]) { acc, cls ->
-                                   Class prev = acc ? (Class) acc[-1] : null
-                                   if (prev == cls) { return acc }
-                                   if (prev != null && prev.isAssignableFrom(cls)) { acc[-1] = cls; return acc }
-                                   if (prev != null && cls.isAssignableFrom(prev)) { return acc }
-                                   acc << cls
-                               }
-                               .unique()}"/>
+                <%-- Every filter running in the container, in chain order. Tomcat's filter
+                     maps are the exact chain: FilterRegistrationBeans, plain Filter beans Boot
+                     adapted and container-added filters like WsFilter alike. Elsewhere, replay
+                     the order Boot registers its filters in (ServletContextInitializerBeans,
+                     disabled ones skipped, matchAfter ones last), then append what else the
+                     Servlet API reports, unnumbered because no portable API exposes its
+                     position. Either way the spec chains URL-pattern matches before
+                     servlet-name matches, hence the stable sorts. --%>
+                <g:set var="tomcatContext"
+                       value="${ { ->
+                           try {
+                               applicationContext.webServer.tomcat.host.findChildren().find { it.path == request.contextPath }
+                           } catch (Throwable ignored) {
+                               null
+                           }
+                       }() }"/>
+                <g:def type="List" var="servletFilters"
+                       value="${tomcatContext
+                               ? tomcatContext.findFilterMaps().toList()
+                                   .inject([:]) { Map acc, fm ->

Review Comment:
   Same defect as the Forge `index.gsp`. Grouping by filter name before the URL-pattern vs servlet-name split lists `A, B` for maps ordered `A -> dispatcherServlet`, `B -> /*`, `A -> /*`, while Tomcat's URL-first chain runs `B, A`. Keep the two templates in sync when this is fixed.



##########
grails-forge/grails-forge-core/src/main/resources/gsp/index.gsp:
##########
@@ -577,25 +577,57 @@
                 <g:def type="List" var="mimeTypeProviders"
                        value="${applicationContext.getBeansOfType(grails.web.mime.MimeTypeProvider)
                                .entrySet().toList().sort { it.key.toLowerCase() }}"/>
-                <%-- The filters still on the call stack ARE this request's pipeline, in
-                     execution order: walk the reversed stack, keep Filter classes, collapse
-                     the extra frames a filter contributes through its abstract bases, and
-                     number what remains. No registry can report this actual order. --%>
-                <g:def type="List" var="requestFilters"
-                       value="${Thread.currentThread().stackTrace.toList().reverse()
-                               .findResults { ste ->
-                                   def cls = null
-                                   try { cls = Class.forName(ste.className, false, Thread.currentThread().contextClassLoader) } catch (Throwable ignored) { }
-                                   (cls != null && jakarta.servlet.Filter.isAssignableFrom(cls)) ? cls : null
-                               }
-                               .inject([]) { acc, cls ->
-                                   Class prev = acc ? (Class) acc[-1] : null
-                                   if (prev == cls) { return acc }
-                                   if (prev != null && prev.isAssignableFrom(cls)) { acc[-1] = cls; return acc }
-                                   if (prev != null && cls.isAssignableFrom(prev)) { return acc }
-                                   acc << cls
-                               }
-                               .unique()}"/>
+                <%-- Every filter running in the container, in chain order. Tomcat's filter
+                     maps are the exact chain: FilterRegistrationBeans, plain Filter beans Boot
+                     adapted and container-added filters like WsFilter alike. Elsewhere, replay
+                     the order Boot registers its filters in (ServletContextInitializerBeans,
+                     disabled ones skipped, matchAfter ones last), then append what else the
+                     Servlet API reports, unnumbered because no portable API exposes its
+                     position. Either way the spec chains URL-pattern matches before
+                     servlet-name matches, hence the stable sorts. --%>
+                <g:set var="tomcatContext"
+                       value="${ { ->
+                           try {
+                               applicationContext.webServer.tomcat.host.findChildren().find { it.path == request.contextPath }
+                           } catch (Throwable ignored) {
+                               null
+                           }
+                       }() }"/>
+                <g:def type="List" var="servletFilters"
+                       value="${tomcatContext
+                               ? tomcatContext.findFilterMaps().toList()
+                                   .inject([:]) { Map acc, fm ->
+                                       Map row = acc.computeIfAbsent(fm.filterName) { n ->
+                                           [name: n, className: tomcatContext.findFilterDef(n)?.filterClass ?: '', urlPatterns: [], mappings: [], ordered: true]
+                                       }
+                                       row.urlPatterns.addAll(fm.URLPatterns)
+                                       row.mappings.addAll(fm.URLPatterns)
+                                       row.mappings.addAll(fm.servletNames)

Review Comment:
   Non-blocking, but related. Tomcat stores a wildcard `*` mapping in `matchAllUrlPatterns` / `matchAllServletNames` and leaves the arrays empty (confirmed against Tomcat 11). Reading only `URLPatterns` and `servletNames` drops those mappings, and a match-all URL mapping is then sorted as if it had no URL mapping. Read the match-all flags in both templates.



##########
grails-forge/grails-forge-core/src/test/groovy/org/grails/forge/feature/view/GrailsGspSpec.groovy:
##########
@@ -250,11 +250,13 @@ class GrailsGspSpec extends ApplicationContextSpec implements CommandOutputFixtu
         index.contains('mappingContext.eventListeners')
         index.contains('<g:message code="welcome.datastores.listeners"/>')
 
-        and: "the request's effective filter pipeline is derived from the rendering call stack"
+        and: "servlet filters list every filter in the container in chain order, with a portable fallback"
         index.contains('data-switch-type="filters"')
-        index.contains('Thread.currentThread().stackTrace')
-        index.contains('jakarta.servlet.Filter.isAssignableFrom')
-        index.contains('<g:message code="welcome.filters.request"/>')
+        index.contains('tomcatContext.findFilterMaps()')

Review Comment:
   Non-blocking on its own, but these assertions only check that source strings are present. Dropping the disabled-registration filter, changing the sort, or omitting mapping collection would still pass. A render-level test for mixed URL/servlet-name mappings, a disabled registration, and a non-Spring filter would have caught the order bugs above.



##########
grails-profiles/web/skeleton/grails-app/views/index.gsp:
##########
@@ -577,25 +577,57 @@
                 <g:def type="List" var="mimeTypeProviders"
                        value="${applicationContext.getBeansOfType(grails.web.mime.MimeTypeProvider)
                                .entrySet().toList().sort { it.key.toLowerCase() }}"/>
-                <%-- The filters still on the call stack ARE this request's pipeline, in
-                     execution order: walk the reversed stack, keep Filter classes, collapse
-                     the extra frames a filter contributes through its abstract bases, and
-                     number what remains. No registry can report this actual order. --%>
-                <g:def type="List" var="requestFilters"
-                       value="${Thread.currentThread().stackTrace.toList().reverse()
-                               .findResults { ste ->
-                                   def cls = null
-                                   try { cls = Class.forName(ste.className, false, Thread.currentThread().contextClassLoader) } catch (Throwable ignored) { }
-                                   (cls != null && jakarta.servlet.Filter.isAssignableFrom(cls)) ? cls : null
-                               }
-                               .inject([]) { acc, cls ->
-                                   Class prev = acc ? (Class) acc[-1] : null
-                                   if (prev == cls) { return acc }
-                                   if (prev != null && prev.isAssignableFrom(cls)) { acc[-1] = cls; return acc }
-                                   if (prev != null && cls.isAssignableFrom(prev)) { return acc }
-                                   acc << cls
-                               }
-                               .unique()}"/>
+                <%-- Every filter running in the container, in chain order. Tomcat's filter
+                     maps are the exact chain: FilterRegistrationBeans, plain Filter beans Boot
+                     adapted and container-added filters like WsFilter alike. Elsewhere, replay
+                     the order Boot registers its filters in (ServletContextInitializerBeans,
+                     disabled ones skipped, matchAfter ones last), then append what else the
+                     Servlet API reports, unnumbered because no portable API exposes its
+                     position. Either way the spec chains URL-pattern matches before
+                     servlet-name matches, hence the stable sorts. --%>
+                <g:set var="tomcatContext"
+                       value="${ { ->
+                           try {
+                               applicationContext.webServer.tomcat.host.findChildren().find { it.path == request.contextPath }
+                           } catch (Throwable ignored) {
+                               null
+                           }
+                       }() }"/>
+                <g:def type="List" var="servletFilters"
+                       value="${tomcatContext
+                               ? tomcatContext.findFilterMaps().toList()
+                                   .inject([:]) { Map acc, fm ->
+                                       Map row = acc.computeIfAbsent(fm.filterName) { n ->
+                                           [name: n, className: tomcatContext.findFilterDef(n)?.filterClass ?: '', urlPatterns: [], mappings: [], ordered: true]
+                                       }
+                                       row.urlPatterns.addAll(fm.URLPatterns)
+                                       row.mappings.addAll(fm.URLPatterns)
+                                       row.mappings.addAll(fm.servletNames)
+                                       acc
+                                   }
+                                   .values().toList()
+                                   .sort { it.urlPatterns ? 0 : 1 }
+                               : { ->
+                                   List springFilters = new org.springframework.boot.web.servlet.ServletContextInitializerBeans(
+                                               (org.springframework.beans.factory.ListableBeanFactory) applicationContext).toList()
+                                           .findAll { it instanceof org.springframework.boot.web.servlet.AbstractFilterRegistrationBean && it.enabled }
+                                           .collect { initializer ->
+                                               def rb = (org.springframework.boot.web.servlet.AbstractFilterRegistrationBean) initializer
+                                               List servletNames = (rb.servletNames as List) + rb.servletRegistrationBeans*.servletName
+                                               List urlPatterns = (rb.urlPatterns || servletNames) ? rb.urlPatterns as List : ['/*']
+                                               [name: rb.filterName, className: rb.filter?.getClass()?.name ?: '', urlPatterns: urlPatterns,
+                                                mappings: urlPatterns + servletNames, matchAfter: rb.matchAfter, ordered: true]
+                                           }
+                                           .sort { (it.urlPatterns ? 0 : 2) + (it.matchAfter ? 1 : 0) }

Review Comment:
   Same fallback as the Forge template. Numbering Spring registrations and appending other filters afterward is not the container chain. A real order of `external, springA, springB` shows up as `springA, springB, external`. Do not present those ordinals as execution order.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.0 (fix): Show every container filter in chain order on the welcome page, and add a grails-compile-static Forge feature [grails-core]

Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on PR #16499:
URL: https://github.com/apache/grails-core/pull/16499#issuecomment-5980633194

   Thanks @matrei, all four addressed:
   
   1. **Disabled registrations and servlet registrations** (55e7e9c293): the fallback skips registrations with `enabled = false`, and adds the servlet names of `servletRegistrationBeans` as `AbstractFilterRegistrationBean.configure` does, so `/*` is only assumed when there are neither URL patterns nor servlet names.
   2. **`?: f.name`** (70470c27f5): guarded on the class name. A class name containing `$` (lambda, anonymous or proxy class) also falls back to the registration name.
   3. **Docs** (63101a12ac): `grailsCompileStatic.adoc` now mentions the feature, with the `create-app --features=grails-compile-static` example, after the `all`/`gsp` example.
   4. **Category** (61fa27129b): now `Category.CONFIGURATION`. `LANGUAGES` wasn't deliberate.
   
   Checked on an 8.0.0-RC2 app with static GSP compilation, both on Tomcat and with the fallback forced, using three extra registrations:
   
   - a disabled one: not listed
   - one mapped with `servletRegistrationBeans = [ref('dispatcherServletRegistration')]`: listed with that servlet name, after the URL-pattern matches
   - one whose filter is a `$Proxy` class: labelled by its registration name
   
   `GrailsGspSpec`, `GrailsCompileStaticSpec`, `GrailsDefaultPluginsSpec`, `CreateAppSpec` and `:grails-forge-core:codeStyle` pass.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.0 (fix): Show every container filter in chain order on the welcome page, and add a grails-compile-static Forge feature [grails-core]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #16499:
URL: https://github.com/apache/grails-core/pull/16499#issuecomment-5977103756

   ## ✅ All tests passed ✅
   
   🏷️ Commit: 4bbf14837e6e9874d17e76d38d42d3a0c67b4744
   ▶️ Tests:  94497 executed
   ⚪️ Checks: 85/85 completed
   
   ---
   _Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.0 (fix): Show every container filter in chain order on the welcome page, and add a grails-compile-static Forge feature [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty merged PR #16499:
URL: https://github.com/apache/grails-core/pull/16499


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.0 (fix): Show every container filter in chain order on the welcome page, and add a grails-compile-static Forge feature [grails-core]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #16499:
URL: https://github.com/apache/grails-core/pull/16499#issuecomment-5981472402

   ## 🚨 All tests passed but jobs failed 🚨
   
   ### Failed Jobs without Test Failures
   
   ❌ [CI / Build Grails-Core \(Ubuntu JDK 25\)](https://github.com/apache/grails-core/actions/runs/37212069454/job/111465359241?pr=16499)
   
   🏷️ Commit: 4f54d20054daee8bef20010148a3ace92b53ae96
   ▶️ Tests:  257 executed
   🟡 Checks: 15/87 completed
   
   ### Rerun Controls
   
   Click the checkbox to trigger a rerun:
   
   🔲 **Rerun jobs**
   
   ---
   _Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.0 (fix): Show every container filter in chain order on the welcome page, and add a grails-compile-static Forge feature [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on PR #16499:
URL: https://github.com/apache/grails-core/pull/16499#issuecomment-5981788481

   @jamesfredley I'm good to merge and I think your comments have been addressed.  Can you please re-review?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.0 (fix): Show every container filter in chain order on the welcome page, and add a grails-compile-static Forge feature [grails-core]

Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on PR #16499:
URL: https://github.com/apache/grails-core/pull/16499#issuecomment-5982040815

   Thanks @matrei. I took up the dispatcher-type thought here rather than in a follow-up.
   
   - **Dispatcher types** (7599fa986f): each row now carries its map's dispatcher types, `REQUEST` where the map states none, as Tomcat assumes. A map that leaves out `REQUEST` is badged with the types it is for, so an `ERROR`-only map no longer reads as part of an ordinary request's chain. Only those maps are badged, since every `OncePerRequestFilter` is mapped for all five types and badging every row would be noise. Off Tomcat, a Spring Boot registration's types come from `determineDispatcherTypes()`; the Servlet API doesn't expose them for the container's other filters. Both test examples register an `ERROR`-only filter and check its badge, and both specs fail with the badge removed.
   - **`grails-compile-static`** (cdc35cb97a): the generated block now sets `controllers`, `services` and `tagLibs` individually instead of `all = true`, so an artefact type a later release adds to `all` isn't compiled statically in a generated application on upgrade without anyone asking for it.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.0 (fix): Show every container filter in chain order on the welcome page, and add a grails-compile-static Forge feature [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on PR #16499:
URL: https://github.com/apache/grails-core/pull/16499#issuecomment-5982377613

   @jamesfredley I'm limited on the time  I have today so I need to get this merged so i can call the 8.0.0 vote. I believe everything is addressed, but if it's not I can reroll the vote late tonight or we can address in a future PR. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 8.0 (fix): Show every container filter in chain order on the welcome page, and add a grails-compile-static Forge feature [grails-core]

Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on code in PR #16499:
URL: https://github.com/apache/grails-core/pull/16499#discussion_r4178176905


##########
grails-forge/grails-forge-core/src/main/resources/gsp/index.gsp:
##########
@@ -577,25 +577,57 @@
                 <g:def type="List" var="mimeTypeProviders"
                        value="${applicationContext.getBeansOfType(grails.web.mime.MimeTypeProvider)
                                .entrySet().toList().sort { it.key.toLowerCase() }}"/>
-                <%-- The filters still on the call stack ARE this request's pipeline, in
-                     execution order: walk the reversed stack, keep Filter classes, collapse
-                     the extra frames a filter contributes through its abstract bases, and
-                     number what remains. No registry can report this actual order. --%>
-                <g:def type="List" var="requestFilters"
-                       value="${Thread.currentThread().stackTrace.toList().reverse()
-                               .findResults { ste ->
-                                   def cls = null
-                                   try { cls = Class.forName(ste.className, false, Thread.currentThread().contextClassLoader) } catch (Throwable ignored) { }
-                                   (cls != null && jakarta.servlet.Filter.isAssignableFrom(cls)) ? cls : null
-                               }
-                               .inject([]) { acc, cls ->
-                                   Class prev = acc ? (Class) acc[-1] : null
-                                   if (prev == cls) { return acc }
-                                   if (prev != null && prev.isAssignableFrom(cls)) { acc[-1] = cls; return acc }
-                                   if (prev != null && cls.isAssignableFrom(prev)) { return acc }
-                                   acc << cls
-                               }
-                               .unique()}"/>
+                <%-- Every filter running in the container, in chain order. Tomcat's filter
+                     maps are the exact chain: FilterRegistrationBeans, plain Filter beans Boot
+                     adapted and container-added filters like WsFilter alike. Elsewhere, replay
+                     the order Boot registers its filters in (ServletContextInitializerBeans,
+                     disabled ones skipped, matchAfter ones last), then append what else the
+                     Servlet API reports, unnumbered because no portable API exposes its
+                     position. Either way the spec chains URL-pattern matches before
+                     servlet-name matches, hence the stable sorts. --%>
+                <g:set var="tomcatContext"
+                       value="${ { ->
+                           try {
+                               applicationContext.webServer.tomcat.host.findChildren().find { it.path == request.contextPath }
+                           } catch (Throwable ignored) {
+                               null
+                           }
+                       }() }"/>
+                <g:def type="List" var="servletFilters"
+                       value="${tomcatContext
+                               ? tomcatContext.findFilterMaps().toList()
+                                   .inject([:]) { Map acc, fm ->

Review Comment:
   Fixed in 6eacfd59f6. The panel now lists one row per filter map instead of grouping by filter: the URL-pattern maps first, then the servlet-name maps under their own heading, numbered in the order Tomcat walks them. With maps `A -> dispatcherServlet`, `B -> /*`, `A -> /*` it lists B's URL map before A's, and A again under servlet names. A filter mapped more than once can run at different positions for different requests, so the numbers are per mapping rather than per filter. `WelcomePageFiltersSpec` in the new `welcome-page` test example renders exactly that case on Tomcat.



##########
grails-profiles/web/skeleton/grails-app/views/index.gsp:
##########
@@ -577,25 +577,57 @@
                 <g:def type="List" var="mimeTypeProviders"
                        value="${applicationContext.getBeansOfType(grails.web.mime.MimeTypeProvider)
                                .entrySet().toList().sort { it.key.toLowerCase() }}"/>
-                <%-- The filters still on the call stack ARE this request's pipeline, in
-                     execution order: walk the reversed stack, keep Filter classes, collapse
-                     the extra frames a filter contributes through its abstract bases, and
-                     number what remains. No registry can report this actual order. --%>
-                <g:def type="List" var="requestFilters"
-                       value="${Thread.currentThread().stackTrace.toList().reverse()
-                               .findResults { ste ->
-                                   def cls = null
-                                   try { cls = Class.forName(ste.className, false, Thread.currentThread().contextClassLoader) } catch (Throwable ignored) { }
-                                   (cls != null && jakarta.servlet.Filter.isAssignableFrom(cls)) ? cls : null
-                               }
-                               .inject([]) { acc, cls ->
-                                   Class prev = acc ? (Class) acc[-1] : null
-                                   if (prev == cls) { return acc }
-                                   if (prev != null && prev.isAssignableFrom(cls)) { acc[-1] = cls; return acc }
-                                   if (prev != null && cls.isAssignableFrom(prev)) { return acc }
-                                   acc << cls
-                               }
-                               .unique()}"/>
+                <%-- Every filter running in the container, in chain order. Tomcat's filter
+                     maps are the exact chain: FilterRegistrationBeans, plain Filter beans Boot
+                     adapted and container-added filters like WsFilter alike. Elsewhere, replay
+                     the order Boot registers its filters in (ServletContextInitializerBeans,
+                     disabled ones skipped, matchAfter ones last), then append what else the
+                     Servlet API reports, unnumbered because no portable API exposes its
+                     position. Either way the spec chains URL-pattern matches before
+                     servlet-name matches, hence the stable sorts. --%>
+                <g:set var="tomcatContext"
+                       value="${ { ->
+                           try {
+                               applicationContext.webServer.tomcat.host.findChildren().find { it.path == request.contextPath }
+                           } catch (Throwable ignored) {
+                               null
+                           }
+                       }() }"/>
+                <g:def type="List" var="servletFilters"
+                       value="${tomcatContext
+                               ? tomcatContext.findFilterMaps().toList()
+                                   .inject([:]) { Map acc, fm ->

Review Comment:
   Fixed in the same commit, 6eacfd59f6. The two copies are still identical.



##########
grails-forge/grails-forge-core/src/main/resources/gsp/index.gsp:
##########
@@ -577,25 +577,57 @@
                 <g:def type="List" var="mimeTypeProviders"
                        value="${applicationContext.getBeansOfType(grails.web.mime.MimeTypeProvider)
                                .entrySet().toList().sort { it.key.toLowerCase() }}"/>
-                <%-- The filters still on the call stack ARE this request's pipeline, in
-                     execution order: walk the reversed stack, keep Filter classes, collapse
-                     the extra frames a filter contributes through its abstract bases, and
-                     number what remains. No registry can report this actual order. --%>
-                <g:def type="List" var="requestFilters"
-                       value="${Thread.currentThread().stackTrace.toList().reverse()
-                               .findResults { ste ->
-                                   def cls = null
-                                   try { cls = Class.forName(ste.className, false, Thread.currentThread().contextClassLoader) } catch (Throwable ignored) { }
-                                   (cls != null && jakarta.servlet.Filter.isAssignableFrom(cls)) ? cls : null
-                               }
-                               .inject([]) { acc, cls ->
-                                   Class prev = acc ? (Class) acc[-1] : null
-                                   if (prev == cls) { return acc }
-                                   if (prev != null && prev.isAssignableFrom(cls)) { acc[-1] = cls; return acc }
-                                   if (prev != null && cls.isAssignableFrom(prev)) { return acc }
-                                   acc << cls
-                               }
-                               .unique()}"/>
+                <%-- Every filter running in the container, in chain order. Tomcat's filter
+                     maps are the exact chain: FilterRegistrationBeans, plain Filter beans Boot
+                     adapted and container-added filters like WsFilter alike. Elsewhere, replay
+                     the order Boot registers its filters in (ServletContextInitializerBeans,
+                     disabled ones skipped, matchAfter ones last), then append what else the
+                     Servlet API reports, unnumbered because no portable API exposes its
+                     position. Either way the spec chains URL-pattern matches before
+                     servlet-name matches, hence the stable sorts. --%>
+                <g:set var="tomcatContext"
+                       value="${ { ->
+                           try {
+                               applicationContext.webServer.tomcat.host.findChildren().find { it.path == request.contextPath }
+                           } catch (Throwable ignored) {
+                               null
+                           }
+                       }() }"/>
+                <g:def type="List" var="servletFilters"
+                       value="${tomcatContext
+                               ? tomcatContext.findFilterMaps().toList()
+                                   .inject([:]) { Map acc, fm ->
+                                       Map row = acc.computeIfAbsent(fm.filterName) { n ->
+                                           [name: n, className: tomcatContext.findFilterDef(n)?.filterClass ?: '', urlPatterns: [], mappings: [], ordered: true]
+                                       }
+                                       row.urlPatterns.addAll(fm.URLPatterns)
+                                       row.mappings.addAll(fm.URLPatterns)
+                                       row.mappings.addAll(fm.servletNames)
+                                       acc
+                                   }
+                                   .values().toList()
+                                   .sort { it.urlPatterns ? 0 : 1 }
+                               : { ->
+                                   List springFilters = new org.springframework.boot.web.servlet.ServletContextInitializerBeans(
+                                               (org.springframework.beans.factory.ListableBeanFactory) applicationContext).toList()
+                                           .findAll { it instanceof org.springframework.boot.web.servlet.AbstractFilterRegistrationBean && it.enabled }
+                                           .collect { initializer ->
+                                               def rb = (org.springframework.boot.web.servlet.AbstractFilterRegistrationBean) initializer
+                                               List servletNames = (rb.servletNames as List) + rb.servletRegistrationBeans*.servletName
+                                               List urlPatterns = (rb.urlPatterns || servletNames) ? rb.urlPatterns as List : ['/*']
+                                               [name: rb.filterName, className: rb.filter?.getClass()?.name ?: '', urlPatterns: urlPatterns,
+                                                mappings: urlPatterns + servletNames, matchAfter: rb.matchAfter, ordered: true]
+                                           }
+                                           .sort { (it.urlPatterns ? 0 : 2) + (it.matchAfter ? 1 : 0) }

Review Comment:
   Fixed in 6eacfd59f6. Nothing is numbered off Tomcat anymore. The panel lists Spring Boot's enabled registrations in registration order, then the container's other filters, under a separate description (`welcome.filters.unordered`) saying that is not necessarily the order they run. `WelcomePageFiltersJettySpec` in the new `welcome-page-jetty` test example checks it on Jetty.



##########
grails-profiles/web/skeleton/grails-app/views/index.gsp:
##########
@@ -577,25 +577,57 @@
                 <g:def type="List" var="mimeTypeProviders"
                        value="${applicationContext.getBeansOfType(grails.web.mime.MimeTypeProvider)
                                .entrySet().toList().sort { it.key.toLowerCase() }}"/>
-                <%-- The filters still on the call stack ARE this request's pipeline, in
-                     execution order: walk the reversed stack, keep Filter classes, collapse
-                     the extra frames a filter contributes through its abstract bases, and
-                     number what remains. No registry can report this actual order. --%>
-                <g:def type="List" var="requestFilters"
-                       value="${Thread.currentThread().stackTrace.toList().reverse()
-                               .findResults { ste ->
-                                   def cls = null
-                                   try { cls = Class.forName(ste.className, false, Thread.currentThread().contextClassLoader) } catch (Throwable ignored) { }
-                                   (cls != null && jakarta.servlet.Filter.isAssignableFrom(cls)) ? cls : null
-                               }
-                               .inject([]) { acc, cls ->
-                                   Class prev = acc ? (Class) acc[-1] : null
-                                   if (prev == cls) { return acc }
-                                   if (prev != null && prev.isAssignableFrom(cls)) { acc[-1] = cls; return acc }
-                                   if (prev != null && cls.isAssignableFrom(prev)) { return acc }
-                                   acc << cls
-                               }
-                               .unique()}"/>
+                <%-- Every filter running in the container, in chain order. Tomcat's filter
+                     maps are the exact chain: FilterRegistrationBeans, plain Filter beans Boot
+                     adapted and container-added filters like WsFilter alike. Elsewhere, replay
+                     the order Boot registers its filters in (ServletContextInitializerBeans,
+                     disabled ones skipped, matchAfter ones last), then append what else the
+                     Servlet API reports, unnumbered because no portable API exposes its
+                     position. Either way the spec chains URL-pattern matches before
+                     servlet-name matches, hence the stable sorts. --%>
+                <g:set var="tomcatContext"
+                       value="${ { ->
+                           try {
+                               applicationContext.webServer.tomcat.host.findChildren().find { it.path == request.contextPath }
+                           } catch (Throwable ignored) {
+                               null
+                           }
+                       }() }"/>
+                <g:def type="List" var="servletFilters"
+                       value="${tomcatContext
+                               ? tomcatContext.findFilterMaps().toList()
+                                   .inject([:]) { Map acc, fm ->
+                                       Map row = acc.computeIfAbsent(fm.filterName) { n ->
+                                           [name: n, className: tomcatContext.findFilterDef(n)?.filterClass ?: '', urlPatterns: [], mappings: [], ordered: true]
+                                       }
+                                       row.urlPatterns.addAll(fm.URLPatterns)
+                                       row.mappings.addAll(fm.URLPatterns)
+                                       row.mappings.addAll(fm.servletNames)
+                                       acc
+                                   }
+                                   .values().toList()
+                                   .sort { it.urlPatterns ? 0 : 1 }
+                               : { ->
+                                   List springFilters = new org.springframework.boot.web.servlet.ServletContextInitializerBeans(
+                                               (org.springframework.beans.factory.ListableBeanFactory) applicationContext).toList()
+                                           .findAll { it instanceof org.springframework.boot.web.servlet.AbstractFilterRegistrationBean && it.enabled }
+                                           .collect { initializer ->
+                                               def rb = (org.springframework.boot.web.servlet.AbstractFilterRegistrationBean) initializer
+                                               List servletNames = (rb.servletNames as List) + rb.servletRegistrationBeans*.servletName
+                                               List urlPatterns = (rb.urlPatterns || servletNames) ? rb.urlPatterns as List : ['/*']
+                                               [name: rb.filterName, className: rb.filter?.getClass()?.name ?: '', urlPatterns: urlPatterns,
+                                                mappings: urlPatterns + servletNames, matchAfter: rb.matchAfter, ordered: true]
+                                           }
+                                           .sort { (it.urlPatterns ? 0 : 2) + (it.matchAfter ? 1 : 0) }

Review Comment:
   Same fix, 6eacfd59f6. The copies are identical.



##########
grails-forge/grails-forge-core/src/main/resources/gsp/index.gsp:
##########
@@ -577,25 +577,57 @@
                 <g:def type="List" var="mimeTypeProviders"
                        value="${applicationContext.getBeansOfType(grails.web.mime.MimeTypeProvider)
                                .entrySet().toList().sort { it.key.toLowerCase() }}"/>
-                <%-- The filters still on the call stack ARE this request's pipeline, in
-                     execution order: walk the reversed stack, keep Filter classes, collapse
-                     the extra frames a filter contributes through its abstract bases, and
-                     number what remains. No registry can report this actual order. --%>
-                <g:def type="List" var="requestFilters"
-                       value="${Thread.currentThread().stackTrace.toList().reverse()
-                               .findResults { ste ->
-                                   def cls = null
-                                   try { cls = Class.forName(ste.className, false, Thread.currentThread().contextClassLoader) } catch (Throwable ignored) { }
-                                   (cls != null && jakarta.servlet.Filter.isAssignableFrom(cls)) ? cls : null
-                               }
-                               .inject([]) { acc, cls ->
-                                   Class prev = acc ? (Class) acc[-1] : null
-                                   if (prev == cls) { return acc }
-                                   if (prev != null && prev.isAssignableFrom(cls)) { acc[-1] = cls; return acc }
-                                   if (prev != null && cls.isAssignableFrom(prev)) { return acc }
-                                   acc << cls
-                               }
-                               .unique()}"/>
+                <%-- Every filter running in the container, in chain order. Tomcat's filter
+                     maps are the exact chain: FilterRegistrationBeans, plain Filter beans Boot
+                     adapted and container-added filters like WsFilter alike. Elsewhere, replay
+                     the order Boot registers its filters in (ServletContextInitializerBeans,
+                     disabled ones skipped, matchAfter ones last), then append what else the
+                     Servlet API reports, unnumbered because no portable API exposes its
+                     position. Either way the spec chains URL-pattern matches before
+                     servlet-name matches, hence the stable sorts. --%>
+                <g:set var="tomcatContext"
+                       value="${ { ->
+                           try {
+                               applicationContext.webServer.tomcat.host.findChildren().find { it.path == request.contextPath }
+                           } catch (Throwable ignored) {
+                               null
+                           }
+                       }() }"/>
+                <g:def type="List" var="servletFilters"
+                       value="${tomcatContext
+                               ? tomcatContext.findFilterMaps().toList()
+                                   .inject([:]) { Map acc, fm ->
+                                       Map row = acc.computeIfAbsent(fm.filterName) { n ->
+                                           [name: n, className: tomcatContext.findFilterDef(n)?.filterClass ?: '', urlPatterns: [], mappings: [], ordered: true]
+                                       }
+                                       row.urlPatterns.addAll(fm.URLPatterns)
+                                       row.mappings.addAll(fm.URLPatterns)
+                                       row.mappings.addAll(fm.servletNames)

Review Comment:
   Fixed in 6eacfd59f6. The Tomcat rows read `matchAllUrlPatterns` and `matchAllServletNames` and show the mapping as `*`, so a match-all URL mapping is listed with the URL-pattern maps. The Tomcat test example registers one.



##########
grails-forge/grails-forge-core/src/test/groovy/org/grails/forge/feature/view/GrailsGspSpec.groovy:
##########
@@ -250,11 +250,13 @@ class GrailsGspSpec extends ApplicationContextSpec implements CommandOutputFixtu
         index.contains('mappingContext.eventListeners')
         index.contains('<g:message code="welcome.datastores.listeners"/>')
 
-        and: "the request's effective filter pipeline is derived from the rendering call stack"
+        and: "servlet filters list every filter in the container in chain order, with a portable fallback"
         index.contains('data-switch-type="filters"')
-        index.contains('Thread.currentThread().stackTrace')
-        index.contains('jakarta.servlet.Filter.isAssignableFrom')
-        index.contains('<g:message code="welcome.filters.request"/>')
+        index.contains('tomcatContext.findFilterMaps()')

Review Comment:
   Agreed. b8f8c251f7 adds two test examples, `welcome-page` (Tomcat) and `welcome-page-jetty`, that stage the web profile's welcome page, compile it statically and render it in development, where the filter panels appear. Their filters cover a servlet-name map ahead of another filter's URL map, a match-all mapping, a disabled registration and a filter added straight to the container. Both specs fail against the previous template, and the Jetty spec also fails with the disabled-registration check removed. The string checks here stay only as a quick structural check of the template.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org