In my Java code, I am setting a custom cookie on the response as follows.
final Cookie cookie = new Cookie("FOO", "bar"); // 1 day in seconds