本文整理汇总了Java中org.apache.http.cookie.Cookie.getDomain方法的典型用法代码示例。如果您正苦于以下问题:Java Cookie.getDomain方法的具体用法?Java Cookie.getDomain怎么用?Java Cookie.getDomain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.cookie.Cookie
的用法示例。
在下文中一共展示了Cookie.getDomain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveCookies
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
public void saveCookies(List<Cookie> cookies){
String strCookie = "";
Date sessionTime = null;
if (cookies != null && !cookies.isEmpty()) {
for (int i = 0; i < cookies.size(); i++) {
Cookie cookie = cookies.get(i);
if (cookie.getName().equalsIgnoreCase("JSESSIONID")){
strCookie += cookie.getName() + "="
+ cookie.getValue() + ";domain="
+cookie.getDomain();
sessionTime = cookies.get(i).getExpiryDate();
}
}
}
editor.putString("cookies", strCookie);
editor.commit();
editor.putString("cookiesExpiryDate", (sessionTime == null)?null:TimeUtil.getDTFormat().format(sessionTime));
editor.commit();
}
示例2: isForPublicSuffix
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
private boolean isForPublicSuffix(Cookie cookie) {
String domain = cookie.getDomain();
if (domain.startsWith(".")) domain = domain.substring(1);
domain = Punycode.toUnicode(domain);
// An exception rule takes priority over any other matching rule.
if (this.exceptions != null) {
if (this.exceptions.contains(domain)) return false;
}
if (this.suffixes == null) return false;
do {
if (this.suffixes.contains(domain)) return true;
// patterns
if (domain.startsWith("*.")) domain = domain.substring(2);
int nextdot = domain.indexOf('.');
if (nextdot == -1) break;
domain = "*" + domain.substring(nextdot);
} while (domain.length() > 0);
return false;
}
示例3: match
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
/**
* Match cookie domain attribute.
*/
public boolean match(final Cookie cookie, final CookieOrigin origin) {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");
}
if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null");
}
String host = origin.getHost().toLowerCase(Locale.ENGLISH);
String cookieDomain = cookie.getDomain();
// The effective host name MUST domain-match the Domain
// attribute of the cookie.
if (!domainMatch(host, cookieDomain)) {
return false;
}
// effective host name minus domain must not contain any dots
String effectiveHostWithoutDomain = host.substring(
0, host.length() - cookieDomain.length());
return effectiveHostWithoutDomain.indexOf('.') == -1;
}
示例4: validate
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
@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 CookieRestrictionViolationException("Domain attribute \""
+ domain
+ "\" violates the Netscape cookie specification for "
+ "special domains");
}
} else {
if (domainParts < 3) {
throw new CookieRestrictionViolationException("Domain attribute \""
+ domain
+ "\" violates the Netscape cookie specification");
}
}
}
}
示例5: formatCookieAsVer
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
/**
* 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 char array buffer to use for output
* @param cookie The {@link Cookie} to be formatted as string
* @param version The version to use.
*/
protected void formatCookieAsVer(final CharArrayBuffer buffer,
final Cookie cookie, int version) {
formatParamAsVer(buffer, cookie.getName(), cookie.getValue(), version);
if (cookie.getPath() != null) {
if (cookie instanceof ClientCookie
&& ((ClientCookie) cookie).containsAttribute(ClientCookie.PATH_ATTR)) {
buffer.append("; ");
formatParamAsVer(buffer, "$Path", cookie.getPath(), version);
}
}
if (cookie.getDomain() != null) {
if (cookie instanceof ClientCookie
&& ((ClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)) {
buffer.append("; ");
formatParamAsVer(buffer, "$Domain", cookie.getDomain(), version);
}
}
}
示例6: match
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
public boolean match(final Cookie cookie, final CookieOrigin origin) {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");
}
if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null");
}
String host = origin.getHost();
String domain = cookie.getDomain();
if (domain == null) {
return false;
}
if (host.equals(domain)) {
return true;
}
if (!domain.startsWith(".")) {
domain = '.' + domain;
}
return host.endsWith(domain) || host.equals(domain.substring(1));
}
示例7: addCookie
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
@Override
public void addCookie(Cookie cookie) {
String name = cookie.getName() + cookie.getDomain();
// Save cookie into local store, or remove if expired
if (!cookie.isExpired(new Date())) {
cookies.put(name, cookie);
} else {
cookies.remove(name);
}
// Save cookie into persistent store
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
prefsWriter.apply();
}
示例8: addCookie
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
@Override
public void addCookie(Cookie cookie) {
if (omitNonPersistentCookies && !cookie.isPersistent())
return;
String name = cookie.getName() + cookie.getDomain();
// Save cookie into local store, or remove if expired
if (!cookie.isExpired(new Date())) {
cookies.put(name, cookie);
} else {
cookies.remove(name);
}
// Save cookie into persistent store
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
prefsWriter.commit();
}
示例9: addCookie
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
public void addCookie(Cookie cookie) {
String name = cookie.getName() + cookie.getDomain();
if (cookie.isExpired(new Date())) {
this.cookies.remove(name);
} else {
this.cookies.put(name, cookie);
}
Editor prefsWriter = this.cookiePrefs.edit();
prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", this.cookies.keySet()));
prefsWriter.putString(new StringBuilder(COOKIE_NAME_PREFIX).append(name).toString(), encodeCookie(new SerializableCookie(cookie)));
prefsWriter.commit();
}
示例10: match
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
public boolean match(final Cookie cookie, final CookieOrigin origin) {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");
}
if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null");
}
String host = origin.getHost();
String domain = cookie.getDomain();
if (domain == null) {
return false;
}
return host.equals(domain) || (domain.startsWith(".") && host.endsWith(domain));
}
示例11: match
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
@Override
public boolean match(Cookie cookie, CookieOrigin origin) {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");
}
if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null");
}
String host = origin.getHost();
String domain = cookie.getDomain();
if (domain == null) {
return false;
}
return host.endsWith(domain);
}
示例12: addCookie
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
public void addCookie(Cookie cookie) {
if (!this.omitNonPersistentCookies || cookie.isPersistent()) {
String name = cookie.getName() + cookie.getDomain();
if (cookie.isExpired(new Date())) {
this.cookies.remove(name);
} else {
this.cookies.put(name, cookie);
}
Editor prefsWriter = this.cookiePrefs.edit();
prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", this.cookies.keySet()));
prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie
(cookie)));
prefsWriter.commit();
}
}
示例13: deleteCookie
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
public void deleteCookie(Cookie cookie) {
String name = cookie.getName() + cookie.getDomain();
this.cookies.remove(name);
Editor prefsWriter = this.cookiePrefs.edit();
prefsWriter.remove(COOKIE_NAME_PREFIX + name);
prefsWriter.commit();
}
示例14: deleteCookie
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
/**
* Non-standard helper method, to delete cookie
*
* @param cookie cookie to be removed
*/
public void deleteCookie(Cookie cookie) {
String name = cookie.getName() + cookie.getDomain();
cookies.remove(name);
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
prefsWriter.remove(COOKIE_NAME_PREFIX + name);
prefsWriter.commit();
}
示例15: validate
import org.apache.http.cookie.Cookie; //导入方法依赖的package包/类
/**
* Validate cookie domain attribute.
*/
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");
}
String host = origin.getHost().toLowerCase(Locale.ENGLISH);
if (cookie.getDomain() == null) {
throw new CookieRestrictionViolationException("Invalid cookie state: " +
"domain not specified");
}
String cookieDomain = cookie.getDomain().toLowerCase(Locale.ENGLISH);
if (cookie instanceof ClientCookie
&& ((ClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)) {
// Domain attribute must start with a dot
if (!cookieDomain.startsWith(".")) {
throw new CookieRestrictionViolationException("Domain attribute \"" +
cookie.getDomain() + "\" violates RFC 2109: domain must start with a dot");
}
// Domain attribute must contain at least one embedded dot,
// or the value must be equal to .local.
int dotIndex = cookieDomain.indexOf('.', 1);
if (((dotIndex < 0) || (dotIndex == cookieDomain.length() - 1))
&& (!cookieDomain.equals(".local"))) {
throw new CookieRestrictionViolationException(
"Domain attribute \"" + cookie.getDomain()
+ "\" violates RFC 2965: the value contains no embedded dots "
+ "and the value is not .local");
}
// The effective host name must domain-match domain attribute.
if (!domainMatch(host, cookieDomain)) {
throw new CookieRestrictionViolationException(
"Domain attribute \"" + cookie.getDomain()
+ "\" violates RFC 2965: effective host name does not "
+ "domain-match domain attribute.");
}
// effective host name minus domain must not contain any dots
String effectiveHostWithoutDomain = host.substring(
0, host.length() - cookieDomain.length());
if (effectiveHostWithoutDomain.indexOf('.') != -1) {
throw new CookieRestrictionViolationException("Domain attribute \""
+ cookie.getDomain() + "\" violates RFC 2965: "
+ "effective host minus domain may not contain any dots");
}
} else {
// Domain was not specified in header. In this case, domain must
// string match request host (case-insensitive).
if (!cookie.getDomain().equals(host)) {
throw new CookieRestrictionViolationException("Illegal domain attribute: \""
+ cookie.getDomain() + "\"."
+ "Domain of origin: \""
+ host + "\"");
}
}
}