当前位置: 首页>>代码示例>>Java>>正文


Java BasicClientCookie2类代码示例

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


BasicClientCookie2类属于org.apache.http.impl.cookie包,在下文中一共展示了BasicClientCookie2类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addCookie

import org.apache.http.impl.cookie.BasicClientCookie2; //导入依赖的package包/类
/**
 * Adds an {@link Cookie HTTP cookie}, replacing any existing equivalent cookies.
 * If the given cookie has already expired it will not be added, but existing
 * values will still be removed.
 *
 * @param cookie the {@link Cookie cookie} to be added
 * @see #addCookies(Cookie[])
 */
@Override
public synchronized void addCookie(final Cookie cookie) {
    if (cookie != null) {
        // first remove any old cookie that is equivalent
        cookies.remove(cookie);
        Date now = new Date();
        if (!cookie.isExpired(now)) {
            Date targetExpiryDate = new Date(System.currentTimeMillis() + maxExpiresMillis);
            if (!cookie.isExpired(targetExpiryDate)) {
                try {
                    if (cookie instanceof BasicClientCookie) {
                        ((BasicClientCookie) cookie).setExpiryDate(targetExpiryDate);
                    } else if (cookie instanceof BasicClientCookie2) {
                        ((BasicClientCookie2) cookie).setExpiryDate(targetExpiryDate);
                    }
                } catch (Exception e) {
                }
            }

            cookies.add(cookie);
        }
    }
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:32,代码来源:BarrierCookieStore.java

示例2: setUp

import org.apache.http.impl.cookie.BasicClientCookie2; //导入依赖的package包/类
@Before
public void setUp() {
    this.target = new HttpHost("localhost.local", 80);
    this.cookieStore = new BasicCookieStore();
    final BasicClientCookie2 cookie1 = new BasicClientCookie2("name1", "value1");
    cookie1.setVersion(1);
    cookie1.setDomain("localhost.local");
    cookie1.setPath("/");
    this.cookieStore.addCookie(cookie1);
    final BasicClientCookie2 cookie2 = new BasicClientCookie2("name2", "value2");
    cookie2.setVersion(1);
    cookie2.setDomain("localhost.local");
    cookie2.setPath("/");
    this.cookieStore.addCookie(cookie2);

    this.cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create()
        .register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider())
        .register(CookieSpecs.STANDARD, new RFC2965SpecProvider())
        .register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider())
        .register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider())
        .build();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestRequestAddCookies.java

示例3: toApacheCookie

import org.apache.http.impl.cookie.BasicClientCookie2; //导入依赖的package包/类
public Cookie toApacheCookie() {
	BasicClientCookie2 cookie = new BasicClientCookie2(name, value);
	
	cookie.setComment(cookieComment);
	cookie.setDomain(cookieDomain);
	cookie.setExpiryDate(cookieExpiryDate);
	cookie.setPath(cookiePath);
	cookie.setSecure(isSecure);
	cookie.setVersion(cookieVersion);
	cookie.setPorts(ports);
	
	// copy over attributes
	/*
	for(Entry<String, String> entry : attribs.entrySet()) {
		cookie.setAttribute(entry.getKey(), entry.getValue());
	}*/
	
	return cookie;
}
 
开发者ID:ltrr-arizona-edu,项目名称:tellervo,代码行数:20,代码来源:WSCookieWrapper.java

示例4: testExcludeExpiredCookies

import org.apache.http.impl.cookie.BasicClientCookie2; //导入依赖的package包/类
@Test
public void testExcludeExpiredCookies() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", "/");

    final BasicClientCookie2 cookie3 = new BasicClientCookie2("name3", "value3");
    cookie3.setVersion(1);
    cookie3.setDomain("localhost.local");
    cookie3.setPath("/");
    cookie3.setExpiryDate(new Date(System.currentTimeMillis() + 100));
    this.cookieStore.addCookie(cookie3);

    Assert.assertEquals(3, this.cookieStore.getCookies().size());

    this.cookieStore = Mockito.spy(this.cookieStore);

    final HttpRoute route = new HttpRoute(this.target, null, false);

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
    context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
    context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);

    // Make sure the third cookie expires
    Thread.sleep(200);

    final HttpRequestInterceptor interceptor = new RequestAddCookies();
    interceptor.process(request, context);

    final Header[] headers1 = request.getHeaders(SM.COOKIE);
    Assert.assertNotNull(headers1);
    Assert.assertEquals(2, headers1.length);
    Assert.assertEquals("$Version=1; name1=\"value1\"", headers1[0].getValue());
    Assert.assertEquals("$Version=1; name2=\"value2\"", headers1[1].getValue());
    final Header[] headers2 = request.getHeaders(SM.COOKIE2);
    Assert.assertNotNull(headers2);
    Assert.assertEquals(0, headers2.length);

    Mockito.verify(this.cookieStore, Mockito.times(1)).clearExpired(Mockito.<Date>any());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:41,代码来源:TestRequestAddCookies.java

示例5: Cookie

import org.apache.http.impl.cookie.BasicClientCookie2; //导入依赖的package包/类
public Cookie(String name, String value) {
	this.httpCookie = new BasicClientCookie2(name, value);
}
 
开发者ID:Coffeeboys,项目名称:RenewPass,代码行数:4,代码来源:Cookie.java

示例6: isRepresentingBasicClientCookie2

import org.apache.http.impl.cookie.BasicClientCookie2; //导入依赖的package包/类
public boolean isRepresentingBasicClientCookie2() {
	return httpCookie instanceof BasicClientCookie2;
}
 
开发者ID:Coffeeboys,项目名称:RenewPass,代码行数:4,代码来源:Cookie.java

示例7: getHttpCookieAsBasicClientCookie2

import org.apache.http.impl.cookie.BasicClientCookie2; //导入依赖的package包/类
public BasicClientCookie2 getHttpCookieAsBasicClientCookie2() {
	return (BasicClientCookie2)httpCookie;
}
 
开发者ID:Coffeeboys,项目名称:RenewPass,代码行数:4,代码来源:Cookie.java

示例8: setCookieLocale

import org.apache.http.impl.cookie.BasicClientCookie2; //导入依赖的package包/类
/**
 * Set the cookie locale to en_US.
 */
private void setCookieLocale(){
    cookieStore.addCookie(new BasicClientCookie2("box_locale", "en_US"));
    cookieStore.addCookie(new BasicClientCookie2("country", "US"));
    cookieStore.addCookie(new BasicClientCookie2("lang", "en-US"));
}
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:9,代码来源:BoxDotComAccount.java

示例9: loadCookies

import org.apache.http.impl.cookie.BasicClientCookie2; //导入依赖的package包/类
@Override
protected List<Cookie> loadCookies() {
	final List<Cookie> list = new LinkedList<Cookie>();
	final Cursor cursor = myDatabase.rawQuery(
		"SELECT cookie_id,host,path,name,value,date_of_expiration,secure FROM Cookie", null
	);
	while (cursor.moveToNext()) {
		final long id = cursor.getLong(0);
		final String host = cursor.getString(1);
		final String path = cursor.getString(2);
		final String name = cursor.getString(3);
		final String value = cursor.getString(4);
		final Date date = SQLiteUtil.getDate(cursor, 5);
		final boolean secure = cursor.getLong(6) == 1;
		Set<Integer> portSet = null;
		final Cursor portsCursor = myDatabase.rawQuery(
			"SELECT port FROM CookiePort WHERE cookie_id = " + id, null
		);
		while (portsCursor.moveToNext()) {
			if (portSet == null) {
				portSet = new HashSet<Integer>();
			}
			portSet.add((int)portsCursor.getLong(1));
		}
		portsCursor.close();
		final BasicClientCookie2 c = new BasicClientCookie2(name, value);
		c.setDomain(host);
		c.setPath(path);
		if (portSet != null) {
			final int ports[] = new int[portSet.size()];
			int index = 0;
			for (int p : portSet) {
				ports[index] = p;
				++index;
			}
			c.setPorts(ports);
		}
		c.setExpiryDate(date);
		c.setSecure(secure);
		c.setDiscard(false);
		list.add(c);
	}
	cursor.close();
	return list;
}
 
开发者ID:liufeiit,项目名称:itmarry,代码行数:46,代码来源:SQLiteCookieDatabase.java


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