How to delete a cookie on server with JAX-RS NewCookie?
This is how it works (rather dirty approach):
return Response.ok()
.header(
"Set-Cookie",
"foo=deleted;Domain=.example.com;Path=/;Expires=Thu, 01-Jan-1970 00:00:01 GMT"
);
I cannot try proposed, but it should work (since it is common work around for java servlet API to remove cookie).
Step 1. Get access to HttpServletResponse. To do it declare in your service something like:
@Context
HttpServletResponse _currentResponse;
Step 2. Let the client side chance to remove cookie by set expiration time
Cookie userCookie = new Cookie(cookieName, "");
_currentResponse.setContentType("text/html");
userCookie.setMaxAge(0);
_currentResponse.addCookie(userCookie);