use of org.apache.http.cookie.MalformedCookieException in project XobotOS by xamarin.
the class RFC2965PortAttributeHandler method parsePortAttribute.
/**
* 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;
}
use of org.apache.http.cookie.MalformedCookieException in project platform_external_apache-http by android.
the class NetscapeDomainHandler method validate.
@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");
}
}
}
}
use of org.apache.http.cookie.MalformedCookieException in project platform_external_apache-http by android.
the class NetscapeDraftSpec method parse.
/**
* Parses the Set-Cookie value into an array of <tt>Cookie</tt>s.
*
* <p>Syntax of the Set-Cookie HTTP Response Header:</p>
*
* <p>This is the format a CGI script would use to add to
* the HTTP headers a new piece of data which is to be stored by
* the client for later retrieval.</p>
*
* <PRE>
* Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secure
* </PRE>
*
* <p>Please note that Netscape draft specification does not fully
* conform to the HTTP header format. Netscape draft does not specify
* whether multiple cookies may be sent in one header. Hence, comma
* character may be present in unquoted cookie value or unquoted
* parameter value.</p>
*
* @see <a href="http://wp.netscape.com/newsref/std/cookie_spec.html">
* The Cookie Spec.</a>
*
* @param header the <tt>Set-Cookie</tt> received from the server
* @return an array of <tt>Cookie</tt>s parsed from the Set-Cookie value
* @throws MalformedCookieException if an exception occurs during parsing
*/
public List<Cookie> parse(final Header header, final CookieOrigin origin) throws MalformedCookieException {
if (header == null) {
throw new IllegalArgumentException("Header may not be null");
}
if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null");
}
NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
CharArrayBuffer buffer;
ParserCursor cursor;
if (header instanceof FormattedHeader) {
buffer = ((FormattedHeader) header).getBuffer();
cursor = new ParserCursor(((FormattedHeader) header).getValuePos(), buffer.length());
} else {
String s = header.getValue();
if (s == null) {
throw new MalformedCookieException("Header value is null");
}
buffer = new CharArrayBuffer(s.length());
buffer.append(s);
cursor = new ParserCursor(0, buffer.length());
}
return parse(new HeaderElement[] { parser.parseHeader(buffer, cursor) }, origin);
}
use of org.apache.http.cookie.MalformedCookieException in project platform_external_apache-http by android.
the class BasicMaxAgeHandler method parse.
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));
}
use of org.apache.http.cookie.MalformedCookieException in project platform_external_apache-http by android.
the class RFC2965PortAttributeHandler method parsePortAttribute.
/**
* 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;
}
Aggregations