Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework Multiple filters in Global.java

I'm using Play Framework 2.3.2 (Java version)

I was wondering how I would go about adding multiple filters to the filters() override in Global.java? I have this to enable the CSRF Filter:

public class Global extends GlobalSettings {
    @Override
    public <T extends EssentialFilter> Class<T>[] filters() {
        return new Class[]{CSRFFilter.class};
    }
}

and I'd like to now also add the Gzip filter. What's the correct syntax to use to have both the CSRF filter and GZIP compression? It's described here: http://www.playframework.com/documentation/2.3.x/GzipEncoding but it doesn't say how to add that as a filter when one already exists.

Thanks in advance!

like image 844
max1221 Avatar asked Jun 07 '26 00:06

max1221


1 Answers

You can add them in the array like

return new Class[]{CSRFFilter.class, GzipFilter.class};

Unfortunately I didn't find any info about the order they are executed, but I guess they are executed in the order they are defined in the array.

like image 175
Salem Avatar answered Jun 09 '26 15:06

Salem