/** * {@inheritDoc} */ @Override public boolean equals(final Object o) { if (!(o instanceof Cookie)) { return false; } final Cookie other = (Cookie) o; final String path = getPath() == null ? "/" : getPath(); final String otherPath = other.getPath() == null ? "/" : other.getPath(); return new EqualsBuilder().append(getName(), other.getName()).append(getDomain(), other.getDomain()) .append(path, otherPath).isEquals(); }
/** * {@inheritDoc} */ @Override public boolean equals(final Object o) { if (!(o instanceof Cookie)) { return false; } final Cookie other = (Cookie) o; final String path = getPath() == null ? "/" : getPath(); final String otherPath = other.getPath() == null ? "/" : other.getPath(); return new EqualsBuilder().append(getName(), other.getName()).append(getDomain(), other.getDomain()) .append(path, otherPath).isEquals(); }
public void saveCookies() throws IOException { CookieManager cm = getWebClient().getCookieManager(); ArrayList<BasicClientCookie> list = new ArrayList<>(); for (Cookie c : cm.getCookies()) { BasicClientCookie bc = new BasicClientCookie(c.getName(), c.getValue()); bc.setDomain(c.getDomain()); bc.setPath(c.getPath()); list.add(bc); } File cookiesFile = Directories.META.getDir(cookiesFileName); if (cookiesFile.exists()) { cookiesFile.delete(); } String o = new Gson().toJson(list); FileUtils.writeByteArrayToFile(cookiesFile, o.getBytes()); } /*
/** * {@inheritDoc} */ @Override public String toString() { return getName() + "=" + getValue() + (getDomain() != null ? ";domain=" + getDomain() : "") + (getPath() != null ? ";path=" + getPath() : "") + (getExpires() != null ? ";expires=" + getExpires() : "") + (isSecure() ? ";secure" : "") + (isHttpOnly() ? ";httpOnly" : ""); }
@Override public List<javax.servlet.http.Cookie> getCookies() { List<javax.servlet.http.Cookie> result = new LinkedList<javax.servlet.http.Cookie>(); Set<Cookie> cookies = wc.getCookieManager().getCookies(); for (Cookie cookie : cookies) { javax.servlet.http.Cookie c = new javax.servlet.http.Cookie( cookie.getName(), cookie.getValue()); c.setComment(cookie.toHttpClient().getComment()); c.setDomain(cookie.getDomain()); Date expire = cookie.toHttpClient().getExpiryDate(); if (expire == null) { c.setMaxAge(-1); } else { Date now = Calendar.getInstance().getTime(); // Convert milli-second to second Long second = Long.valueOf((expire.getTime() - now.getTime()) / 1000); c.setMaxAge(second.intValue()); } c.setPath(cookie.getPath()); c.setSecure(cookie.toHttpClient().isSecure()); c.setVersion(cookie.toHttpClient().getVersion()); result.add(c); } return result; }
/** * {@inheritDoc} */ @Override public String toString() { return getName() + "=" + getValue() + (getDomain() != null ? ";domain=" + getDomain() : "") + (getPath() != null ? ";path=" + getPath() : "") + (getExpires() != null ? ";expires=" + getExpires() : "") + (isSecure() ? ";secure" : "") + (isHttpOnly() ? ";httpOnly" : ""); }
public WebResponse getResponse( WebRequest request ) throws IOException { Cookie jsCookie = webClient.getCookieManager().getCookie("JSESSIONID"); if (jsCookie != null && (!jsCookie.getValue().startsWith("\"") && !jsCookie.getValue().endsWith("\""))) { Cookie newCookie = new Cookie(jsCookie.getDomain(), jsCookie.getName(), "\"" + jsCookie.getValue() + "\"", jsCookie.getPath(), jsCookie.getExpires(), jsCookie.isSecure()); webClient.getCookieManager().removeCookie(jsCookie); webClient.getCookieManager().addCookie(newCookie); } return super.getResponse(request); } };