简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM