Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

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.

Code Block
@Path("/resource")
public class Resource {
    @Context
    private HttpHeaders headers;

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

Anchor
HttpHeaders
HttpHeaders

javax.ws.rs.core.HttpHeaders

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.

Anchor
UriInfo
UriInfo

javax.ws.rs.core.UriInfo

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

Anchor
SecurityContext
SecurityContext

javax.ws.rs.core.SecurityContext

SecurityContext provides access to the security information.

Anchor
Request
Request

javax.ws.rs.core.Request

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

Anchor
Providers
Providers

javax.ws.rs.core.Providers

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.