Grails
  1. Grails
  2. GRAILS-8712

Filters don't work in either "run-war" or manual deployment to Tomcat 7, while work fine in "run-app"

    Details

    • Type: Bug Bug
    • Status: Reopened
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0 final
    • Fix Version/s: None
    • Labels:
    • Environment:

      Description

      I've created grails-app/conf/MyFilters.groovy

      class MyFilters {
          def filters = {
              all(controller: "*", action: "*") {
                  before = {
                      log.info "Filtering $controllerName $actionName"
                  }
              }
          }
      }
      

      I've also configured logging to file "./grails.log". When I ran app as grails run-app - the message above is logged fine, if using grails run-war - message doesn't get logged.

      Attached sample app.

        Activity

        Hide
        Serge P. Nekoval added a comment -

        I have a similar issue. However, the test application does actually work for me.
        The thing that DOESN'T work is putting NNNFilters.groovy inside a package.
        When you put Filters.groovy into a package inside grails-app/conf OR simply specify package com.mypackage in the file header, the filter stops working.

        Show
        Serge P. Nekoval added a comment - I have a similar issue. However, the test application does actually work for me. The thing that DOESN'T work is putting NNNFilters.groovy inside a package. When you put Filters.groovy into a package inside grails-app/conf OR simply specify package com.mypackage in the file header, the filter stops working.
        Hide
        Lari Hotari added a comment - - edited

        A filter in com.mypackage package should be put in grails-app/conf/com/mypackage directory . This might explain why it works in run-app mode but not in run-war / war deployment.

        Show
        Lari Hotari added a comment - - edited A filter in com.mypackage package should be put in grails-app/conf/com/mypackage directory . This might explain why it works in run-app mode but not in run-war / war deployment.
        Hide
        Hay M. Tran added a comment -

        I am using grails 2.0.4
        The filters works fine.
        I tried both conf/AppOtherFilters (no package) and conf/htmc/AppFilters (package htmc).

        Initially it didn't work for me. And then I found my problem. The problem was that I renamed the file name from HtmcFilter.groovy to AppFilter.groovy but forgot to rename the class name inside the source file. Strangely enough grails
        didn't give me any compilation error and it actually run OK in dev mode.

        In any case, renaming the class inside the source file to match the name of the file resolved the issue.

        So, double check to make sure that your class name matches your file name, and also the package name if applicable if any.

        Show
        Hay M. Tran added a comment - I am using grails 2.0.4 The filters works fine. I tried both conf/AppOtherFilters (no package) and conf/htmc/AppFilters (package htmc). Initially it didn't work for me. And then I found my problem. The problem was that I renamed the file name from HtmcFilter.groovy to AppFilter.groovy but forgot to rename the class name inside the source file. Strangely enough grails didn't give me any compilation error and it actually run OK in dev mode. In any case, renaming the class inside the source file to match the name of the file resolved the issue. So, double check to make sure that your class name matches your file name, and also the package name if applicable if any.
        Hide
        Hay M. Tran added a comment -

        Sorry, the line 'I tried both conf/AppOtherFilters (no package) and conf/htmc/AppFilters (package htmc).'
        should be 'I tried both conf/AppOtherFilters.groovy (no package) and conf/htmc/AppFilters.groovy (package htmc).'

        Show
        Hay M. Tran added a comment - Sorry, the line 'I tried both conf/AppOtherFilters (no package) and conf/htmc/AppFilters (package htmc).' should be 'I tried both conf/AppOtherFilters.groovy (no package) and conf/htmc/AppFilters.groovy (package htmc).'
        Hide
        Hay M. Tran added a comment - - edited

        I wrote a small tutorial on how to get filters to work using grails version 2.0.4 to display the number of times the grails application (site) and a particular page on the site is visited. Here is the link to the tutorial Visiting count statistics using grails filters.

        Show
        Hay M. Tran added a comment - - edited I wrote a small tutorial on how to get filters to work using grails version 2.0.4 to display the number of times the grails application (site) and a particular page on the site is visited. Here is the link to the tutorial Visiting count statistics using grails filters .

          People

          • Assignee:
            Unassigned
            Reporter:
            Vladimir Grichina
          • Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:

              Development