public void parse(final SetCookie cookie, final String value) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (value == null) { throw new MalformedCookieException("Missing value for domain attribute"); } if (value.trim().length() == 0) { throw new MalformedCookieException("Blank value for domain attribute"); } cookie.setDomain(value); }
public void parse(final SetCookie cookie, final String value) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (value == null) { throw new MalformedCookieException("Missing value for domain attribute"); } if (value.trim().length() == 0) { throw new MalformedCookieException("Blank value for domain attribute"); } cookie.setDomain(value); }
public void parse(final SetCookie cookie, final String value) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (value == null) { throw new MalformedCookieException("Missing value for version attribute"); } if (value.trim().length() == 0) { throw new MalformedCookieException("Blank value for version attribute"); } try { cookie.setVersion(Integer.parseInt(value)); } catch (NumberFormatException e) { throw new MalformedCookieException("Invalid version: " + e.getMessage()); } }
@Override public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (cookie.getVersion() < 0) { throw new MalformedCookieException("Cookie version may not be negative"); } }
public void parse(final SetCookie cookie, final String value) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (value == null) { throw new MalformedCookieException("Missing value for max-age attribute"); } int age; try { age = Integer.parseInt(value); } catch (NumberFormatException e) { throw new MalformedCookieException ("Invalid max-age attribute: " + value); } if (age < 0) { throw new MalformedCookieException ("Negative max-age attribute: " + value); } cookie.setExpiryDate(new Date(System.currentTimeMillis() + age * 1000L)); }
/** * Parse cookie version attribute. */ public void parse(final SetCookie cookie, final String value) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (value == null) { throw new MalformedCookieException( "Missing value for version attribute"); } int version = -1; try { version = Integer.parseInt(value); } catch (NumberFormatException e) { version = -1; } if (version < 0) { throw new MalformedCookieException("Invalid cookie version."); } cookie.setVersion(version); }
@Override public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } String name = cookie.getName(); if (name.indexOf(' ') != -1) { throw new MalformedCookieException("Cookie name may not contain blanks"); } if (name.startsWith("$")) { throw new MalformedCookieException("Cookie name may not start with $"); } super.validate(cookie, origin); }
public void parse(final SetCookie cookie, final String value) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (value == null) { throw new MalformedCookieException("Missing value for expires attribute"); } try { cookie.setExpiryDate(DateUtils.parseDate(value, this.datepatterns)); } catch (DateParseException dpe) { throw new MalformedCookieException("Unable to parse expires attribute: " + value); } }
/** * Parses the given Port attribute value (e.g. "8000,8001,8002") * into an array of ports. * * @param portValue port attribute value * @return parsed array of ports * @throws MalformedCookieException if there is a problem in * parsing due to invalid portValue. */ private static int[] parsePortAttribute(final String portValue) throws MalformedCookieException { StringTokenizer st = new StringTokenizer(portValue, ","); int[] ports = new int[st.countTokens()]; try { int i = 0; while(st.hasMoreTokens()) { ports[i] = Integer.parseInt(st.nextToken().trim()); if (ports[i] < 0) { throw new MalformedCookieException ("Invalid Port attribute."); } ++i; } } catch (NumberFormatException e) { throw new MalformedCookieException ("Invalid Port " + "attribute: " + e.getMessage()); } return ports; }
/** * validate cookie version attribute. Version attribute is REQUIRED. */ public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (cookie instanceof SetCookie2) { if (cookie instanceof ClientCookie && !((ClientCookie) cookie).containsAttribute(ClientCookie.VERSION_ATTR)) { throw new MalformedCookieException( "Violates RFC 2965. Version attribute is required."); } } }
/** * Parse cookie domain attribute. */ public void parse(final SetCookie cookie, String domain) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (domain == null) { throw new MalformedCookieException( "Missing value for domain attribute"); } if (domain.trim().length() == 0) { throw new MalformedCookieException( "Blank value for domain attribute"); } domain = domain.toLowerCase(Locale.ENGLISH); if (!domain.startsWith(".")) { // Per RFC 2965 section 3.2.2 // "... If an explicitly specified value does not start with // a dot, the user agent supplies a leading dot ..." // That effectively implies that the domain attribute // MAY NOT be an IP address of a host name domain = '.' + domain; } cookie.setDomain(domain); }
String domain = cookie.getDomain(); if (domain == null) { throw new MalformedCookieException("Cookie domain may not be null"); throw new MalformedCookieException("Domain attribute \"" + domain + "\" does not match the host \"" throw new MalformedCookieException("Domain attribute \"" + domain + "\" violates RFC 2109: domain must start with a dot"); throw new MalformedCookieException("Domain attribute \"" + domain + "\" violates RFC 2109: domain must contain an embedded dot"); throw new MalformedCookieException( "Illegal domain attribute \"" + domain + "\". Domain of origin: \"" + host + "\""); throw new MalformedCookieException("Domain attribute \"" + domain + "\" violates RFC 2109: host minus domain may not contain any dots");
String domain = cookie.getDomain(); if (domain == null) { throw new MalformedCookieException("Cookie domain may not be null"); throw new MalformedCookieException( "Illegal domain attribute \"" + domain + "\". Domain of origin: \"" + host + "\""); throw new MalformedCookieException( "Illegal domain attribute \"" + domain + "\". Domain of origin: \"" + host + "\"");
@Override public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { super.validate(cookie, origin); // Perform Netscape Cookie draft specific validation String host = origin.getHost(); String domain = cookie.getDomain(); if (host.contains(".")) { int domainParts = new StringTokenizer(domain, ".").countTokens(); if (isSpecialDomain(domain)) { if (domainParts < 2) { throw new MalformedCookieException("Domain attribute \"" + domain + "\" violates the Netscape cookie specification for " + "special domains"); } } else { if (domainParts < 3) { throw new MalformedCookieException("Domain attribute \"" + domain + "\" violates the Netscape cookie specification"); } } } }
public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (!match(cookie, origin)) { throw new MalformedCookieException( "Illegal path attribute \"" + cookie.getPath() + "\". Path of origin: \"" + origin.getPath() + "\""); } }
/** * Validate cookie port attribute. If the Port attribute was specified * in header, the request port must be in cookie's port list. */ public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (origin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } int port = origin.getPort(); if (cookie instanceof ClientCookie && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) { if (!portMatch(port, cookie.getPorts())) { throw new MalformedCookieException( "Port attribute violates RFC 2965: " + "Request port not found in cookie's port list."); } } }
String value = headerelement.getValue(); if (name == null || name.length() == 0) { throw new MalformedCookieException("Cookie name may not be empty");
protected List<Cookie> parse(final HeaderElement[] elems, final CookieOrigin origin) throws MalformedCookieException { List<Cookie> cookies = new ArrayList<Cookie>(elems.length); for (HeaderElement headerelement : elems) { String name = headerelement.getName(); String value = headerelement.getValue(); if (name == null || name.length() == 0) { throw new MalformedCookieException("Cookie name may not be empty"); } BasicClientCookie cookie = new BasicClientCookie(name, value); cookie.setPath(getDefaultPath(origin)); cookie.setDomain(getDefaultDomain(origin)); // cycle through the parameters NameValuePair[] attribs = headerelement.getParameters(); for (int j = attribs.length - 1; j >= 0; j--) { NameValuePair attrib = attribs[j]; String s = attrib.getName().toLowerCase(Locale.ENGLISH); cookie.setAttribute(s, attrib.getValue()); CookieAttributeHandler handler = findAttribHandler(s); if (handler != null) { handler.parse(cookie, attrib.getValue()); } } cookies.add(cookie); } return cookies; }
String s = header.getValue(); if (s == null) { throw new MalformedCookieException("Header value is null");
String s = header.getValue(); if (s == null) { throw new MalformedCookieException("Header value is null");