How to read header parameter in Jersey REST - directly into a variable.
//contentType is the String variable which can be used later inside the method.
@GET
public Response getFirstUser(@HeaderParam("Content-Type")
String contentType){
.....
System.out.println("content type:" + contentType)
..
}
There is one more way, by reading using @Context HttpHeader (you can also use this in case you need to get multiple/all header parameters)://All headers can be read by iterating over headers object.
@GET
public Response getFirstUser(
@Context HttpHeaders headers){
String contentType = headers.getRequestHeader("Content-Type");
String userAgent= headers.getRequestHeader("user-agent").get(0);...
...
}