Access Request object from REST
To elaborate on @dfa's answer for alternatives, I find this to be simpler than specifying the variable on each resource method signature:
public class MyResource {
@Context
private HttpServletRequest httpRequest;
@GET
public Response foo() {
httpRequest.getContentType(); //or whatever else you want to do with it
}
}
On JAX-RS you must annotate a Request parameter with @Context:
@GET
public Response foo(@Context Request request) {
}
Optionally you can also inject:
- UriInfo
- HttpHeaders
- SecurityContext
- HttpServletRequest