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

Java Cookie类代码示例

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

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



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

示例1: testGetCookie

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
@Test
public void testGetCookie() throws Exception {
    NewCookie cookie1 = ParsecHttpUtil.getCookie(new Cookie(
        "cookie1_name",
        "cookie1_value",
        false,
        null,
        "cookie1_path",
        1,
        true,
        true
    ));

    assertEquals("cookie1_name", cookie1.getName());
    assertEquals("cookie1_value", cookie1.getValue());
    assertEquals(null, cookie1.getDomain());
    assertEquals("cookie1_path", cookie1.getPath());
    assertEquals(null, cookie1.getExpiry());
    assertEquals(1, cookie1.getMaxAge());
    assertTrue(cookie1.isSecure());
    assertTrue(cookie1.isHttpOnly());
}
 
开发者ID:yahoo,项目名称:parsec-libraries,代码行数:23,代码来源:ParsecHttpUtilTest.java


示例2: recordCookie

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
protected void recordCookie(com.ning.http.client.Request httpRequest, Trace trace) {
    if (cookieSampler.isSampling()) {
        Collection<Cookie> cookies = httpRequest.getCookies();

        if (cookies.isEmpty()) {
            return;
        }

        StringBuilder sb = new StringBuilder(cookieDumpSize * 2);
        Iterator<Cookie> iterator = cookies.iterator();
        while (iterator.hasNext()) {
            Cookie cookie = iterator.next();
            sb.append(cookie.getName()).append("=").append(cookie.getValue());
            if (iterator.hasNext()) {
                sb.append(",");
            }
        }
        trace.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.drop(sb.toString(), cookieDumpSize));
    }
}
 
开发者ID:masonmei,项目名称:apm-agent,代码行数:21,代码来源:ExecuteRequestInterceptor.java


示例3: recordCookie

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
private void recordCookie(Request httpRequest, SpanEventRecorder recorder) {
    if (cookieSampler.isSampling()) {
        Collection<Cookie> cookies = httpRequest.getCookies();

        if (cookies.isEmpty()) {
            return;
        }

        StringBuilder sb = new StringBuilder(config.getCookieDumpSize() * 2);
        Iterator<Cookie> iterator = cookies.iterator();
        while (iterator.hasNext()) {
            Cookie cookie = iterator.next();
            sb.append(cookie.getName()).append('=').append(cookie.getValue());
            if (iterator.hasNext()) {
                sb.append(',');
            }
        }
        recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.abbreviate(sb.toString(), config.getCookieDumpSize()));
    }
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:21,代码来源:ExecuteRequestInterceptor.java


示例4: storeCookies

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
public void storeCookies(TestCase testCase, List<Cookie> cookieLst) {
	int simNumber = testCase.getSimulationNumber()==null?0:testCase.getSimulationNumber();
	if(testCase.isServerApiAuth() || testCase.isServerApiTarget()) {
		simNumber = -1;
	} else if(testCase.isExternalApi()) {
		simNumber = -2;
	} else if(testCase.getSimulationNumber()==null) {
		simNumber = 0;
	}
	if(cookieLst!=null && cookies.get(simNumber)!=null)
	{
		for (Cookie cookie : cookieLst) {
			if(cookie.getValue()!=null)
			{
				cookies.get(simNumber).put(cookie.getName(), cookie.getValue());
			}
		}
	}
}
 
开发者ID:sumeetchhetri,项目名称:gatf,代码行数:20,代码来源:WorkflowContextHandler.java


示例5: getCookie

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
/**
 * Get {@link NewCookie} from Ning {@link Cookie}.
 *
 * @param ningCookie Ning {@link Cookie}
 * @return {@link NewCookie}
 */
public static NewCookie getCookie(final Cookie ningCookie) {
    return new NewCookie(
        ningCookie.getName(),
        ningCookie.getValue(),
        ningCookie.getPath(),
        ningCookie.getDomain(),
        "",
        (int) ningCookie.getMaxAge(),
        ningCookie.isSecure(),
        ningCookie.isHttpOnly()
    );
}
 
开发者ID:yahoo,项目名称:parsec-libraries,代码行数:19,代码来源:ParsecHttpUtil.java


示例6: setCookies

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
private void setCookies(Collection<Cookie> cookies) {
    this.cookies.clear();

    if (cookies != null) {
        this.cookies.addAll(cookies);
    }
}
 
开发者ID:adamcin,项目名称:granite-client-packman,代码行数:8,代码来源:AsyncPackageManagerClient.java


示例7: addContext

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
private AsyncHttpClient.BoundRequestBuilder addContext(AsyncHttpClient.BoundRequestBuilder builder) {
    if (builder != null) {
        if (this.realm != null) {
            builder.setRealm(this.realm);
        }
        for (Cookie cookie : this.cookies) {
            builder.addCookie(cookie);
        }
    }
    return builder;
}
 
开发者ID:adamcin,项目名称:granite-client-packman,代码行数:12,代码来源:AsyncPackageManagerClient.java


示例8: setResponse

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
public void setResponse(String endpoint, Response response) throws IOException {

        Integer statusCode = response.getStatusCode();
        String httpResponse = response.getResponseBody();
        List<Cookie> cookies = response.getCookies();
        this.response = new HttpResponse(statusCode, httpResponse, cookies);
    }
 
开发者ID:Stratio,项目名称:bdt,代码行数:8,代码来源:CommonG.java


示例9: setDCOSCookie

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
public void setDCOSCookie(String DCOSsecret, String email) throws Exception {
    final JWTSigner signer = new JWTSigner(DCOSsecret);
    final HashMap<String, Object> claims = new HashMap();
    claims.put("uid", email);
    final String jwt = signer.sign(claims);
    Cookie cookie = new Cookie("dcos-acs-auth-cookie", jwt, false, "", "", 99999, false, false);
    List<Cookie> cookieList = new ArrayList<Cookie>();
    cookieList.add(cookie);
    commonspec.setCookies(cookieList);
}
 
开发者ID:Stratio,项目名称:bdt,代码行数:11,代码来源:GivenGSpec.java


示例10: setGoSecSSOCookie

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
/**
 * Generate token to authenticate in gosec SSO
 * @param ssoHost current sso host
 * @param userName username
 * @param passWord password
 * @throws Exception exception
 */
@Given("^I set sso token using host '(.+?)' with user '(.+?)' and password '(.+?)'$")
public void setGoSecSSOCookie(String ssoHost, String userName, String passWord) throws Exception {
    HashMap<String, String> ssoCookies = new GosecSSOUtils(ssoHost, userName, passWord).ssoTokenGenerator();
    String[] tokenList = {"user", "dcos-acs-auth-cookie"};
    List<Cookie> cookiesAtributes = addSsoToken(ssoCookies, tokenList);

    commonspec.setCookies(cookiesAtributes);
}
 
开发者ID:Stratio,项目名称:bdt,代码行数:16,代码来源:GivenGSpec.java


示例11: addSsoToken

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
public List<Cookie> addSsoToken(HashMap<String, String> ssoCookies, String[] tokenList) {
    List<Cookie> cookiesAttributes = new ArrayList<>();

    for (String tokenKey : tokenList) {
        cookiesAttributes.add(new Cookie(tokenKey, ssoCookies.get(tokenKey),
                false, null,
                null, 999999, false, false));
    }
    return cookiesAttributes;
}
 
开发者ID:Stratio,项目名称:bdt,代码行数:11,代码来源:GivenGSpec.java


示例12: getCookie

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
/**
 * Get only one cookie, using the cookie name.
 */
@Override
public Cookie getCookie(String name) {
    for (Cookie cookie : ahcResponse.getCookies()) {
        // safe -- cookie.getName() will never return null
        if (cookie.getName().equals(name)) {
            return cookie;
        }
    }
    return null;
}
 
开发者ID:mcoira,项目名称:async-rest-client,代码行数:14,代码来源:NingRestResponse.java


示例13: testOptionalCachingOnJSESSIONIDCookie

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
@Test
public void testOptionalCachingOnJSESSIONIDCookie() throws Exception {
    Map<String,String> filterInitParams = new HashMap<String,String>(1,1.0f) {{
        put(PublishToMemcachedFilter.MEMCACHED_KEY_PARAM,"$scheme$request_method$uri$args?$cookie_jsessionid?");
        put(PublishToMemcachedFilter.MEMCACHED_EXPIRY,"10");
    }};
    server.setupServlet3Filter("localhost:" + memcached.getPort(),null,filterInitParams);
    String url = server.setupServlet("/date/*","date","org.greencheek.web.filter.memcached.servlets.JSESSIONIDServlet",true);

    assertTrue(server.startTomcat());
    url = server.replacePort(url);
    Response response = executeGetRequest(url);
    assertEquals(CacheConfigGlobals.DEFAULT_CACHE_MISS_HEADER_VALUE,getCacheHeader(response));

    List<Cookie> cookies = response.getCookies();
    String sessionId = getSessionID(response);

    response = executeGetRequest(url,cookies);
    assertEquals(CacheConfigGlobals.DEFAULT_CACHE_MISS_HEADER_VALUE,getCacheHeader(response));

    response = executeGetRequest(url,cookies);
    assertEquals(CacheConfigGlobals.DEFAULT_CACHE_HIT_HEADER_VALUE,getCacheHeader(response));

    response = executeGetRequest(url);
    assertEquals(CacheConfigGlobals.DEFAULT_CACHE_HIT_HEADER_VALUE,getCacheHeader(response));
    assertEquals(sessionId, getSessionID(response));

    Cookie c = cookies.get(0);
    Cookie madeupJsessionId = new Cookie("JSESSIONID","xx","xx",c.getDomain(),c.getPath(),
            c.getExpires(),c.getMaxAge(),c.isSecure(),c.isHttpOnly());

    response = executeGetRequest(url, Collections.singletonList(madeupJsessionId));
    assertEquals(CacheConfigGlobals.DEFAULT_CACHE_MISS_HEADER_VALUE,getCacheHeader(response));
    assertNotEquals(sessionId, getSessionID(response));

}
 
开发者ID:tootedom,项目名称:tomcat-memcached-response-filter,代码行数:37,代码来源:TestFilterConfiguration.java


示例14: executeGetRequest

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
private Response executeGetRequest(String url,List<Cookie> cookies) throws Exception {
    AsyncHttpClient.BoundRequestBuilder rBuilder = server.getHttpClient().prepareGet(url);
    for(Cookie c : cookies) {
        rBuilder.addCookie(c);
    }
    Request r = rBuilder.build();
    return server.getHttpClient().executeRequest(r).get();
}
 
开发者ID:tootedom,项目名称:tomcat-memcached-response-filter,代码行数:9,代码来源:TestFilterConfiguration.java


示例15: getCookieString

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
private String getCookieString(Response response, String key) {
    for(Cookie c : response.getCookies()) {
        if(c.getName().equalsIgnoreCase(key)) {
            return c.getValue();
        }
    }
    return "";
}
 
开发者ID:tootedom,项目名称:tomcat-memcached-response-filter,代码行数:9,代码来源:TestFilterConfiguration.java


示例16: build

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
/**
 * Buile new {@link ParsecAsyncHttpRequest} instance.
 *
 * @return {@link ParsecAsyncHttpRequest}
 */
@SuppressWarnings("PMD.NPathComplexity")
public ParsecAsyncHttpRequest build() {
    ningRequestBuilder = new RequestBuilder(method)
        .setContentLength(contentLength)
        .setFollowRedirects(followRedirect)
        .setHeaders(headers)
        .setProxyServer(proxyServer)
        .setRangeOffset(rangeOffset)
        .setRequestTimeout(requestTimeout)
        .setVirtualHost(virtualHost)
        .setUri(new Uri(
            uri.getScheme(),
            uri.getUserInfo(),
            uri.getHost(),
            uri.getPort(),
            uri.getPath(),
            uri.getRawQuery()
    ));

    if (body != null) {
        ningRequestBuilder.setBody(body);
    } else if (byteBody != null) {
        ningRequestBuilder.setBody(byteBody);
    }

    if (bodyEncoding != null) {
        ningRequestBuilder.setBodyEncoding(bodyEncoding);
    }

    if (cookies != null && !cookies.isEmpty()) {
        for (NewCookie cookie : cookies) {
            ningRequestBuilder.addCookie(new Cookie(
                cookie.getName(),
                cookie.getValue(),
                false,
                cookie.getDomain(),
                cookie.getPath(),
                cookie.getMaxAge(),
                cookie.isSecure(),
                cookie.isHttpOnly()
            ));
        }
    }

    if (formParams != null) {
        ningRequestBuilder.setFormParams(formParams);
    }

    if (queryParams != null) {
        ningRequestBuilder.setQueryParams(queryParams);
    }

    if (acceptCompression && !headers.containsKey(ACCEPT_ENCODING_HEADER)) {
        ningRequestBuilder.addHeader(ACCEPT_ENCODING_HEADER, COMPRESSION_TYPE);
    }

    for (Part part: bodyParts) {
        ningRequestBuilder.addBodyPart(part);
    }

    return new ParsecAsyncHttpRequest(this);
}
 
开发者ID:yahoo,项目名称:parsec-libraries,代码行数:68,代码来源:ParsecAsyncHttpRequest.java


示例17: testGetCookies

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
@Test
public void testGetCookies() throws Exception {
    List<Cookie> ningCookies = new ArrayList<>();

    ningCookies.add(Cookie.newValidCookie(
        "cookie1_name",
        "cookie1_value",
        false,
        null,
        "cookie1_path",
        1,
        true,
        true
    ));

    ningCookies.add(Cookie.newValidCookie(
        "cookie2_name",
        "cookie2_value",
        false,
        null,
        "cookie2_path",
        2,
        false,
        false
    ));

    List<NewCookie> cookies = ParsecHttpUtil.getCookies(ningCookies);
    assertEquals(2, cookies.size());

    NewCookie cookie1 = cookies.get(0);
    assertEquals("cookie1_name", cookie1.getName());
    assertEquals("cookie1_value", cookie1.getValue());
    assertEquals(null, cookie1.getDomain());
    assertEquals("cookie1_path", cookie1.getPath());
    assertEquals(null, cookie1.getExpiry());
    assertEquals(1, cookie1.getMaxAge());
    assertTrue(cookie1.isSecure());
    assertTrue(cookie1.isHttpOnly());

    NewCookie cookie2 = cookies.get(1);
    assertEquals("cookie2_name", cookie2.getName());
    assertEquals("cookie2_value", cookie2.getValue());
    assertEquals(null, cookie2.getDomain());
    assertEquals("cookie2_path", cookie2.getPath());
    assertEquals(null, cookie2.getExpiry());
    assertEquals(2, cookie2.getMaxAge());
    assertFalse(cookie2.isSecure());
    assertFalse(cookie2.isHttpOnly());
}
 
开发者ID:yahoo,项目名称:parsec-libraries,代码行数:50,代码来源:ParsecHttpUtilTest.java


示例18: testGet

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
@Test
public void testGet() throws Exception {
    FluentCaseInsensitiveStringsMap responseHeaders = new FluentCaseInsensitiveStringsMap();

    responseHeaders.add("header1", "header1_value1");
    responseHeaders.add("header2", "header2_value1");

    List<Cookie> ningCookies = new ArrayList<>();

    ningCookies.add(new Cookie(
        "cookie1_name",
        "cookie1_value",
        false,
        null,
        "cookie1_path",
        1,
        true,
        true
    ));

    ningCookies.add(new Cookie(
        "cookie2_name",
        "cookie2_value",
        false,
        null,
        "cookie2_path",
        2,
        false,
        false
    ));

    when(mockNingResponse.getHeaders()).thenReturn(responseHeaders);
    when(mockNingResponse.getContentType()).thenReturn(MediaType.APPLICATION_JSON);
    when(mockNingResponse.getCookies()).thenReturn(ningCookies);
    when(mockNingResponse.getStatusCode()).thenReturn(200);
    when(mockNingResponse.hasResponseHeaders()).thenReturn(true);

    when(mockNingFuture.get()).thenReturn(mockNingResponse);
    when(mockNingFuture.get(anyLong(), any(TimeUnit.class))).thenReturn(mockNingResponse);

    ParsecCompletableFuture<Response> future = new ParsecCompletableFuture<>(mockNingFuture);
    Response response = future.get();

    assertEquals(response.getContentType(), MediaType.APPLICATION_JSON);
    assertEquals(response.getHeaders().size(), 2);

    response = future.get(3, TimeUnit.SECONDS);

    assertEquals(response.getContentType(), MediaType.APPLICATION_JSON);
    assertEquals(response.getHeaders().size(), 2);
}
 
开发者ID:yahoo,项目名称:parsec-libraries,代码行数:52,代码来源:ParsecCompletableFutureTest.java


示例19: getCookies

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
public List<Cookie> getCookies() {
    return cookies;
}
 
开发者ID:Stratio,项目名称:bdt,代码行数:4,代码来源:HttpResponse.java


示例20: setCookies

import com.ning.http.client.cookie.Cookie; //导入依赖的package包/类
public void setCookies(List<Cookie> cookies) {
    this.cookies = cookies;
}
 
开发者ID:Stratio,项目名称:bdt,代码行数:4,代码来源:HttpResponse.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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