users@jersey.java.net

Re: [Jersey] unable to set cookie from server

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 02 Apr 2010 14:01:36 +0200

Hi,

What version of Jersey are you using?

Can you enable server-side logging to see what Jersey is sending back
to the browser:

   https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/container/filter/LoggingFilter.html

it might be an issue with how you have constructed the NewCookie which
is sent, in the Set-Cookie response header, to the client

You can also look at the simple console example, which uses cookies:

   http://download.java.net/maven/2/com/sun/jersey/samples/simple-console/1.1.5.1/simple-console-1.1.5.1-project.zip

and in this case i tested with Firefox and it received the Set-Cookie
and returns the Cookie.

Paul.

On Apr 2, 2010, at 1:00 PM, Pankhuri wrote:

> 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
>