@Context annotation allows you to inject request/response context details into JAX-RS provider and resource classes. Injection can be performed into a class field, a bean property or a method parameter.
The following types are available only when the application is deployed in a servlet container:
Find below a quick description of each JAX-RS type available for injection:
Application: The instance of the application-supplied
Applicationsubclass can be injected into a class field or method parameter. Access to the
Applicationsubclass instance allows configuration information to be centralized in that class.
URIs and URI templates:
UriInfoprovides both static and dynamic, per-request information, about the components of a request URI.
Content negotiation and preconditions: The methods of
Requestallow a caller to determine the best matching representation variant and to evaluate whether the current state of the resource matches any preconditions in the request.
Security context: The
SecurityContextinterface provides access to information about the security context of the current request. The methods of
SecurityContextprovide access to the current user principal, information about roles assumed by the requester, whether the request arrived over a secure channel and the authentication scheme used.
Providersinterface allows for lookup of provider instances based on a set of search criteria. This interface is expected to be primarily of interest to provider authors wishing to use other providers functionality. It is injectable in both client and server providers.
Resource context: The
ResourceContextinterface provides access to instantiation and initialization of resource or subresource classes in the default per-request scope. It can be injected to help with creation and initialization, or just initialization, of instances created by an application.
Configuration: Both the client and the server runtime
Configurations are available for injection in providers (client or server) and resource classes (server only).