SlingHttpServletRequest getCookies() method returning null on publish | Community
Skip to main content
Level 4
December 1, 2016

SlingHttpServletRequest getCookies() method returning null on publish

  • December 1, 2016
  • 3 replies
  • 2866 views

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; }
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

Jitendra_S_Toma
Level 10
December 2, 2016

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

kautuk_sahni
Community Manager
Community Manager
December 2, 2016

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
March 20, 2023

Did you got a solution?