This page last changed on Aug 24, 2009 by bluk.

Context Information

In addition to request parameters and entities, there is more request information that can be accessed via request @Context injected variables.

When a resource method is invoked, the runtime injects the @Context variables.

public class Resource {
    private HttpHeaders headers;

    public void get(@Context UriInfo uriInfo) {
       /* use headers or uriInfo variable here */

HttpHeaders provides methods that allow users to access request headers. A few convenience methods such as #getAcceptableLanguages() and #getAcceptableMediaTypes() provide client preference sorted acceptable responses.

UriInfo provides methods so developers can find or build URI information of the current request.

SecurityContext provides access to the security information.

Request provides methods for evaluating preconditions and for selecting the best response variant based on the request headers.

Providers allows access to the user and runtime provided MessageBodyReaders, MessageBodyWriters, ContextResolvers, and ExceptionMappers. It is useful for other providers but can sometimes be useful for resource methods and classes.

Document generated by Confluence on Nov 11, 2009 06:57