It is perfectly legal to have multiple filters or interceptors added for a REST client or server. In such a case, you might want to control the order in which they are executed at runtime. JAX-RS allows you to manage the order of execution by adding the @javax.annotation.Priority annotation on the filter or the interceptor class. The Priority values should be non-negative. You can use standard constants defined in the javax.ws.rs.Priorities class to set the priorities. An example is given here:
@Provider @Priority(Priorities.HEADER_DECORATOR) public class JAXRSReaderInterceptor implements ReaderInterceptor { //Interceptor implementation goes here }
Interceptors and filters are sorted on the basis of their priority in ascending order. While processing a request, the request filter with the lowest priority will be executed first and followed by the next one in the sequence. While processing a response, filters are executed in reverse order. In other words, the response filter with the highest priority will be executed first, followed by the next highest one in the sequence.