November 2017
Intermediate to advanced
420 pages
10h 29m
English
The @javax.ws.rs.CookieParam annotation injects the matching cookie parameters present in the HTTP headers into a class field, a resource class bean property (the getter method for accessing the attribute), or a method parameter.
The following code snippet uses the Default-Dept cookie parameter present in the request to return the default department details:
@GET
@Path("cook")
@Produces(MediaType.APPLICATION_JSON)
public Department getDefaultDepartment(@CookieParam("Default-Dept") short departmentId) {
Department dept=findDepartmentById(departmentId);
return dept;
}