Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

SlingHttpServletRequest getCookies() method returning null on publish


Level 4

Hi All,

I have written a simple method to read cookie value (code below). Code works fine in author environment but breaks in publish as request.getCookies() returns null to me. I have white-listed the cookie in Opt configuration. Please can someone help what should i do to fix this.

After it works fine in publish, I hope it works in Dispatcher also.



public static String readCookieValue(final SlingHttpServletRequest request, final String name) { final Cookie[] cookies = request.getCookies(); for (final Cookie cookie : cookies) { if(cookie.getName().equals(name)){ return cookie.getValue(); } } return null; }
3 Replies


Level 9


Have you verified through browser console whether cookie is part of request or not?. if cookie is not part of request, kindly check how are you setting the cookie? 





As mentioned by Jitendra,

This actually means that the request the client sent in contains no cookies. Please check them through browsers dev tools.

Or it could be the case that your cookie got expired.


Kautuk Sahni