/** * 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(); }
/** * 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); } }
/** * Gets the token value. * * @param tokenName the token name * @return the token value */ public String getTokenValue(String tokenName) { Cookie ck = tokenValues.get(tokenName); if (ck != null) { return ck.getValue(); } return null; }
/** * Adds the specified cookie. * @param cookie the cookie to add */ public synchronized void addCookie(final Cookie cookie) { if (cookie.getValue() == null) { cookie.setValue(""); } cookies_.remove(cookie); cookies_.add(cookie); }
/** * Adds the specified cookie. * @param cookie the cookie to add */ public synchronized void addCookie(final Cookie cookie) { if (cookie.getValue() == null) { cookie.setValue(""); } cookies_.remove(cookie); cookies_.add(cookie); }
/** * Removes the specified cookie. * @param cookie the cookie to remove */ public synchronized void removeCookie(final Cookie cookie) { if (cookie.getValue() == null) { cookie.setValue(""); } cookies_.remove(cookie); }
/** * Removes the specified cookie. * @param cookie the cookie to remove */ public synchronized void removeCookie(final Cookie cookie) { if (cookie.getValue() == null) { cookie.setValue(""); } cookies_.remove(cookie); }
/** * Removes the specified cookie. * @param cookie the cookie to remove */ public synchronized void removeCookie(final Cookie cookie) { if (cookie.getValue() == null) { cookie.setValue(""); } cookies_.remove(cookie); }
/** * Adds the specified cookie. * @param cookie the cookie to add */ public synchronized void addCookie(final Cookie cookie) { if (cookie.getValue() == null) { cookie.setValue(""); } cookies_.remove(cookie); cookies_.add(cookie); }
@Override public String getCookieValueFromCookies(Object cookiesObject, String cookieName) { Cookie[] cookies = (Cookie[]) cookiesObject; int sessionIndex = getCookieIndexFromCookiesArray(cookieName, cookies); if (sessionIndex >= 0) { return cookies[sessionIndex].getValue(); } else { return null; } }
/** * Gets the token values string representation. * * @return the token values string */ public String getTokenValuesString() { if (tokenValues.isEmpty()) { return ""; } StringBuilder buf = new StringBuilder(); for (Map.Entry<String, Cookie> entry : tokenValues.entrySet()) { buf.append(entry.getKey()).append('=').append(entry.getValue().getValue()).append(';'); } buf.deleteCharAt(buf.length() - 1); return buf.toString(); }
@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; }
private static List<List<Pair<String, String>>> convertTokenValues(Map<String, Cookie> values) { List<List<Pair<String, String>>> tokens = new ArrayList<>(); for (Entry<String, Cookie> token : values.entrySet()) { Cookie cookie = token.getValue(); List<Pair<String, String>> fields = new ArrayList<>(); fields.add(new Pair<>("name", token.getKey())); fields.add(new Pair<>("value", cookie.getValue())); fields.add(new Pair<>("domain", cookie.getDomain())); fields.add(new Pair<>("path", cookie.getPath())); fields.add(new Pair<>("secure", Boolean.toString(cookie.getSecure()))); tokens.add(fields); } return tokens; } }
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; }
/** * This method formats the cookie so it can be send from server to client in a * {@linkplain HttpConstants#HEADER_COOKIE_SET "Set-Cookie"} header. */ public static String formatCookieForASetCookieHeader(Cookie cookie) { StringBuffer sb = new StringBuffer(); ServerCookie.appendCookieValue(sb, cookie.getVersion(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getDomain(), cookie.getComment(), -1, cookie.getSecure(), false); Date expiryDate = cookie.getExpiryDate(); if (expiryDate != null) { sb.append("; Expires="); sb.append(EXPIRE_FORMATTER.format(expiryDate)); } return sb.toString(); }
/** @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 logCookiesAtState(String when) { Cookie[] cookies = getState().getCookies(); if (cookies.length == 0) { Log_OC.d(TAG + " #" + mInstanceNumber, "No cookie at STATE " + when); } else { Log_OC.d(TAG + " #" + mInstanceNumber, "Cookies at STATE (" + when + ")"); for (int i=0; i<cookies.length; i++) { Log_OC.d(TAG + " #" + mInstanceNumber, " (" + i + "):" + "\n name: " + cookies[i].getName() + "\n value: " + cookies[i].getValue() + "\n domain: " + cookies[i].getDomain() + "\n path: " + cookies[i].getPath() ); } } }
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() ); }