Cookie cookie = new Cookie(host, headerelement.getName(), headerelement.getValue(),
/** * 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); } }
if (cookie.getDomain() == null) { LOG.warn("Invalid cookie state: domain not specified"); return false; if (cookie.getPath() == null) { LOG.warn("Invalid cookie state: path not specified"); return false; (cookie.getExpiryDate() == null || cookie.getExpiryDate().after(new Date())) && (domainMatch(host, cookie.getDomain())) && (pathMatch(path, cookie.getPath())) && (cookie.getSecure() ? secure : true);
/** * 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(); }
throw new IllegalArgumentException("Cookie name may not be blank"); this.setPath(path); this.setDomain(domain); this.setExpiryDate(expires); this.setSecure(secure);
/** * 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(); }
@Override public void addCookiesToClient(HttpClient client, Object cookiesObject, String policy, MuleEvent event, URI destinationUri) { Cookie[] cookies = (Cookie[]) cookiesObject; if (cookies != null && cookies.length > 0) { String host = destinationUri.getHost(); String path = destinationUri.getRawPath(); for (Cookie cookie : cookies) { client.getState().addCookie( new Cookie(host, cookie.getName(), cookie.getValue(), path, cookie.getExpiryDate(), cookie.getSecure())); } client.getParams().setCookiePolicy(CookieHelper.getCookiePolicy(policy)); } }
final String name = StringUtils.substringBefore(parts[0], "="); final String value = StringUtils.substringAfter(parts[0], "="); final Cookie cookie = new Cookie(getPage().getWebResponse().getRequestSettings().getUrl().getHost(), name, value); for (int i = 1; i < parts.length; i++) { final String partValue = StringUtils.substringAfter(parts[i], "=").trim(); if ("path".equals(partName)) { cookie.setPath(partValue); cookie.setExpiryDate(DateUtil.parseDate(partValue));
if (cookie.getVersion() < 0) { throw new MalformedCookieException ("Illegal version number " + cookie.getValue()); if (!host.endsWith(cookie.getDomain())) { String s = cookie.getDomain(); if (s.startsWith(".")) { s = s.substring(1, s.length()); "Illegal domain attribute \"" + cookie.getDomain() + "\". Domain of origin: \"" + host + "\""); if (!host.equals(cookie.getDomain())) { throw new MalformedCookieException( "Illegal domain attribute \"" + cookie.getDomain() + "\". Domain of origin: \"" + host + "\""); if (!path.startsWith(cookie.getPath())) { throw new MalformedCookieException( "Illegal path attribute \"" + cookie.getPath() + "\". Path of origin: \"" + path + "\"");
public Cookie createCookie() throws ParseException { Cookie cookie = new Cookie(); cookie.setName(getName()); cookie.setValue(getValue()); cookie.setDomain(domain); cookie.setPath(path); if(expiryDate != null) { cookie.setExpiryDate(formatExpiryDate(expiryDate)); } if(maxAge != null && expiryDate == null) { cookie.setExpiryDate(new Date(System.currentTimeMillis() + Integer.valueOf(maxAge) * 1000L)); } if(secure != null) { cookie.setSecure(Boolean.valueOf(secure)); } if(version != null) { cookie.setVersion(Integer.valueOf(version)); } return cookie; }
private org.apache.commons.httpclient.Cookie toHttpClientCookie(Cookie cookie) { org.apache.commons.httpclient.Cookie internal = new org.apache.commons.httpclient.Cookie(); internal.setName(cookie.getName()); internal.setValue(cookie.getValue()); internal.setComment(cookie.getComment()); internal.setDomain(cookie.getDomain()); // internal.setExpiryDate(toExpiry(cookie.getMaxAge())); internal.setPath(cookie.getPath()); internal.setVersion(cookie.getVersion()); return internal; }
/** * 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; } }
paramValue = "/"; cookie.setPath(paramValue); cookie.setPathAttributeSpecified(true); "Blank value for domain attribute"); cookie.setDomain(paramValue); cookie.setDomainAttributeSpecified(true); + "attribute: " + e.getMessage()); cookie.setExpiryDate( new Date(System.currentTimeMillis() + age * 1000L)); cookie.setSecure(true); cookie.setComment(paramValue); cookie.setExpiryDate(DateUtil.parseDate(paramValue, this.datepatterns)); } catch (DateParseException dpe) { LOG.debug("Error parsing cookie date", dpe);
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; }
if (cookie.getName().indexOf(' ') != -1) { throw new MalformedCookieException("Cookie name may not contain blanks"); if (cookie.getName().startsWith("$")) { throw new MalformedCookieException("Cookie name may not start with $"); if (cookie.isDomainAttributeSpecified() && (!cookie.getDomain().equals(host))) { if (!cookie.getDomain().startsWith(".")) { throw new MalformedCookieException("Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2109: domain must start with a dot"); int dotIndex = cookie.getDomain().indexOf('.', 1); if (dotIndex < 0 || dotIndex == cookie.getDomain().length() - 1) { throw new MalformedCookieException("Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2109: domain must contain an embedded dot"); if (!host.endsWith(cookie.getDomain())) { throw new MalformedCookieException( "Illegal domain attribute \"" + cookie.getDomain() + "\". Domain of origin: \"" + host + "\""); - cookie.getDomain().length()); if (hostWithoutDomain.indexOf('.') != -1) { throw new MalformedCookieException("Domain attribute \"" + cookie.getDomain()
private Cookie convertCookie(HttpCookie cookie) { Cookie c = new Cookie(cookie.getDomain(), cookie.getName(), cookie.getValue(), cookie.getPath(), (int) cookie.getMaxAge(), cookie.getSecure()); c.setVersion(cookie.getVersion()); c.setComment(cookie.getComment()); return c; }
@Override public void applyTo(OwnCloudClient client) { client.getParams().setAuthenticationPreemptive(false); client.getParams().setCredentialCharset(OwnCloudCredentialsFactory.CREDENTIAL_CHARSET); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); client.setFollowRedirects(false); Uri serverUri = client.getBaseUri(); String[] cookies = mSessionCookie.split(";"); if (cookies.length > 0) { Cookie cookie = null; for (int i=0; i<cookies.length; i++) { int equalPos = cookies[i].indexOf('='); if (equalPos >= 0) { cookie = new Cookie(); cookie.setName(cookies[i].substring(0, equalPos)); cookie.setValue(cookies[i].substring(equalPos + 1)); cookie.setDomain(serverUri.getHost()); // VERY IMPORTANT cookie.setPath(serverUri.getPath()); // VERY IMPORTANT client.getState().addCookie(cookie); } } } }