Reputation: 2382
I want to modify the response content of specific Grails requests. How do I configure a ResponseWrapper in a request filter?
I had hoped it would be the following, but the response is a read-only property:
class MyFilters {
def filters = {
wrapFoo(controller:'foo', action:'bar') {
before = {
response = new MyResponseWrapper(response)
}
[...]
Thanks!
Upvotes: 3
Views: 1347
Reputation: 75681
You can't - Grails filters are wrappers for Spring HandlerInterceptors and are invoked further up the processing chain than servlet filters. If you want to wrap the response you need to use a real servlet filter.
Create the class in src/java or src/groovy that implements javax.servlet.Filter
and register it in web.xml like you would in a non-Grails application. To get access to web.xml run grails install-templates
and edit the file in src/templates/war
Upvotes: 7