Tech

REST API with Tomcat and Jersey, part 2

I have to use old style authentication with this project, and the user authentication information is stored in cookies (Ugh! I know). So for the REST APIs to read cookies to make sure an incoming request is valid (logged in), we can use

@GET
@Path("/{param}")
public Response getMsg(
@CookieParam(value = "MY_COOKIE_NAME_1") String myCookieValue1,
@CookieParam(value = "MY_COOKIE_NAME_2") int myCookieValue2,
@PathParam("param") String msg)
{
// check myCookieValue1 and myCookieValue2 are valid

// then proceed normal operation
String output = "Jersey say : " + msg;
return Response.status(200).entity(output).build();
}

Leave a comment