More Than Five
More Than Five

Reputation: 10419

Equivalent of chain.doFilter in Grails

In Java, in a filter we could do:

chain.doFilter(request, response);

This mean we could use our own RequestWrappers and do:

chain.doFilter(new RequestWrapper(request), response);

What is the equivalent to chain.doFilter in grails? I would like to create my RequestWrapper and then invoked the doFilter so that the next Filter gets it?

Upvotes: 2

Views: 919

Answers (1)

ataylor
ataylor

Reputation: 66069

Grails filters (as described here) are not implemented as servlet filters. I don't think that grails filters provide a way to wrap the request.

You might be able to achieve the same effect by taking advantage of the dynamic nature of groovy. For example, you could modify the metaClass of the request object to delegate certain methods to another object.

Another alternative is to use a regular servlet filter:

  1. Create a class that extends javax.servlet.Filter in src/groovy or src/java.
  2. Run grails install-templates (if you haven't already).
  3. Update src/templates/war/web.xml to include <filter> and <filter-mapping> elements exactly as you would with a pure Java web app.

Upvotes: 3

Related Questions