String result = null;
Cookie cookie = null;
HttpServletResponse response = responseProvider.get();
if (response.isCommitted()) {
throw new OrgamaCoreException(
"Cookies cannot be added to the response after the " +
"response has been committed");
}
Cookie existingCookie = getCookieFromRequest(name);
if (existingCookie == null) {
cookie = new Cookie(name, value);
}
else {
result = existingCookie.getValue();
cookie = (Cookie)existingCookie.clone();
cookie.setValue(value);
}
if (expirationDate != null) {
cookie.setMaxAge((int)((expirationDate.getTime() -
new Date().getTime()) / 1000L));
}
updatedCookies.put(name, cookie);
response.addCookie(cookie);
return result;
}
catch(OrgException ox) {
throw ox;
}
catch(Exception ex) {
throw new OrgamaCoreException(
"Failed to set the value of cookie: " + name, ex);
}
}