public Map<String, Object> toJson() { Map<String, Object> toReturn = new TreeMap<>(); if (getDomain() != null) { toReturn.put("domain", getDomain()); } if (getExpiry() != null) { toReturn.put("expiry", getExpiry()); } if (getName() != null) { toReturn.put("name", getName()); } if (getPath() != null) { toReturn.put("path", getPath()); } if (getValue() != null) { toReturn.put("value", getValue()); } toReturn.put("secure", isSecure()); toReturn.put("httpOnly", isHttpOnly()); return toReturn; }
@RequestMapping(method = RequestMethod.GET, value = "/session/{domain}") public List<Cookie> getSession(@PathVariable String domain) { return authService.getSession(domain).stream() .map(cookie -> new Cookie.Builder() .withDomain(cookie.getDomain()) .withExpiry(cookie.getExpiry()) .withIsHttpOnly(cookie.isHttpOnly()) .withIsSecure(cookie.isSecure()) .withName(cookie.getName()) .withPath(cookie.getPath()) .withValue(cookie.getValue()) .build() ).collect(toList()); }
private com.gargoylesoftware.htmlunit.util.Cookie convertSeleniumCookieToHtmlUnit(Cookie cookie) { return new com.gargoylesoftware.htmlunit.util.Cookie( cookie.getDomain(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getExpiry(), cookie.isSecure(), cookie.isHttpOnly() ); }
/** * Converts Selenium cookie to Apache http client. * @param browserCookie selenium cookie. * @return http client format. */ protected ClientCookie convertCookie(Cookie browserCookie) { BasicClientCookie cookie = new BasicClientCookie(browserCookie.getName(), browserCookie.getValue()); String domain = browserCookie.getDomain(); if (domain != null && domain.startsWith(".")) { // http client does not like domains starting with '.', it always removes it when it receives them domain = domain.substring(1); } cookie.setDomain(domain); cookie.setPath(browserCookie.getPath()); cookie.setExpiryDate(browserCookie.getExpiry()); cookie.setSecure(browserCookie.isSecure()); if (browserCookie.isHttpOnly()) { cookie.setAttribute("httponly", ""); } return cookie; } }