New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filters not loading with initial run-app in Grails 3.0.4/5 #9221

Closed
erichelgeson opened this Issue Sep 4, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@erichelgeson
Contributor

erichelgeson commented Sep 4, 2015

Filters seem to not be picked up when a grails 3 app starts.

Example: https://github.com/erichelgeson/filters

$ grails clean # ensure we dont have any cached classes
$ grails run-app

BUILD SUCCESSFUL

| Running application...
objc[58760]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
INFO org.grails.plugins.web.filters.FiltersGrailsPlugin - reloadFilters
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin - Resulting handlers:
Grails application running at http://localhost:8080 in environment: development

Notice that no Filters are registered. Now lets rename the file/class so spring-loaded picks it up -

File /Users/erichelgeson/source/testapps/filters/grails-app/conf/filters/MyOtherFilters.groovy changed, recompiling...
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin - onChange: [plugin:org.grails.plugins.web.filters.FiltersGrailsPlugin@5d5434bf, application:org.grails.core.legacy.LegacyGrailsApplication@1629447d, manager:grails.plugins.DefaultGrailsPluginManager@7d4ee998, ctx:org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7383eae2: startup date [Fri Sep 04 11:25:13 CDT 2015]; root of context hierarchy, source:class MyOtherFilters]
INFO org.grails.plugins.web.filters.FiltersGrailsPlugin - reloadFilters
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin - Current filter order is 'Artefact > MyOther'
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin - Processing filter 'MyOtherFilters'
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin -   Adding filter 'MyOtherFilters', since all dependencies have been added
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin - Filter dependency ordering complete
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin - Resulting handlers:
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin -   FilterToHandlerAdapter[FilterConfig[testingCheck, scope=[controller:*, action:*]], MyOtherFilters@21678584]

Now you can see the filter was registered and is working. To prove it's not something with the original class, lets rename it back to MyFilters:

File /Users/erichelgeson/source/testapps/filters/grails-app/conf/filters/MyFilters.groovy changed, recompiling...
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin - onChange: [plugin:org.grails.plugins.web.filters.FiltersGrailsPlugin@5d5434bf, application:org.grails.core.legacy.LegacyGrailsApplication@1629447d, manager:grails.plugins.DefaultGrailsPluginManager@7d4ee998, ctx:org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7383eae2: startup date [Fri Sep 04 11:25:13 CDT 2015]; root of context hierarchy, source:class MyFilters]
INFO org.grails.plugins.web.filters.FiltersGrailsPlugin - reloadFilters
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin - Current filter order is 'Artefact > MyOther,Artefact > My'
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin - Processing filter 'MyOtherFilters'
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin -   Adding filter 'MyOtherFilters', since all dependencies have been added
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin - Processing filter 'MyFilters'
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin -   Adding filter 'MyFilters', since all dependencies have been added
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin - Filter dependency ordering complete
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin - Resulting handlers:
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin -   FilterToHandlerAdapter[FilterConfig[testingCheck, scope=[controller:*, action:*]], MyOtherFilters@21678584]
DEBUG org.grails.plugins.web.filters.FiltersGrailsPlugin -   FilterToHandlerAdapter[FilterConfig[testingCheck, scope=[controller:*, action:*]], MyFilters@1263b828]

I know Filters are deprecated, but should still work and needed for porting 2.x apps :)

@graemerocher

This comment has been minimized.

Member

graemerocher commented Sep 7, 2015

The issue in your example app is that the filters are in grails-app/conf. In Grails 3.0.x this is now a resources directory and sources in here are not compiled (this is mentioned in http://grails.github.io/grails-doc/latest/guide/upgrading.html).

Filters should now go in grails-app/filters or grails-app/controllers to be picked up.

@erichelgeson

This comment has been minimized.

Contributor

erichelgeson commented Sep 7, 2015

Works, thanks. It makes sense after knowing this, but I think a mention in the upgrading doc would be helpful, since spring-loaded does pick it up when the class is changed, which lead me to a lot of confusion. (and there is no mention of this convention in the docs I can find)

I'll create a PR on grails-docs with a note on filters. Thanks for looking into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment