Java Reference
In-Depth Information
unauthenticated users executing any of your JAX-RS components. So, if you have a custom
authentication filter, you probably want that filter to be executed first. Another example is
the combination of our GZIP encoding example with a separate WriterInterceptor that
encrypts the message body. You probably don't want to encrypt a GZIP-encoded representa-
tion. Instead you'll want to GZIP-encode an encrypted representation. So ordering is import-
ant.
In JAX-RS, filters and interceptors are assigned a numeric priority either through the @Pri-
ority annotation or via a programmatic interface defined by Configurable . The JAX-RS
runtime sorts filters and interceptors based on this numeric priority. Smaller numbers are first
in the chain:
package
package javax . annotation ;
public
public @interface Priority {
int
int value ();
}
The @Priority annotation is actually reused from the injection framework that comes with
JDK 7. This annotation would be used as follows:
import
import javax.annotation.Priority
javax.annotation.Priority ;
import
import javax.ws.rs.Priorities
javax.ws.rs.Priorities ;
@Provider
@PreMatching
@Priority ( Priorities . AUTHENTICATION )
public
public class
class BearerTokenFilter
BearerTokenFilter implements
implements ContainerRequestFilter {
...
}
The @Priority annotation can take any numeric value you wish. The Priorities class spe-
cifies some common constants that you can use when applying the @Priority annotation:
package
package javax . ws . rs ;
public
public final
final class
class Priorities
Priorities {
private
private Priorities () {
// prevents construction
}
/**
* Security authentication filter/interceptor priority.
*/
Search WWH ::




Custom Search