out.println();
}
}
StringBuffer sb = null;
StringBuffer sb2 = null;
Cookie cc = null;
// add session cookie
if (sessionValue != null) {
HttpSession session = serve.getSession(sessionValue);
if (session != null) {
if (((AcmeSession) session).isValid()) {
if (session.isNew()) {
cc = new Cookie(SESSION_COOKIE_NAME,
sessionValue);
if (serve.expiredIn < 0)
cc.setMaxAge(Math.abs(serve.expiredIn) * 60);
ServletContext sc = ((AcmeSession) session)
.getServletContext();
try {
String cp = (String) sc
.getClass()
.getMethod("getContextPath",
Utils.EMPTY_CLASSES)
.invoke(sc, Utils.EMPTY_OBJECTS);
if (cp.length() == 0)
cp = "/";
cc.setPath(cp);
} catch (Exception e) {
}
addCookie(cc);
}
} else {
cc = new Cookie(SESSION_COOKIE_NAME, "");
cc.setMaxAge(0);
addCookie(cc);
}
}
}
// how to remove a cookie
// cc = new Cookie(cookieName, "");
// cc.setMaxAge(0);
//
for (int i = 0; outCookies != null && i < outCookies.size(); i++) {
cc = (Cookie) outCookies.elementAt(i);
if (cc.getSecure() && isSecure() == false)
continue;
int version = cc.getVersion();
String token;
if (version > 1) {
if (sb2 == null)
sb2 = new StringBuffer(SETCOOKIE + "2: ");
else
sb2.append(',');
sb2.append(cc.getName());
sb2.append("=\"");
sb2.append(cc.getValue()).append('"');
token = cc.getComment();
if (token != null)
sb2.append("; Comment=\"").append(token)
.append('"');
token = cc.getDomain();
if (token != null)
sb2.append("; Domain=\"").append(token).append('"');
if (cc.getMaxAge() >= 0)
sb2.append("; Max-Age=\"").append(cc.getMaxAge())
.append('"');
token = cc.getPath();
if (token != null)
sb2.append("; Path=\"").append(token).append('"');
if (cc.getSecure()) {
sb2.append("; Secure");
}
sb2.append("; Version=\"").append(version).append('"');
} else {
if (sb == null)
sb = new StringBuffer(SETCOOKIE + ": ");
else
// sb.append(',');
sb.append("\r\n" + SETCOOKIE + ": "); // for IE not
sb.append(cc.getName());
sb.append('=');
sb.append(cc.getValue());// .append('"');
if (cc.getDomain() != null
&& cc.getDomain().length() > 0) {
sb.append("; domain=" + cc.getDomain());
}
if (cc.getMaxAge() >= 0) {
sb.append("; expires=");
sb.append(expdatefmt.format(new Date(new Date()
.getTime() + 1000l * cc.getMaxAge())));
}
if (cc.getPath() != null && cc.getPath().length() > 0) {
sb.append("; path=" + cc.getPath());
}
if (cc.getSecure()) {
sb.append("; secure");
}
}
}
if (sb != null) {