Unable to set cookie in response header (newcookie doesn't show in external browser) : Jersey jax-rs
- by Pankhuri
I am trying to set a session cookie from server side :
import javax.ws.rs.core.NewCookie;
import javax.ws.rs.core.Response;
public class Login {
@POST
@Produces("application/json")
@Consumes("application/json")
public Response login (String RequestPacket){
NewCookie cookie=null;
CacheControl cc=new CacheControl();
cookie = LoginBO.validUser(RequestPacket);
cc.setNoCache(true);
if(cookie.getValue()!=null)
return Response.ok("welcome "+cookie.getValue()).cookie(cookie).cacheControl(cc).build();
else
return Response.status(404).entity("Invalid User").build();
}
}
In eclipse browser: on the client side (using gxt for that) when I print header i get the Set-Cookie field. which is expected. But the browser is not storing the cookie.
in external browser: the header doesn't have any set-cookie field.
Should I use HTTPServletResponse? But shouldn't the javax.ws.rs.core.Response work as well?