Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

SlingHttpServletRequest getCookies() method returning null on publish

Avatar

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.

Thanks,

Shehjad

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

Avatar

Level 9

Hi,

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? 

Regards,

Jitendra

Avatar

Administrator

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



Kautuk Sahni