slingHttpServletResponse.addCookie() throwing me illegalStateException with a message staying "Response is committed".
I'm using AEM 6.5.7 with HTL code in my component.
And I get the illegalStateException when I try to invoke the addCookie for my slingHttpServletResponse in the doPost method of my servlet.
Please find the below code snippet for the same;
slingHttpServletResponse.addCookie(util.updateCookie(cookieName, URLEncoder.encode(userName, "utf-8"), domainName, slingHttpServletRequest));
slingHttpServletResponse.addCookie(util.updateCookie("ssname", URLEncoder.encode(businessName, "utf-8"), domainName, slingHttpServletRequest));
- updateCookie method is as follows which is returning me the cookie value without any problem in my logs.
public static final Cookie updateCookie(String cookieName, String value, String domain,
SlingHttpServletRequest request) {
Cookie cookie;
if (null == request.getCookie(cookieName)) {
LOGGER.info("Creating new cookie.");
cookie = new Cookie(cookieName, value);
} else {
LOGGER.info("Updating existing cookie.");
cookie = request.getCookie(cookieName);
}
if (null != cookie) {
LOGGER.info("cookie is not null");
cookie.setPath("/");
cookie.setDomain(domain);
}
LOGGER.info("final cookie set:::"+cookie);
return cookie;
}
Kindly help me to resolve the problem