Setting cookie in LiftFilter

Posted by Gero on Stack Overflow See other posts from Stack Overflow or by Gero
Published on 2010-12-29T08:11:59Z Indexed on 2010/12/30 20:54 UTC
Read the original article Hit count: 167

Filed under:
|
|

Hi,

How do I set a cookie in a LiftFilter.doFilter method?

I tried to set the cookie as follows (stripped some code):

class AuthenticationFilter extends LiftFilter {

  override def  doFilter(request: ServletRequest, response: ServletResponse , chain: FilterChain) {

      val cookie = new HTTPCookie("SomeCookie", Full("" + System.nanoTime), Empty,
        Full("/authentication"), Full(60 * 60 * 24 * 14), Empty, Empty)
      cookie.setPath("/somePath")
      S.addCookie(cookie)

      val httpResp = response.asInstanceOf[HttpServletResponse]
      httpResp.sendRedirect("/some/page.html")

  }
}

However, when I check the browsers cookie, no cookie is set (apart from JSESSIONID), and I know the doFilter method is being executed because of logging messages and the fact that the browser is redirected to /some/page.html.

I'm using Scala 2.8, Lift 2.1-SNAPSHOT and the app is running is GAE (1.3.6, only tested on dev_appserver so far).

Any ideas? Thanks,

Gero

© Stack Overflow or respective owner

Related posts about google-app-engine

Related posts about scala