我正在尝试直接从 Cookie 请求标头中挖掘到我之前通过以下方式存储在 Play 会话中的值
Http.Context.current().session().put("my-fancy-key", "some-interesting-value");
我只能访问 play.mvc.Http.Request ,从中我可以访问 play.mvc.Http.Cookie ...但从那里我绊倒了。
这个片段不起作用......提示?
注意:我完全愿意使用不在 Play 框架中的对象。我看到 Netty 有 cookie r/w 函数,并且正在研究那些……也许是直接在 javax 中的东西?
String playSessionCookieName = Configuration.root().getString("session.cookieName", "PLAY_SESSION");
Http.Cookie playSessionCookie = r.cookie(playSessionCookieName);
if (playSessionCookie != null) {
// FIXME: What to do here to get my value?
Logger.debug("Found the cookie! Serialized value: " + playSessionCookie.value());
try {
ObjectInputStream objIn = new ObjectInputStream(new ByteArrayInputStream(playSessionCookie.value().getBytes()));
Http.Session session = (Http.Session) objIn.readObject();
// Here's the goal
Logger.debug("Found my value: " + session.get("my-fancy-key"));
} catch (Exception e) {
Logger.warn("Couldn't deserialize the value.", e);
}
}