Cookie set in request not received at Restlet servlet end

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Cookie set in request not received at Restlet servlet end

hims
I have a Test Client which makes Restlet Request as below :

public class TestRestlet {
public static void main(String[] args) throws IOException {
    CookieHandler.setDefault(new CookieManager( null, CookiePolicy.ACCEPT_ALL ));
    ClientResource resource = getClientResource();
    Representation rep = resource.get();
    System.out.println(rep.getText());

}

private static ClientResource getClientResource() {
    String resouceURL = "http://localhost:8080/ActivitiSampleProject/service/process-definitions?suspended=false";
    CookieSetting cookie1 = new CookieSetting("USER", "qdny6HjWY0HONvWoyufBWemrDE+5IcdsssssK0E8UGmu5RKPF7h0BWKvBPSn+Kucb82Aq");
    cookie1.setDomain(".abc.com");
    cookie1.setPath("/");
    cookie1.setMaxAge(-1);
    ClientResource resource = new ClientResource(resouceURL);
    resource.getRequest().getCookies().add(cookie1);
    return resource;
}
}

At Restlet Servlet I want to read these cookies from request and send them back to calling client to fetch some information based on the cookie.

But I am unable to retrieve the cookies : I have set my debugger at service method of org.restlet.ext.servlet.ServerServlet and the request has no cookies.

public void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    .......
}
Is this the correct way to set cookies in request what am i doing wrong.?

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3089938
Reply | Threaded
Open this post in threaded view
|

Re: Cookie set in request not received at Restlet servlet end

hims
After some hit and trials by using the following code I am able to retrieve cookies at server side. The documentation of Restlet says ClientResource internally calls Client. Is there a way the same can be achieved using ClientResource by setting some options ?. I want to use ClientResource as most of the code I plan to introduce a change to, uses ClientResource, also all example source code uses ClientResource.

        public static void main(String[] args) throws IOException {
                Client c = new Client(Protocol.HTTP);
        Request request = new Request(Method.GET,
                "http://localhost:8080/ActivitiSampleProjectNonSpring/service/hello");
        request.getCookies().add("USER", "TESTCOOKIE");
       
        Response response = c.handle(request);
        Representation rep =  response.getEntity();
        System.out.println(rep.getText());
        }