本文整理匯總了Java中org.apache.commons.httpclient.Cookie.setVersion方法的典型用法代碼示例。如果您正苦於以下問題:Java Cookie.setVersion方法的具體用法?Java Cookie.setVersion怎麽用?Java Cookie.setVersion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.httpclient.Cookie
的用法示例。
在下文中一共展示了Cookie.setVersion方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testValidateInvalidCookieVersion
import org.apache.commons.httpclient.Cookie; //導入方法依賴的package包/類
public void testValidateInvalidCookieVersion() throws Exception {
CookieSpec cookiespec = new CookieSpecBase();
Cookie cookie = new Cookie();
cookie.setVersion(-1);
try {
cookiespec.validate("host", 80, "/", false, cookie);
fail("MalformedCookieException must have been thrown");
} catch (MalformedCookieException expected) {
}
}
示例2: testNullCookieValueFormatting
import org.apache.commons.httpclient.Cookie; //導入方法依賴的package包/類
/**
* Tests if null cookie values are handled correctly.
*/
public void testNullCookieValueFormatting() {
Cookie cookie = new Cookie(".whatever.com", "name", null, "/", null, false);
cookie.setDomainAttributeSpecified(true);
cookie.setPathAttributeSpecified(true);
CookieSpec cookiespec = new RFC2109Spec();
String s = cookiespec.formatCookie(cookie);
assertEquals("$Version=0; name=; $Path=/; $Domain=.whatever.com", s);
cookie.setVersion(1);
s = cookiespec.formatCookie(cookie);
assertEquals("$Version=\"1\"; name=\"\"; $Path=\"/\"; $Domain=\".whatever.com\"", s);
}
示例3: parseAttribute
import org.apache.commons.httpclient.Cookie; //導入方法依賴的package包/類
/**
* Parse RFC 2109 specific cookie attribute and update the corresponsing
* {@link Cookie} properties.
*
* @param attribute {@link NameValuePair} cookie attribute from the
* <tt>Set- Cookie</tt>
* @param cookie {@link Cookie} to be updated
* @throws MalformedCookieException if an exception occurs during parsing
*/
public void parseAttribute(
final NameValuePair attribute, final Cookie cookie)
throws MalformedCookieException {
if (attribute == null) {
throw new IllegalArgumentException("Attribute may not be null.");
}
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null.");
}
final String paramName = attribute.getName().toLowerCase();
final String paramValue = attribute.getValue();
if (paramName.equals("path")) {
if (paramValue == null) {
throw new MalformedCookieException(
"Missing value for path attribute");
}
if (paramValue.trim().equals("")) {
throw new MalformedCookieException(
"Blank value for path attribute");
}
cookie.setPath(paramValue);
cookie.setPathAttributeSpecified(true);
} else if (paramName.equals("version")) {
if (paramValue == null) {
throw new MalformedCookieException(
"Missing value for version attribute");
}
try {
cookie.setVersion(Integer.parseInt(paramValue));
} catch (NumberFormatException e) {
throw new MalformedCookieException("Invalid version: "
+ e.getMessage());
}
} else {
super.parseAttribute(attribute, cookie);
}
}