users@jersey.java.net

unable to set cookie from server

From: Pankhuri <pankhurisa_at_rediffmail.com>
Date: 2 Apr 2010 11:00:02 -0000

I am using jersey jax-rs in eclipse galilio as backend of my project

and gxt as frontend.



I want to set session cookie from server after successful login.



However, I am unable to use the



javax.ws.rs.core.Response;

javax.ws.rs.core.NewCookie;



classes.

 I've given Response as the return value of my function.



Eclipse Browser: Header contains Set-Cookie field but this cookie is

not sent across for any request in the domain/path. The cookie is not

reflected in the cookies list on the client as well.



External Browser: Header DOES NOT contain Set-Cookie field. Rest of the

problem follows. However, I can retrive the cookie in SOME cases.



Should I use HttpServletResponse for setting cookie?



Here's the code:



package web;



import java.io.IOException;

import javax.ws.rs.POST;

import javax.ws.rs.Produces;

import javax.ws.rs.Consumes;

import javax.ws.rs.core.CacheControl;

import javax.ws.rs.core.NewCookie;

import javax.ws.rs.core.Response;



import business.LoginBO;



@Path("/login")



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();

        }

}







Please help