I do not understand. It worked an hour ago, and suddenly I cannot return the cookie I just set. In Chrome, I see that there is actually a cookie, but if I try to return it null:
private void setLoggedInCookie(String sessionId) {
String domain = this.getDomain();
Cookies.setCookie(ApiParameters.LOGIN_COOKIE, sessionId, expires, domain, "/", true);
String cookie = Cookies.getCookie(ApiParameters.LOGIN_COOKIE);
for (String string : Cookies.getCookieNames()) {
LOGGER.info("Cookie name: " + string);
}
if(cookie == null) {
throw new RuntimeException("Cookie is 'null'.");
}
}
private String getDomain() {
LOGGER.fine("Host name: " + Window.Location.getHostName());
String domain = Window.Location.getHostName().replaceAll(".*//", "").replaceAll("/", "").replaceAll(":.*", "");
return "localhost".equalsIgnoreCase(domain) ? "localhost" : domain;
}
What's happening?
source
share