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


Java DefaultCookie类代码示例

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


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

示例1: realWriteAndFlush

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
public static void realWriteAndFlush(Channel channel, String text, String contentType, boolean keepalive, DefaultCookie nettyCookie) {
    FullHttpResponse response = new DefaultFullHttpResponse(
            HttpVersion.HTTP_1_1,
            HttpResponseStatus.OK,
            Unpooled.copiedBuffer(text + "\r\n", CharsetUtil.UTF_8));

    HttpUtil.setContentLength(response, text.length());
    response.headers().set(HttpHeaderNames.CONTENT_TYPE, contentType);
    setDateAndCacheHeaders(response, null);
    if (keepalive) {
        response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
    }

    if (nettyCookie != null) {
        response.headers().set(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(nettyCookie));
    }
    // Write the initial line and the header.
    channel.write(response);
    channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
}
 
开发者ID:jwboardman,项目名称:whirlpool,代码行数:21,代码来源:WebSocketHelper.java

示例2: getCookies_returns_cookies_from_requestInfo

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
@Test
public void getCookies_returns_cookies_from_requestInfo() {
    // given
    Set<io.netty.handler.codec.http.cookie.Cookie> nettyCookies = new LinkedHashSet<>(Arrays.asList(
        new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString()),
        new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString())
    ));
    doReturn(nettyCookies).when(requestInfoMock).getCookies();

    List<Cookie> expectedCookieList = nettyCookies
        .stream().map(nc -> new Cookie(nc.name(), nc.value())).collect(Collectors.toList());

    // when
    Cookie[] result = wrapper.getCookies();

    // then
    for (int i = 0; i < result.length; i++) {
        Cookie expected = expectedCookieList.get(i);
        Cookie actual = result[i];
        assertThat(actual.getName()).isEqualTo(expected.getName());
        assertThat(actual.getValue()).isEqualTo(expected.getValue());
    }
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:24,代码来源:HttpServletRequestWrapperForRequestInfoTest.java

示例3: uber_constructor_for_full_response_sets_fields_as_expected

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
@Test
public void uber_constructor_for_full_response_sets_fields_as_expected() {
    // given
    int httpStatusCode = 200;
    HttpHeaders headers = new DefaultHttpHeaders();
    String mimeType = "text/text";
    Charset contentCharset = CharsetUtil.UTF_8;
    Set<Cookie> cookies = Sets.newHashSet(new DefaultCookie("key1", "val1"), new DefaultCookie("key2", "val2"));
    boolean preventCompressedResponse = true;

    // when
    BaseResponseInfo<?> responseInfo = createNewBaseResponseInfoForTesting(httpStatusCode, headers, mimeType, contentCharset, cookies, preventCompressedResponse);

    // then
    assertThat(responseInfo.getHttpStatusCode(), is(httpStatusCode));
    assertThat(responseInfo.getHeaders(), is(headers));
    assertThat(responseInfo.getDesiredContentWriterMimeType(), is(mimeType));
    assertThat(responseInfo.getDesiredContentWriterEncoding(), is(contentCharset));
    assertThat(responseInfo.getCookies(), is(cookies));
    assertThat(responseInfo.getUncompressedRawContentLength(), nullValue());
    assertThat(responseInfo.isPreventCompressedOutput(), is(preventCompressedResponse));
    assertThat(responseInfo.isResponseSendingStarted(), is(false));
    assertThat(responseInfo.isResponseSendingLastChunkSent(), is(false));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:25,代码来源:BaseResponseInfoTest.java

示例4: extractCookies_works_if_cookies_defined_in_headers

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
@Test
public void extractCookies_works_if_cookies_defined_in_headers() {
    // given
    Cookie cookie1 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    Cookie cookie2 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    HttpHeaders headers = new DefaultHttpHeaders().add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookie1, cookie2));

    HttpRequest nettyRequestMock = mock(HttpRequest.class);
    doReturn(headers).when(nettyRequestMock).headers();

    // when
    Set<Cookie> extractedCookies = HttpUtils.extractCookies(nettyRequestMock);

    // then
    assertThat(extractedCookies.contains(cookie1), is(true));
    assertThat(extractedCookies.contains(cookie2), is(true));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:18,代码来源:HttpUtilsTest.java

示例5: extractCookies_works_if_cookies_defined_in_trailing_headers

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
@Test
public void extractCookies_works_if_cookies_defined_in_trailing_headers() {
    // given
    Cookie cookie1 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    Cookie cookie2 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    HttpHeaders trailingHeaders = new DefaultHttpHeaders().add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookie1, cookie2));

    FullHttpRequest nettyRequestMock = mock(FullHttpRequest.class);
    doReturn(new DefaultHttpHeaders()).when(nettyRequestMock).headers();
    doReturn(trailingHeaders).when(nettyRequestMock).trailingHeaders();

    // when
    Set<Cookie> extractedCookies = HttpUtils.extractCookies(nettyRequestMock);

    // then
    assertThat(extractedCookies.contains(cookie1), is(true));
    assertThat(extractedCookies.contains(cookie2), is(true));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:19,代码来源:HttpUtilsTest.java

示例6: extractCookies_handles_cookie_values_leniently

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
@Test
public void extractCookies_handles_cookie_values_leniently() {
    // given
    //these are cookie values seen in the wild...
    Cookie cookie1 = new DefaultCookie(UUID.randomUUID().toString(), "2094%3Az%7C2021%3Ab");
    Cookie cookie2 = new DefaultCookie(UUID.randomUUID().toString(), "geoloc=cc=US,rc=OR,tp=vhigh,tz=PST,la=45.4978,lo=-122.6937,bw=5000");
    Cookie cookie3 = new DefaultCookie(UUID.randomUUID().toString(), "\"dm=n.com&si=27431295-a282-4745-8cd5-542e7fce" +
            "429e&ss=1477551008358&sl=76&tt=437632&obo=12&sh=1477552753923%3D76%3A12%3A437632%2C1477552698670%3D75%3" +
            "A12%3A429879%2C1477552677137%3D74%3A12%3A426596%2C1477552672564%3D73%3A12%3A425585%2C1477552669893%3D72" +
            "%3A12%3A423456&bcn=%2F%2F3408178b.mpstat.us%2F&ld=1477552753923&r=http%3A%2F%2Fwww.nike.com%2Fbe%2Fde_de%" +
            "2F&ul=1477552756811\"");
    HttpHeaders headers = new DefaultHttpHeaders().add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookie1, cookie2, cookie3));

    HttpRequest nettyRequestMock = mock(HttpRequest.class);
    doReturn(headers).when(nettyRequestMock).headers();

    // when
    Set<Cookie> extractedCookies = HttpUtils.extractCookies(nettyRequestMock);

    // then
    assertThat(extractedCookies.contains(cookie1), is(true));
    assertThat(extractedCookies.contains(cookie2), is(true));
    assertThat(extractedCookies.contains(cookie3), is(true));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:25,代码来源:HttpUtilsTest.java

示例7: testSuccess_setCookies

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
@Test
public void testSuccess_setCookies() throws Exception {
  setHandshakeSuccess();
  // First inbound message is hello.
  channel.readInbound();
  String responseContent = "<epp>response</epp>";
  Cookie cookie1 = new DefaultCookie("name1", "value1");
  Cookie cookie2 = new DefaultCookie("name2", "value2");
  channel.writeOutbound(
      makeEppHttpResponse(responseContent, HttpResponseStatus.OK, cookie1, cookie2));
  ByteBuf response = channel.readOutbound();
  assertThat(response).isEqualTo(Unpooled.wrappedBuffer(responseContent.getBytes(UTF_8)));
  String requestContent = "<epp>request</epp>";
  channel.writeInbound(Unpooled.wrappedBuffer(requestContent.getBytes(UTF_8)));
  FullHttpRequest request = channel.readInbound();
  assertHttpRequestEquivalent(request, makeEppHttpRequest(requestContent, cookie1, cookie2));
  // Nothing further to pass to the next handler.
  assertThat((Object) channel.readInbound()).isNull();
  assertThat((Object) channel.readOutbound()).isNull();
  assertThat(channel.isActive()).isTrue();
}
 
开发者ID:google,项目名称:nomulus,代码行数:22,代码来源:EppServiceHandlerTest.java

示例8: addCookie

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
public Response addCookie(String name, String value, String domain, Boolean isHttpOnly, Long maxAge, String path, Boolean isSecured) {
    if(cookies == null) {
        cookies = Lists.newArrayList();
    }
    final DefaultCookie defaultCookie = new DefaultCookie(name, value);
    if(domain != null) {
        defaultCookie.setDomain(domain);
    }
    if(isHttpOnly != null) {
        defaultCookie.setHttpOnly(isHttpOnly);
    }
    if(maxAge != null) {
        defaultCookie.setMaxAge(maxAge);
    }
    if(path != null) {
        defaultCookie.setPath(path);
    }
    if(isSecured != null) {
        defaultCookie.setSecure(isSecured);
    }
    cookies.add(defaultCookie);
    return this;
}
 
开发者ID:buremba,项目名称:netty-rest,代码行数:24,代码来源:Response.java

示例9: createSession

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
private CommonResponse createSession(String username, Set<String> roles, boolean ldap)
        throws Exception {
    String sessionId = new BigInteger(130, secureRandom).toString(32);
    ImmutableSession session = ImmutableSession.builder()
            .caseAmbiguousUsername(username)
            .ldap(ldap)
            .roles(roles)
            .lastRequest(clock.currentTimeMillis())
            .build();
    sessionMap.put(sessionId, session);

    String layoutJson = layoutService
            .getLayoutJson(session.createAuthentication(central, configRepository));
    CommonResponse response = new CommonResponse(OK, MediaType.JSON_UTF_8, layoutJson);
    Cookie cookie =
            new DefaultCookie(configRepository.getWebConfig().sessionCookieName(), sessionId);
    cookie.setHttpOnly(true);
    cookie.setPath("/");
    response.setHeader(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie));
    purgeExpiredSessions();

    auditSuccessfulLogin(username);
    return response;
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:25,代码来源:HttpSessionManager.java

示例10: unauthorized

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
private FullHttpResponse unauthorized(Optional<String> jsonp) {
    String encode = JsonHelper.jsonObject()
            .put("success", false)
            .put("message", UNAUTHORIZED.reasonPhrase())
            .put("authentication", config.getAuthentication())
            .put("googleApiKey", config.getGoogleClientId()).toString();
    if (jsonp.isPresent()) {
        encode = jsonp.get() + "(" + encode + ")";
    }
    DefaultFullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK,
            wrappedBuffer(encode.getBytes(CharsetUtil.UTF_8)));

    DefaultCookie cookie = new DefaultCookie("session", "");
    cookie.setHttpOnly(true);
    cookie.setMaxAge(0);
    response.headers().add(SET_COOKIE, STRICT.encode(cookie));
    response.headers().set(CONTENT_TYPE, "application/json; charset=utf-8");
    return response;
}
 
开发者ID:rakam-io,项目名称:rakam,代码行数:20,代码来源:WebUserHttpService.java

示例11: map

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
@Override
public List<Cookie> map(Event event, RequestParams requestParams, InetAddress sourceAddress, HttpHeaders responseHeaders) {
    GenericRecord properties = event.properties();

    if (properties.get("_user") == null) {
        Schema.Field user = event.properties().getSchema().getField("_user");
        if (user == null) {
            return null;
        }

        Schema.Type type = user.schema().getTypes().get(1).getType();
        Object anonymousUser = requestParams.cookies().stream()
                .filter(e -> e.name().equals("_anonymous_user")).findAny()
                .map(e -> cast(type, e.value())).orElse(generate(type));

        properties.put("_user", anonymousUser);
        DefaultCookie cookie = new DefaultCookie("_anonymous_user", String.valueOf(anonymousUser));
        cookie.setPath("/");

        return ImmutableList.of(cookie);
    }

    return null;
}
 
开发者ID:rakam-io,项目名称:rakam,代码行数:25,代码来源:UserIdEventMapper.java

示例12: convertWisdomCookieToNettyCookie

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
/**
 * Converts the Wisdom's cookie to a Netty's cookie.
 *
 * @param cookie the Wisdom's cookie
 * @return the Netty's cookie with the same metadata and content than the input cookie.
 */
public static DefaultCookie convertWisdomCookieToNettyCookie(Cookie cookie) {
    DefaultCookie nettyCookie = new DefaultCookie(cookie.name(), cookie.value());
    nettyCookie.setMaxAge(cookie.maxAge());
    // Comments are not supported anymore by netty.
    if (cookie.domain() != null) {
        nettyCookie.setDomain(cookie.domain());
    }
    if (cookie.isSecure()) {
        nettyCookie.setSecure(true);
    }
    if (cookie.path() != null) {
        nettyCookie.setPath(cookie.path());
    }
    if (cookie.isHttpOnly()) {
        nettyCookie.setHttpOnly(true);
    }
    return nettyCookie;
}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:25,代码来源:CookieHelper.java

示例13: getUserInfo

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
@RouterMapping(path="/info",requestMethod=RequestMethod.GET,renderType=RenderType.JSON)
public CookieRender getUserInfo(UserBean userBean, @RouterParam(key="pid") Integer pid){
    JSONObject object = new JSONObject();
    object.put("user",userService.selectUserInfo(userBean.getId()));
    object.put("pid",pid);
    CookieRender render = new DefaultCookieRender(RenderType.JSON,object);
    // 设置Cookie
    render.setCookie(new DefaultCookie("ak","47"));
    return render;
}
 
开发者ID:all4you,项目名称:redant,代码行数:11,代码来源:UserController.java

示例14: addCookie

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
/**
 * 添加一个Cookie
 * @param response response
 * @param name  cookie名字
 * @param value cookie值
 * @param domain cookie所在域
 * @param maxAge cookie生命周期  以秒为单位
 */
public static void addCookie(HttpResponse response,String name,String value,String domain,long maxAge){
    Cookie cookie = new DefaultCookie(name,value);
    cookie.setPath("/");
    if(domain!=null && domain.trim().length()>0) {
        cookie.setDomain(domain);
    }
    if(maxAge>0){
        cookie.setMaxAge(maxAge);
    }
    setCookie(response,cookie);
}
 
开发者ID:all4you,项目名称:redant,代码行数:20,代码来源:CookieHelper.java

示例15: saveCookies

import io.netty.handler.codec.http.cookie.DefaultCookie; //导入依赖的package包/类
private void saveCookies(final CharSequence headerKey, final CharSequence headerValue) {
    if (headerKey.toString().equalsIgnoreCase(SET_COOKIE)) {
        String rawValue = String.valueOf(headerValue);
        int idx = rawValue.indexOf(";");
        String cookie = rawValue.substring(0, idx).trim();
        idx = cookie.indexOf("=");
        String cookieName = cookie.substring(0, idx).trim();
        String cookieValue = cookie.substring(idx + 1).trim();
        cookieStorage.add(new DefaultCookie(cookieName, cookieValue));
    }
}
 
开发者ID:globocom,项目名称:groot,代码行数:12,代码来源:RequestExecutorService.java


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