If you want to, you can still use the HttpServletRequestListener interface. While it doesn’t have any effect if implemented by a Root, it still works as previously with Application. See e.g.
https://vaadin.com/forum/-/message_boards/view_message/1032255 for more info.
Another option is that you use the WrappedRequest that is passed e.g. to Root.init and to RequestHandler.handleRequest. The WrappedRequest API does not yet give any direct access to cookies, but you could use WrappedHttpServletRequest.cast(WrappedRequest) to get a WrappedHttpServletRequest that gives full access to the HttpServletRequest API.
Thanks that definitely answers how to read cookies but how about setting them using the wrappedhttpservletresponse api? I prefer to use that than implement HttpServletRequestListener. Root.init only has access to WrappedRequest.
Also I noticed that in WrappedResponse interface there is no setCookie so I wonder even if I could get access to wrappedhttpservletresponse if I can set the cookie via the setCookie api. The HttpServletResponse object is private as well.
It is true that no response object is provided to Root.init, and I’m not sure whether there should be one.
You can however get a response object through using HttpServletRequestListener or RequestHandler. There is for some reason no method for getting a HttpServletResponse from a WrappedResponse, but by casting the WrappedResponse to a WrappedHttpServletResponse, you get access to all the methods from the HttpServletResponse API.
We clearly need to put some effort into the API for using cookies before Vaadin 7 is ready for prime time.
Hi, i’m not sure is this a right solution, but my way of doin this is to cast the VaadinRequest to VaadinServletRequest at the init when ur application start to get the cookies, otherwise you can also use VaadinService ( a static class ) to get the VaadinRequest and cast it to VaadinServletRequest and get cookies. To set cookie you can get the VaadinResponse by VaadinService and cast it to VaadinServletResponse then addcookie. By the way i’m using vaadin 7 beta3 ).
Cookie[] cookies = ((VaadinServletRequest)VaadinService.getCurrentRequest()).getCookies();
((VaadinServletResponse)VaadinService.getCurrentResponse()).addCookie(ursCookie);