/** * Return a string suitable for sending in a <tt>"Cookie"</tt> header * @param cookie a {@link Cookie} to be formatted as string * @return a string suitable for sending in a <tt>"Cookie"</tt> header. */ public String formatCookie(Cookie cookie) { LOG.trace("enter CookieSpecBase.formatCookie(Cookie)"); if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } StringBuffer buf = new StringBuffer(); buf.append(cookie.getName()); buf.append("="); String s = cookie.getValue(); if (s != null) { buf.append(s); } return buf.toString(); }
/** * Two cookies are equal if the name, path and domain match. * @param obj The object to compare against. * @return true if the two objects are equal. */ public boolean equals(Object obj) { if (obj == null) return false; if (this == obj) return true; if (obj instanceof Cookie) { Cookie that = (Cookie) obj; return LangUtils.equals(this.getName(), that.getName()) && LangUtils.equals(this.cookieDomain, that.cookieDomain) && LangUtils.equals(this.cookiePath, that.cookiePath); } else { return false; } }
/** * Returns a hash code in keeping with the * {@link Object#hashCode} general hashCode contract. * @return A hash code */ public int hashCode() { int hash = LangUtils.HASH_SEED; hash = LangUtils.hashCode(hash, this.getName()); hash = LangUtils.hashCode(hash, this.cookieDomain); hash = LangUtils.hashCode(hash, this.cookiePath); return hash; }
/** * Return a string suitable for sending in a <tt>"Cookie"</tt> header * as defined in RFC 2109 for backward compatibility with cookie version 0 * @param buffer The string buffer to use for output * @param cookie The {@link Cookie} to be formatted as string * @param version The version to use. */ private void formatCookieAsVer(final StringBuffer buffer, final Cookie cookie, int version) { String value = cookie.getValue(); if (value == null) { value = ""; } formatParam(buffer, new NameValuePair(cookie.getName(), value), version); if ((cookie.getPath() != null) && cookie.isPathAttributeSpecified()) { buffer.append("; "); formatParam(buffer, new NameValuePair("$Path", cookie.getPath()), version); } if ((cookie.getDomain() != null) && cookie.isDomainAttributeSpecified()) { buffer.append("; "); formatParam(buffer, new NameValuePair("$Domain", cookie.getDomain()), version); } }
/** * Returns the currently configured cookie with the specified name, or <tt>null</tt> if one does not exist. * @param name the name of the cookie to return * @return the currently configured cookie with the specified name, or <tt>null</tt> if one does not exist */ public synchronized Cookie getCookie(final String name) { for (Cookie cookie : cookies_) { if (StringUtils.equals(cookie.getName(), name)) { return cookie; } } return null; }
/** * Returns the currently configured cookie with the specified name, or <tt>null</tt> if one does not exist. * @param name the name of the cookie to return * @return the currently configured cookie with the specified name, or <tt>null</tt> if one does not exist */ public synchronized Cookie getCookie(final String name) { for (Cookie cookie : cookies_) { if (StringUtils.equals(cookie.getName(), name)) { return cookie; } } return null; }
protected int getCookieIndexFromCookiesArray(String cookieName, Cookie[] preExistentCookies) { if (preExistentCookies != null && cookieName != null) { for (int i = 0; i < preExistentCookies.length; i++) { if (cookieName.equals(preExistentCookies[i].getName())) { return i; } } } return -1; }
/** * Returns the currently configured cookie with the specified name, or <tt>null</tt> if one does not exist. * @param name the name of the cookie to return * @return the currently configured cookie with the specified name, or <tt>null</tt> if one does not exist */ public synchronized Cookie getCookie(final String name) { for (Cookie cookie : cookies_) { if (StringUtils.equals(cookie.getName(), name)) { return cookie; } } return null; }
@Override public Object putAndMergeCookie(Object preExistentCookies, Cookie[] newCookiesArray) { if (newCookiesArray == null) { return preExistentCookies; } for (Cookie cookie : newCookiesArray) { preExistentCookies = putAndMergeCookie(preExistentCookies, cookie.getName(), cookie.getValue()); } return preExistentCookies; }
/** * Returns a hash code in keeping with the * {@link Object#hashCode} general hashCode contract. * @return A hash code */ public int hashCode() { int hash = LangUtils.HASH_SEED; hash = LangUtils.hashCode(hash, this.getName()); hash = LangUtils.hashCode(hash, this.cookieDomain); hash = LangUtils.hashCode(hash, this.cookiePath); return hash; }
/** * Returns a hash code in keeping with the * {@link Object#hashCode} general hashCode contract. * @return A hash code */ public int hashCode() { int hash = LangUtils.HASH_SEED; hash = LangUtils.hashCode(hash, this.getName()); hash = LangUtils.hashCode(hash, this.cookieDomain); hash = LangUtils.hashCode(hash, this.cookiePath); return hash; }
/** * Returns a hash code in keeping with the * {@link Object#hashCode} general hashCode contract. * @return A hash code */ public int hashCode() { int hash = LangUtils.HASH_SEED; hash = LangUtils.hashCode(hash, this.getName()); hash = LangUtils.hashCode(hash, this.cookieDomain); hash = LangUtils.hashCode(hash, this.cookiePath); return hash; }
/** * Returns a hash code in keeping with the * {@link Object#hashCode} general hashCode contract. * @return A hash code */ public int hashCode() { int hash = LangUtils.HASH_SEED; hash = LangUtils.hashCode(hash, this.getName()); hash = LangUtils.hashCode(hash, this.cookieDomain); hash = LangUtils.hashCode(hash, this.cookiePath); return hash; }
public Cookie[] getCookies() { org.apache.commons.httpclient.Cookie[] cookies = message.getInboundProperty(HttpConnector.HTTP_COOKIES_PROPERTY); if (cookies == null) return null; Cookie[] servletCookies = new Cookie[cookies.length]; for (org.apache.commons.httpclient.Cookie c : cookies) { Cookie servletCookie = new Cookie(c.getName(), c.getValue()); servletCookie.setComment(c.getComment()); servletCookie.setDomain(c.getDomain()); } return servletCookies; }
public void deleteCookieNamed(String name) { CookieManager cookieManager = webClient.getCookieManager(); Set<org.apache.commons.httpclient.Cookie> rawCookies = webClient.getCookieManager().getCookies(getHostName()); for (org.apache.commons.httpclient.Cookie cookie : rawCookies) { if (name.equals(cookie.getName())) { cookieManager.removeCookie(cookie); } } }
/** @deprecated (0.14.0) Use {@link #addCookie(ZestCookie)} instead. */ @Deprecated public void addCookie(Cookie cookie) { addCookie( cookie.getDomain(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getExpiryDate(), cookie.getSecure()); }
public Set<Cookie> getCookies() { Set<org.apache.commons.httpclient.Cookie> rawCookies = webClient.getCookieManager().getCookies(getHostName()); Set<Cookie> retCookies = new HashSet<Cookie>(); for(org.apache.commons.httpclient.Cookie c : rawCookies) { if (c.getPath() != null && getPath().startsWith(c.getPath())) { retCookies.add(new ReturnedCookie(c.getName(), c.getValue(), c.getDomain(), c.getPath(), c.getExpiryDate(), c.getSecure())); } } return retCookies; }
private void logCookie(Cookie cookie) { Log_OC.d(TAG, "Cookie name: "+ cookie.getName() ); Log_OC.d(TAG, " value: "+ cookie.getValue() ); Log_OC.d(TAG, " domain: "+ cookie.getDomain()); Log_OC.d(TAG, " path: "+ cookie.getPath() ); Log_OC.d(TAG, " version: "+ cookie.getVersion() ); Log_OC.d(TAG, " expiryDate: " + (cookie.getExpiryDate() != null ? cookie.getExpiryDate().toString() : "--")); Log_OC.d(TAG, " comment: "+ cookie.getComment() ); Log_OC.d(TAG, " secure: "+ cookie.getSecure() ); }