title: How to replace Servlet Filters already defined (replacing legacy doWithWebDescriptor with doWithSpring)
body: <p>I'm trying to upgrade a Grails plugin from version 2.3.4 to 4.0.11. It uses a syntax that is no longer supported to replace filters with names <code>sitemesh</code> and <code>urlMapping</code> with its own filters.</p>
  <p>The code below uses a DSL for xml. It replaces xml nodes in the final generated <code>web.xml</code>.</p>
  <pre><code>def doWithWebDescriptor = { xml -&gt;
      def pageFilter = xml.filter.find { it.'filter-name'.text() == 'sitemesh' }
      def urlMappingFilter = xml.filter.find { it.'filter-name'.text() == 'urlMapping' }
  
      def grailsVersion = GrailsUtil.grailsVersion
  
      // Grails 1.3.x &amp; Grails 2.0.x
      def pageFilterClass = &quot;org.zkoss.zk.grails.web.ZKGrailsPageFilter&quot;
      def urlMappingFilterClass = &quot;org.zkoss.zk.grails.web.ZULUrlMappingsFilter&quot;
  
      if(grailsVersion.startsWith(&quot;2&quot;)) {
          pageFilter.'filter-class'.replaceNode {
              'filter-class'(pageFilterClass)
          }
          urlMappingFilter.'filter-class'.replaceNode {
              'filter-class'(urlMappingFilterClass)
          }
  
          //
          // Require a legacy config for servlet version
          //
          if(application.metadata.getServletVersion() &gt;= '3.0') {
              pageFilter.'filter-class' + {
                  'async-supported'('true')
              }
              urlMappingFilter.'filter-class' + {
                  'async-supported'('true')
              }
          }
      } else {
          pageFilter.'filter-class'.replaceBody(pageFilterClass)
          urlMappingFilter.'filter-class'.replaceBody(urlMappingFilterClass)
      }
  }
  </code></pre>
  <p><strong>What I tried so far</strong></p>
  <p>The code below uses Grails plugin configuration to register filters with spring's <code>FilterRegistrationBean</code>. I'm following <a href="http://docs.grails.org/3.3.11/guide/plugins.html#hookingIntoRuntimeConfiguration" rel="nofollow noreferrer">Grails official documentation</a>.</p>
  <pre><code>Closure doWithSpring() { { -&gt;
      boolean supportsAsync = this.grailsApplication.metadata.getServletVersion() &gt;= &quot;3.0&quot;
  
      pageFilter(FilterRegistrationBean) {
          name = &quot;sitemesh&quot;
          filter = bean(org.zkoss.zk.grails.web.ZKGrailsPageFilter)
          urlPatterns = [&quot;/*&quot;]
          order = Ordered.HIGHEST_PRECEDENCE
          asyncSupported = supportsAsync
      }
  
      urlMappingFilter(FilterRegistrationBean) {
          name = &quot;urlMapping&quot;
          filter = bean(org.zkoss.zk.grails.web.ZULUrlMappingsFilter)
          urlPatterns = [&quot;/*&quot;]
          order = Ordered.HIGHEST_PRECEDENCE
          asyncSupported = supportsAsync
      }
  }}
  </code></pre>
  <p><strong>How can I replicate the legacy code with RegistrationBeans?</strong></p>
  <p>Also, I don't know if any of these filters got deprecated by Grails. I would like to know if there are any other replacements, if possible.</p>
  <p><a href="https://github.com/maiconandsilva/zk-grails" rel="nofollow noreferrer">Here's the project</a> in case anyone wants more context.</p>