Java Reference
In-Depth Information
public
public static
static final
final int
int AUTHENTICATION = 1000 ;
/**
* Security authorization filter/interceptor priority.
*/
public
public static
static final
final int
int AUTHORIZATION = 2000 ;
/**
* Header decorator filter/interceptor priority.
*/
public
public static
static final
final int
int HEADER_DECORATOR = 3000 ;
/**
* Message encoder or decoder filter/interceptor priority.
*/
public
public static
static final
final int
int ENTITY_CODER = 4000 ;
/**
* User-level filter/interceptor priority.
*/
public
public static
static final
final int
int USER = 5000 ;
}
If no priority is specified, the default is USER , 5000 . There's a few Configur-
able.register() methods that you can use as an alternative to the @Priority annotation to
manually assign or override the priority for a filter or interceptor. As mentioned before, the
client classes ClientBuilder , Client , WebTarget , and Invocation.Builder all imple-
ment the Configurable interface. Here's an example of manually setting an interceptor pri-
ority using this inherited Configurable.register() :
ClientBuilder builder = ClientBuilder . newBuilder ();
builder . register ( GZipEncoder . class , Priorities . ENTITY_CODER );
On the server side, you can inject an instance of Configurable into the constructor of your
Application class:
import
import javax.ws.rs.core.Configurable
javax.ws.rs.core.Configurable ;
@ApplicationPath ( "/" )
public
public class
class MyApplication
MyApplication {
public
public MyApplication ( @Context Configurable configurable ) {
configurable . register ( BearerTokenFilter . class , Priorities . AUTHENTICATION );
}
}
Personally, I prefer using the @Priority annotation, as then my filters and interceptors are
self-contained. Users can just plug in my components without having to worry about priorit-
ies.
Search WWH ::




Custom Search