• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ClientCookie类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.http.cookie.ClientCookie的典型用法代码示例。如果您正苦于以下问题:Java ClientCookie类的具体用法?Java ClientCookie怎么用?Java ClientCookie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ClientCookie类属于org.apache.http.cookie包,在下文中一共展示了ClientCookie类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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.");
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:RFC2965PortAttributeHandler.java


示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:RFC2965PortAttributeHandler.java


示例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));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:NetscapeDraftSpec.java


示例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));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:BrowserCompatSpec.java


示例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));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:RFC2109Spec.java


示例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);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:RFC2109Spec.java


示例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;
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:22,代码来源:RFC2965PortAttributeHandlerHC4.java


示例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));
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:17,代码来源:NetscapeDraftSpecHC4.java


示例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));
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:19,代码来源:RFC2109SpecHC4.java


示例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);
        }
    }
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:26,代码来源:RFC2109SpecHC4.java


示例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;
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:21,代码来源:HC4CookieHandler.java


示例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.");
        }
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:20,代码来源:RFC2965PortAttributeHandler.java


示例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;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:RFC2965PortAttributeHandler.java


示例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);
        }
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:RFC2109Spec.java


示例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;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:24,代码来源:BasicDomainHandler.java


示例16: testBasicDomainMatch2

import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
@Test
public void testBasicDomainMatch2() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
    final CookieAttributeHandler h = new BasicDomainHandler();

    cookie.setDomain("somedomain.com");
    cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "somedomain.com");
    Assert.assertTrue(h.match(cookie, origin));

    cookie.setDomain(".somedomain.com");
    Assert.assertTrue(h.match(cookie, origin));

    cookie.setDomain(null);
    Assert.assertFalse(h.match(cookie, origin));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:17,代码来源:TestBasicCookieAttribHandlers.java


示例17: testFormatCookies

import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
@Test
public void testFormatCookies() throws Exception {
    final BasicClientCookie c1 = new BasicClientCookie("name1", "value1");
    c1.setDomain(".whatever.com");
    c1.setAttribute(ClientCookie.DOMAIN_ATTR, c1.getDomain());
    c1.setPath("/");
    c1.setAttribute(ClientCookie.PATH_ATTR, c1.getPath());

    final Cookie c2 = new BasicClientCookie("name2", "value2");
    final Cookie c3 = new BasicClientCookie("name3", null);

    final CookieSpec cookiespec = new NetscapeDraftSpec();
    final List<Cookie> cookies = new ArrayList<Cookie>();
    cookies.add(c1);
    cookies.add(c2);
    cookies.add(c3);
    final List<Header> headers = cookiespec.formatCookies(cookies);
    Assert.assertNotNull(headers);
    Assert.assertEquals(1, headers.size());
    Assert.assertEquals("name1=value1; name2=value2; name3", headers.get(0).getValue());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestCookieNetscapeDraft.java


示例18: testParsePort

import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
/**
 * Test parsing cookie {@code "Port"} attribute.
 */
@Test
public void testParsePort() throws Exception {
    final CookieSpec cookiespec = new RFC2965Spec();
    final CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
    final Header header = new BasicHeader("Set-Cookie2", "name=value;Port=\"80,800,8000\";Version=1;Port=nonsense");
    final List<Cookie> cookies = cookiespec.parse(header, origin);
    Assert.assertNotNull(cookies);
    Assert.assertEquals(1, cookies.size());
    // only the first occurrence of port attribute is considered, others ignored
    final ClientCookie cookie = (ClientCookie) cookies.get(0);
    final int[] ports = cookie.getPorts();
    Assert.assertNotNull(ports);
    Assert.assertEquals(3, ports.length);
    Assert.assertEquals(80, ports[0]);
    Assert.assertEquals(800, ports[1]);
    Assert.assertEquals(8000, ports[2]);
    Assert.assertTrue(cookie.containsAttribute(ClientCookie.PORT_ATTR));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestCookieRFC2965Spec.java


示例19: testParseNullPort

import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
@Test
public void testParseNullPort() throws Exception {
    final CookieSpec cookiespec = new RFC2965Spec();
    final CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
    // null port defaults to request port
    final Header header = new BasicHeader("Set-Cookie2", "name=value;Port=;Version=1");
    final List<Cookie> cookies = cookiespec.parse(header, origin);
    Assert.assertNotNull(cookies);
    Assert.assertEquals(1, cookies.size());
    final ClientCookie cookie = (ClientCookie) cookies.get(0);
    final int[] ports = cookie.getPorts();
    Assert.assertNotNull(ports);
    Assert.assertEquals(1, ports.length);
    Assert.assertEquals(80, ports[0]);
    Assert.assertEquals("", cookie.getAttribute(ClientCookie.PORT_ATTR));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:17,代码来源:TestCookieRFC2965Spec.java


示例20: testParseBlankPort

import org.apache.http.cookie.ClientCookie; //导入依赖的package包/类
@Test
public void testParseBlankPort() throws Exception {
    final CookieSpec cookiespec = new RFC2965Spec();
    final CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
    // blank port defaults to request port
    final Header header = new BasicHeader("Set-Cookie2", "name=value;Port=\"  \";Version=1");
    final List<Cookie> cookies = cookiespec.parse(header, origin);
    Assert.assertNotNull(cookies);
    Assert.assertEquals(1, cookies.size());
    final ClientCookie cookie = (ClientCookie) cookies.get(0);
    final int[] ports = cookie.getPorts();
    Assert.assertNotNull(ports);
    Assert.assertEquals(1, ports.length);
    Assert.assertEquals(80, ports[0]);
    Assert.assertEquals("  ", cookie.getAttribute(ClientCookie.PORT_ATTR));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:17,代码来源:TestCookieRFC2965Spec.java



注:本文中的org.apache.http.cookie.ClientCookie类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ArrowType类代码示例发布时间:2022-05-21
下一篇:
Java SlowCompositeReaderWrapper类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap