You can prioritize your filters. A couple of options
Option 1:
Use @Priority for your filter classes, passing in a value (e.g. @Priority(1) ). The lower the number, the higher the priority (nothing special is needed in web.xml or a subclass of the application)
@Priority(6000) public class MyFilter1 ... {} @Priority(6001) public class MyFilter2 ... {}
See Priorities
Option 2:
Configure it programmatically in an application using Injectable Configurable . Something like
@ApplicationPath("/") public class MyApplication extends Application { public MyApplication(@Context Configurable configurable) { configurable.register(MyFilter1.class, 1000); configurable.register(MyFilter2.class, 1001); } }
Or using ResourceConfig just calling register without the Configurable entered. See API for register overload
public ResourceConfig register(Object component, int bindingPriority)
eg.
public class MyApplication extends ResourceConfig { public MyApplication() { ... register(TestFilter.class, 6000); register(TestFilter2.class, 6001);*/ } }
Note:
Just FYI, constants from the Priorites class are Priorites .
public final class Priorities { private Priorities() { } public static final int AUTHENTICATION = 1000; public static final int AUTHORIZATION = 2000; public static final int HEADER_DECORATOR = 3000; public static final int ENTITY_CODER = 4000; public static final int USER = 5000; }
They are used by some of the built-in components of the framework, so you can consider them by indicating the number at your priority. You can use them as
@Priority(Priorities.USER) // or @Priority(Priorities.USER + 1) public class MyFilter ... {}
Paul samsotha
source share