Issue in getting cookies from AEM servlet | Community
Skip to main content
Level 3
June 5, 2024

Issue in getting cookies from AEM servlet

  • June 5, 2024
  • 1 reply
  • 1177 views

Hi all,

 

We have our website running on AEM 6.5 AMS which is interacting with Intershop via a shared cookie. Once the user is logged into Intershop, a cookie is set by Intershop for the loggedIn user details. This cookie is leveraged by AEM to show the loggedIn user and cart info on AEM pages. AEM has a servlet (invoked from topnav) which reads through all the cookies in request and matches cookie name and then updates the header. This is working fine in AEM 6.5 currently.

 

We are now migrating the website to AEMaaCS and on our cloud dev environment, we are having issue that even though the cookie is correctly set by Intershop but when the servlet is invoked from AEM, it is not getting the cookie using request.getCookies.

 

 

I checked and the servlet call has cookie present in request headers but in below code, it is not retreived.

 

 

Below is the code from servlet to read the cookies

public static JsonObject getCookieAsJson(HttpServletRequest request, String name) {
Cookie[] cookies = request.getCookies();
JsonObject json = new JsonObject();
if (cookies != null) {
for (Cookie cookie : cookies) {
LOG.info("cookie name is:" + cookie.getName());
if (cookie.getName().equals(name)) {
JsonParser parser = new JsonParser();
json = parser.parse(cookie.getValue()).getAsJsonObject();
}
}
}
return json;
}
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

arunpatidar
Community Advisor
Community Advisor
June 5, 2024

Hi @pardeepg4829047 
Are you able to see any of the cookie in the backend? i.e.

LOG.info("cookie name is:" + cookie.getName());
Arun Patidar
Level 3
June 5, 2024

Yes..other cookies are being printed in logger.

arunpatidar
Community Advisor
Community Advisor
June 5, 2024

I am not sure about this but the only thing I noticed is size, can you try to reduce cookie size and check?

Arun Patidar