本文整理汇总了Java中org.apache.http.cookie.ClientCookie类的典型用法代码示例。如果您正苦于以下问题:Java ClientCookie类的具体用法?Java ClientCookie怎么用?Java ClientCookie使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClientCookie类属于org.apache.http.cookie包,在下文中一共展示了ClientCookie类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
/**
* 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 CookieRestrictionViolationException(
"Port attribute violates RFC 2965: "
+ "Request port not found in cookie's port list.");
}
}
}
示例2: match
import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
/**
* Match cookie port attribute. If the Port attribute is not specified
* in header, the cookie can be sent to any port. Otherwise, the request port
* must be in the cookie's port list.
*/
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");
}
int port = origin.getPort();
if (cookie instanceof ClientCookie
&& ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
if (cookie.getPorts() == null) {
// Invalid cookie state: port not specified
return false;
}
if (!portMatch(port, cookie.getPorts())) {
return false;
}
}
return true;
}
示例3: NetscapeDraftSpec
import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
/** Default constructor */
public NetscapeDraftSpec(final String[] datepatterns) {
super();
if (datepatterns != null) {
this.datepatterns = datepatterns.clone();
} else {
this.datepatterns = new String[] { EXPIRES_PATTERN };
}
registerAttribHandler(ClientCookie.PATH_ATTR, new BasicPathHandler());
registerAttribHandler(ClientCookie.DOMAIN_ATTR, new NetscapeDomainHandler());
registerAttribHandler(ClientCookie.MAX_AGE_ATTR, new BasicMaxAgeHandler());
registerAttribHandler(ClientCookie.SECURE_ATTR, new BasicSecureHandler());
registerAttribHandler(ClientCookie.COMMENT_ATTR, new BasicCommentHandler());
registerAttribHandler(ClientCookie.EXPIRES_ATTR, new BasicExpiresHandler(
this.datepatterns));
}
示例4: BrowserCompatSpec
import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
/** Default constructor */
public BrowserCompatSpec(final String[] datepatterns) {
super();
if (datepatterns != null) {
this.datepatterns = datepatterns.clone();
} else {
this.datepatterns = DEFAULT_DATE_PATTERNS;
}
registerAttribHandler(ClientCookie.PATH_ATTR, new BasicPathHandler());
registerAttribHandler(ClientCookie.DOMAIN_ATTR, new BasicDomainHandler());
registerAttribHandler(ClientCookie.MAX_AGE_ATTR, new BasicMaxAgeHandler());
registerAttribHandler(ClientCookie.SECURE_ATTR, new BasicSecureHandler());
registerAttribHandler(ClientCookie.COMMENT_ATTR, new BasicCommentHandler());
registerAttribHandler(ClientCookie.EXPIRES_ATTR, new BasicExpiresHandler(
this.datepatterns));
}
示例5: RFC2109Spec
import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
/** Default constructor */
public RFC2109Spec(final String[] datepatterns, boolean oneHeader) {
super();
if (datepatterns != null) {
this.datepatterns = datepatterns.clone();
} else {
this.datepatterns = DATE_PATTERNS;
}
this.oneHeader = oneHeader;
registerAttribHandler(ClientCookie.VERSION_ATTR, new RFC2109VersionHandler());
registerAttribHandler(ClientCookie.PATH_ATTR, new BasicPathHandler());
registerAttribHandler(ClientCookie.DOMAIN_ATTR, new RFC2109DomainHandler());
registerAttribHandler(ClientCookie.MAX_AGE_ATTR, new BasicMaxAgeHandler());
registerAttribHandler(ClientCookie.SECURE_ATTR, new BasicSecureHandler());
registerAttribHandler(ClientCookie.COMMENT_ATTR, new BasicCommentHandler());
registerAttribHandler(ClientCookie.EXPIRES_ATTR, new BasicExpiresHandler(
this.datepatterns));
}
示例6: formatCookieAsVer
import org.apache.http.cookie.ClientCookie; //导入依赖的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);
}
}
}
示例7: match
import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
/**
* Match cookie port attribute. If the Port attribute is not specified
* in header, the cookie can be sent to any port. Otherwise, the request port
* must be in the cookie's port list.
*/
public boolean match(final Cookie cookie, final CookieOrigin origin) {
Args.notNull(cookie, "Cookie");
Args.notNull(origin, "Cookie origin");
final int port = origin.getPort();
if (cookie instanceof ClientCookie
&& ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
if (cookie.getPorts() == null) {
// Invalid cookie state: port not specified
return false;
}
if (!portMatch(port, cookie.getPorts())) {
return false;
}
}
return true;
}
示例8: NetscapeDraftSpecHC4
import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
/** Default constructor */
public NetscapeDraftSpecHC4(final String[] datepatterns) {
super();
if (datepatterns != null) {
this.datepatterns = datepatterns.clone();
} else {
this.datepatterns = new String[] { EXPIRES_PATTERN };
}
registerAttribHandler(ClientCookie.PATH_ATTR, new BasicPathHandlerHC4());
registerAttribHandler(ClientCookie.DOMAIN_ATTR, new NetscapeDomainHandlerHC4());
registerAttribHandler(ClientCookie.MAX_AGE_ATTR, new BasicMaxAgeHandlerHC4());
registerAttribHandler(ClientCookie.SECURE_ATTR, new BasicSecureHandlerHC4());
registerAttribHandler(ClientCookie.COMMENT_ATTR, new BasicCommentHandlerHC4());
registerAttribHandler(ClientCookie.EXPIRES_ATTR, new BasicExpiresHandlerHC4(
this.datepatterns));
}
示例9: RFC2109SpecHC4
import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
/** Default constructor */
public RFC2109SpecHC4(final String[] datepatterns, final boolean oneHeader) {
super();
if (datepatterns != null) {
this.datepatterns = datepatterns.clone();
} else {
this.datepatterns = DATE_PATTERNS;
}
this.oneHeader = oneHeader;
registerAttribHandler(ClientCookie.VERSION_ATTR, new RFC2109VersionHandlerHC4());
registerAttribHandler(ClientCookie.PATH_ATTR, new BasicPathHandlerHC4());
registerAttribHandler(ClientCookie.DOMAIN_ATTR, new RFC2109DomainHandlerHC4());
registerAttribHandler(ClientCookie.MAX_AGE_ATTR, new BasicMaxAgeHandlerHC4());
registerAttribHandler(ClientCookie.SECURE_ATTR, new BasicSecureHandlerHC4());
registerAttribHandler(ClientCookie.COMMENT_ATTR, new BasicCommentHandlerHC4());
registerAttribHandler(ClientCookie.EXPIRES_ATTR, new BasicExpiresHandlerHC4(
this.datepatterns));
}
示例10: formatCookieAsVer
import org.apache.http.cookie.ClientCookie; //导入依赖的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, final 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);
}
}
}
示例11: makeCookie
import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
/**
* Create an HttpClient cookie from a JMeter cookie
*/
private org.apache.http.cookie.Cookie makeCookie(Cookie jmc) {
long exp = jmc.getExpiresMillis();
BasicClientCookie ret = new BasicClientCookie(jmc.getName(),
jmc.getValue());
ret.setDomain(jmc.getDomain());
ret.setPath(jmc.getPath());
ret.setExpiryDate(exp > 0 ? new Date(exp) : null); // use null for no expiry
ret.setSecure(jmc.getSecure());
ret.setVersion(jmc.getVersion());
if(jmc.isDomainSpecified()) {
ret.setAttribute(ClientCookie.DOMAIN_ATTR, jmc.getDomain());
}
if(jmc.isPathSpecified()) {
ret.setAttribute(ClientCookie.PATH_ATTR, jmc.getPath());
}
return ret;
}
示例12: validate
import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
/**
* Validate cookie port attribute. If the Port attribute was specified
* in header, the request port must be in cookie's port list.
*/
@Override
public void validate(final Cookie cookie, final CookieOrigin origin)
throws MalformedCookieException {
Args.notNull(cookie, "Cookie");
Args.notNull(origin, "Cookie origin");
final int port = origin.getPort();
if (cookie instanceof ClientCookie
&& ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
if (!portMatch(port, cookie.getPorts())) {
throw new CookieRestrictionViolationException(
"Port attribute violates RFC 2965: "
+ "Request port not found in cookie's port list.");
}
}
}
示例13: match
import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
/**
* Match cookie port attribute. If the Port attribute is not specified
* in header, the cookie can be sent to any port. Otherwise, the request port
* must be in the cookie's port list.
*/
@Override
public boolean match(final Cookie cookie, final CookieOrigin origin) {
Args.notNull(cookie, "Cookie");
Args.notNull(origin, "Cookie origin");
final int port = origin.getPort();
if (cookie instanceof ClientCookie
&& ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
if (cookie.getPorts() == null) {
// Invalid cookie state: port not specified
return false;
}
if (!portMatch(port, cookie.getPorts())) {
return false;
}
}
return true;
}
示例14: formatCookieAsVer
import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
/**
* Return a string suitable for sending in a {@code "Cookie"} 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, final 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);
}
}
}
示例15: match
import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
@Override
public boolean match(final Cookie cookie, final CookieOrigin origin) {
Args.notNull(cookie, "Cookie");
Args.notNull(origin, "Cookie origin");
final String host = origin.getHost();
String domain = cookie.getDomain();
if (domain == null) {
return false;
}
if (domain.startsWith(".")) {
domain = domain.substring(1);
}
domain = domain.toLowerCase(Locale.ROOT);
if (host.equals(domain)) {
return true;
}
if (cookie instanceof ClientCookie) {
if (((ClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)) {
return domainMatch(domain, host);
}
}
return false;
}