log.info("Destroying session!");
//destroy the session.
if (sessionId == null) {
return;
}
CookieEncoder cookieEncoder = new CookieEncoder(true);
Cookie cookie = new DefaultCookie(SESSION, "deleted");
cookie.setMaxAge(0);
cookieEncoder.addCookie(cookie);
controller.getResponse().setHeader(HttpHeaders.Names.SET_COOKIE, cookieEncoder.encode());
this.getSessionPersistence(controller).deleteSession(sessionId);
return;
}
if (sessionId == null && !controller.getSessionStorage().isEmpty()) {
CookieEncoder cookieEncoder = new CookieEncoder(true);
sessionId = UUID.randomUUID().toString();
Cookie cookie = new DefaultCookie(SESSION, sessionId);
cookie.setMaxAge(this.maxAge);
cookieEncoder.addCookie(cookie);
controller.getResponse().setHeader(HttpHeaders.Names.SET_COOKIE, cookieEncoder.encode());
}
//save the session.
controller.getSessionStorage().put("expires", IsoDateUtil.getIsoDate(new Date(new Date().getTime()+(1000*this.maxAge))));
if (sessionId != null) {
this.getSessionPersistence(controller).saveSession(sessionId, controller.getSessionStorage());