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


Java ServerCookieEncoder类代码示例

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


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

示例1: toFullHttpResponse

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
/**
 * 转换为Netty所用Response
 * 
 * @return FullHttpResponse
 */
public FullHttpResponse toFullHttpResponse() {
	final FullHttpResponse fullHttpResponse = new DefaultFullHttpResponse(httpVersion, status, content);

	// headers
	final HttpHeaders httpHeaders = fullHttpResponse.headers().add(headers);
	httpHeaders.set(Names.CONTENT_TYPE, contentType + "; charset=" + charset);
	httpHeaders.set(Names.CONTENT_ENCODING, charset);
	httpHeaders.set(Names.CONTENT_LENGTH, content.readableBytes());

	// Cookies
	for (Cookie cookie : cookies) {
		httpHeaders.add(Names.SET_COOKIE, ServerCookieEncoder.encode(cookie));
	}

	return fullHttpResponse;
}
 
开发者ID:chenzehe,项目名称:ponycar,代码行数:22,代码来源:Response.java

示例2: addCookie

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
@Override
public void addCookie(Cookie arg0) {
    String cookieString = m_nettyhttpresp.headers().get(HttpHeaders.Names.COOKIE);
    Set<io.netty.handler.codec.http.Cookie> cookies;
    if (cookieString != null) {
        cookies = CookieDecoder.decode(cookieString);
        cookies.add(new io.netty.handler.codec.http.DefaultCookie(arg0.getName(), arg0.getValue()));
    } else {
        cookies = new HashSet<io.netty.handler.codec.http.Cookie>();
        cookies.add(new io.netty.handler.codec.http.DefaultCookie(arg0.getName(), arg0.getValue()));
    }

    if (!cookies.isEmpty()) {
        // Reset the cookies if necessary.
        HttpHeaders.setHeader(m_nettyhttpresp, HttpHeaders.Names.SET_COOKIE, ServerCookieEncoder.encode(cookies));
    }
}
 
开发者ID:pulsarIO,项目名称:jetstream,代码行数:18,代码来源:DefaultHttpServletResponse.java

示例3: setSigned

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
public void setSigned(String name, String value, long timeout, String path, HttpServerRequest request) {
	Cookie cookie = new DefaultCookie(name, value);
	cookie.setMaxAge(timeout);
	cookie.setSecure("https".equals(Renders.getScheme(request)));
	cookie.setHttpOnly(true);
	if (path != null && !path.trim().isEmpty()) {
		cookie.setPath(path);
	}
	if (signKey != null) {
		try {
			signCookie(cookie);
		} catch (InvalidKeyException | NoSuchAlgorithmException
				| IllegalStateException | UnsupportedEncodingException e) {
			log.error(e);
			return;
		}
		request.response().headers().add("Set-Cookie", ServerCookieEncoder.encode(cookie));
	}
}
 
开发者ID:web-education,项目名称:web-utils,代码行数:20,代码来源:CookieHelper.java

示例4: setCookie

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
void setCookie(HttpRequest request, FullHttpResponse response) {
  // Encode the cookie.
  String cookieString = request.headers().get(COOKIE);
  if (cookieString != null) {
    Set<Cookie> cookies = CookieDecoder.decode(cookieString);
    if (!cookies.isEmpty()) {
      // Reset the cookies if necessary.
      for (Cookie cookie: cookies) {
        if("visit-count".equals(cookie.getName())) {
          int count = Integer.parseInt(cookie.getValue()) ;
          cookie.setValue(Integer.toString(count + 1));
          //System.out.println("Visit: " + count);
        }
        response.headers().add(SET_COOKIE, ServerCookieEncoder.encode(cookie));
      }
    }
  } else {
    // Browser sent no cookie.  Add some.
    response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("id", UUID.randomUUID().toString()));
    response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("visit-count", "1"));
    response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("first-visit-time", new Date().toString()));
  }
}
 
开发者ID:DemandCube,项目名称:Sparkngin,代码行数:24,代码来源:TrackingPixelRouteHandler.java

示例5: handleConnect

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
private void handleConnect(ChannelHandlerContext ctx, HttpRequest req) {
	boolean isConnected = false;
	String sessionId = HttpSessionStore.getClientSessionId(req);
	HttpChannelEntity httpChannelEntity = null;
	if (!HttpSessionStore.checkJSessionId(sessionId)) {
		sessionId = HttpSessionStore.genJSessionId();

		httpChannelEntity = new HttpJsonpChannelEntity(sessionId, true);
		MemoryMetaPool.registerClienId(sessionId, httpChannelEntity);
	} else {
		isConnected = true;
		httpChannelEntity = (HttpChannelEntity) MemoryMetaPool
				.getChannelEntryByClientId(sessionId);
	}

	Map<String, Object> map = new HashMap<String, Object>(2);
	map.put("status", true);
	map.put("clientId", sessionId);
	String result = gson.toJson(map);
	ByteBuf content = ctx.alloc().directBuffer()
			.writeBytes(result.getBytes());

	FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK,
			content);
	if (isConnected) {
		res.headers().add("Set-Cookie",
				ServerCookieEncoder.encode("JSESSIONID", sessionId));
	}
	res.headers().set(CONTENT_TYPE, HEADER_CONTENT_TYPE);
	setContentLength(res, content.readableBytes());

	ScheduledFuture<?> scheduleTask = ctx.executor().schedule(
			new SessionTimeoutTask(sessionId), 60, TimeUnit.SECONDS);
	httpChannelEntity.setScheduleTask(scheduleTask);

	sendHttpResponse(ctx, req, res);
}
 
开发者ID:osswangxining,项目名称:mqttserver,代码行数:38,代码来源:HttpJsonpTransport.java

示例6: writeResponse

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
private boolean writeResponse(HttpObject currentObj, ChannelHandlerContext ctx) {
    // Decide whether to close the connection or not.
    boolean keepAlive = HttpHeaders.isKeepAlive(request);
    // Build the response object.
    FullHttpResponse response = new DefaultFullHttpResponse(
            HTTP_1_1, currentObj.getDecoderResult().isSuccess()? OK : BAD_REQUEST,
            Unpooled.copiedBuffer(buf.toString(), CharsetUtil.UTF_8));

    response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");

    if (keepAlive) {
        // Add 'Content-Length' header only for a keep-alive connection.
        response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
        // Add keep alive header as per:
        // - http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
        response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
    }

    // Encode the cookie.
    String cookieString = request.headers().get(COOKIE);
    if (cookieString != null) {
        Set<Cookie> cookies = CookieDecoder.decode(cookieString);
        if (!cookies.isEmpty()) {
            // Reset the cookies if necessary.
            for (Cookie cookie: cookies) {
                response.headers().add(SET_COOKIE, ServerCookieEncoder.encode(cookie));
            }
        }
    } else {
        // Browser sent no cookie.  Add some.
        response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("key1", "value1"));
        response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("key2", "value2"));
    }

    // Write the response.
    ctx.write(response);

    return keepAlive;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:40,代码来源:HttpSnoopServerHandler.java

示例7: writeResponse

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
private boolean writeResponse(HttpObject currentObj, ChannelHandlerContext ctx) {
    // Decide whether to close the connection or not.
    boolean keepAlive = HttpHeaders.isKeepAlive(request);
    // Build the response object.
    FullHttpResponse response = new DefaultFullHttpResponse(
            HTTP_1_1, currentObj.decoderResult().isSuccess()? OK : BAD_REQUEST,
            Unpooled.copiedBuffer(buf.toString(), CharsetUtil.UTF_8));

    response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");

    if (keepAlive) {
        // Add 'Content-Length' header only for a keep-alive connection.
        response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
        // Add keep alive header as per:
        // - http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
        response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
    }

    // Encode the cookie.
    String cookieString = request.headers().get(COOKIE);
    if (cookieString != null) {
        Set<Cookie> cookies = CookieDecoder.decode(cookieString);
        if (!cookies.isEmpty()) {
            // Reset the cookies if necessary.
            for (Cookie cookie: cookies) {
                response.headers().add(SET_COOKIE, ServerCookieEncoder.encode(cookie));
            }
        }
    } else {
        // Browser sent no cookie.  Add some.
        response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("key1", "value1"));
        response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("key2", "value2"));
    }

    // Write the response.
    ctx.write(response);

    return keepAlive;
}
 
开发者ID:krisjey,项目名称:netty.book.kor,代码行数:40,代码来源:HttpSnoopServerHandler.java

示例8: writeResponse

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
private boolean writeResponse(HttpObject currentObj, ChannelHandlerContext ctx) {
    // Decide whether to close the connection or not.
    boolean keepAlive = isKeepAlive(request);
    // Build the response object.
    FullHttpResponse response = new DefaultFullHttpResponse(
            HTTP_1_1, currentObj.getDecoderResult().isSuccess()? OK : BAD_REQUEST,
            Unpooled.copiedBuffer(buf.toString(), CharsetUtil.UTF_8));

    response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");

    if (keepAlive) {
        // Add 'Content-Length' header only for a keep-alive connection.
        response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
        // Add keep alive header as per:
        // - http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
        response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
    }

    // Encode the cookie.
    String cookieString = request.headers().get(COOKIE);
    if (cookieString != null) {
        Set<Cookie> cookies = CookieDecoder.decode(cookieString);
        if (!cookies.isEmpty()) {
            // Reset the cookies if necessary.
            for (Cookie cookie: cookies) {
                response.headers().add(SET_COOKIE, ServerCookieEncoder.encode(cookie));
            }
        }
    } else {
        // Browser sent no cookie.  Add some.
        response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("key1", "value1"));
        response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("key2", "value2"));
    }

    // Write the response.
    ctx.write(response);

    return keepAlive;
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:40,代码来源:HttpSnoopServerHandler.java

示例9: writeResponse

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
private boolean writeResponse(HttpObject currentObj, ChannelHandlerContext ctx) {
  // Decide whether to close the connection or not.
  boolean keepAlive = isKeepAlive(request);
  // Build the response object.
  FullHttpResponse response =
      new DefaultFullHttpResponse(HTTP_1_1, currentObj.getDecoderResult().isSuccess() ? OK
          : BAD_REQUEST, Unpooled.copiedBuffer(buf.toString(), CharsetUtil.UTF_8));

  response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");

  if (keepAlive) {
    // Add 'Content-Length' header only for a keep-alive connection.
    response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
    // Add keep alive header as per:
    // - http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
    response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
  }

  // Encode the cookie.
  String cookieString = request.headers().get(COOKIE);
  if (cookieString != null) {
    Set<Cookie> cookies = CookieDecoder.decode(cookieString);
    if (!cookies.isEmpty()) {
      // Reset the cookies if necessary.
      for (Cookie cookie : cookies) {
        response.headers().add(SET_COOKIE, ServerCookieEncoder.encode(cookie));
      }
    }
  } else {
    // Browser sent no cookie. Add some.
    response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("key1", "value1"));
    response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("key2", "value2"));
  }

  // Write the response.
  ctx.write(response);

  return keepAlive;
}
 
开发者ID:detectiveframework,项目名称:detective,代码行数:40,代码来源:HttpServerTask.java

示例10: writeResponse

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
private boolean writeResponse(HttpObject currentObj, ChannelHandlerContext ctx) {
  // Decide whether to close the connection or not.
  boolean keepAlive = HttpHeaders.isKeepAlive(request);
  // Build the response object.
  FullHttpResponse response = new DefaultFullHttpResponse(
      HTTP_1_1, currentObj.getDecoderResult().isSuccess() ? OK : BAD_REQUEST,
      Unpooled.copiedBuffer(buf.toString(), CharsetUtil.UTF_8));

  response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");

  if (keepAlive) {
    // Add 'Content-Length' header only for a keep-alive connection.
    response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
    // Add keep alive header as per:
    // - http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
    response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
  }

  // Encode the cookie.
  String cookieString = request.headers().get(COOKIE);
  if (cookieString != null) {
    Set<Cookie> cookies = CookieDecoder.decode(cookieString);
    if (!cookies.isEmpty()) {
      // Reset the cookies if necessary.
      for (Cookie cookie : cookies) {
        response.headers().add(SET_COOKIE, ServerCookieEncoder.encode(cookie));
      }
    }
  } else {
    // Browser sent no cookie.  Add some.
    response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("key1", "value1"));
    response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("key2", "value2"));
  }

  // Write the response.
  ctx.write(response);

  return keepAlive;
}
 
开发者ID:xjdr,项目名称:xio,代码行数:40,代码来源:SampleHandler.java

示例11: set

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
public static void set(String name, String value, long timeout, String path, HttpServerRequest request) {
	Cookie cookie = new DefaultCookie(name, value);
	cookie.setMaxAge(timeout);
	cookie.setSecure("https".equals(Renders.getScheme(request)));
	if (path != null && !path.trim().isEmpty()) {
		cookie.setPath(path);
	}
	request.response().headers().add("Set-Cookie", ServerCookieEncoder.encode(cookie));
}
 
开发者ID:web-education,项目名称:web-utils,代码行数:10,代码来源:CookieHelper.java

示例12: writeResponse

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
private void writeResponse(Channel channel) {
    // Convert the response content to a ChannelBuffer.
    ByteBuf buf = copiedBuffer(responseContent.toString(), CharsetUtil.UTF_8);
    responseContent.setLength(0);

    // Decide whether to close the connection or not.
    boolean close = HttpHeaders.Values.CLOSE.equalsIgnoreCase(request.headers().get(CONNECTION))
            || request.getProtocolVersion().equals(HttpVersion.HTTP_1_0)
            && !HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(request.headers().get(CONNECTION));

    // Build the response object.
    FullHttpResponse response = new DefaultFullHttpResponse(
            HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buf);
    response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");

    if (!close) {
        // There's no need to add 'Content-Length' header
        // if this is the last response.
        response.headers().set(CONTENT_LENGTH, buf.readableBytes());
    }

    Set<Cookie> cookies;
    String value = request.headers().get(COOKIE);
    if (value == null) {
        cookies = Collections.emptySet();
    } else {
        cookies = CookieDecoder.decode(value);
    }
    if (!cookies.isEmpty()) {
        // Reset the cookies if necessary.
        for (Cookie cookie : cookies) {
            response.headers().add(SET_COOKIE, ServerCookieEncoder.encode(cookie));
        }
    }
    // Write the response.
    ChannelFuture future = channel.writeAndFlush(response);
    // Close the connection after the write operation is done if necessary.
    if (close) {
        future.addListener(ChannelFutureListener.CLOSE);
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:42,代码来源:HttpUploadServerHandler.java

示例13: writeResponse

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
private boolean writeResponse(HttpObject currentObj, ChannelHandlerContext ctx) {
  // Decide whether to close the connection or not.
  boolean keepAlive = HttpHeaders.isKeepAlive(request);
  // Build the response object.
  FullHttpResponse response =
      new DefaultFullHttpResponse(
          HTTP_1_1,
          currentObj.getDecoderResult().isSuccess() ? OK : BAD_REQUEST,
          Unpooled.copiedBuffer(buf.toString(), CharsetUtil.UTF_8));

  response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");

  if (keepAlive) {
    // Add 'Content-Length' header only for a keep-alive connection.
    response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
    // Add keep alive header as per:
    // - http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
    response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
  }

  // Encode the cookie.
  String cookieString = request.headers().get(COOKIE);
  if (cookieString != null) {
    Set<Cookie> cookies = CookieDecoder.decode(cookieString);
    if (!cookies.isEmpty()) {
      // Reset the cookies if necessary.
      for (Cookie cookie : cookies) {
        response.headers().add(SET_COOKIE, ServerCookieEncoder.encode(cookie));
      }
    }
  } else {
    // Browser sent no cookie.  Add some.
    response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("key1", "value1"));
    response.headers().add(SET_COOKIE, ServerCookieEncoder.encode("key2", "value2"));
  }

  // Write the response.
  ctx.write(response);

  return keepAlive;
}
 
开发者ID:xjdr,项目名称:xio,代码行数:42,代码来源:SampleHandler.java

示例14: encode

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
String encode() {
    return ServerCookieEncoder.encode(c);
}
 
开发者ID:nosceon,项目名称:titanite,代码行数:4,代码来源:Cookie.java

示例15: bake

import io.netty.handler.codec.http.ServerCookieEncoder; //导入依赖的package包/类
public ResponseBuilder bake() {
  addCookie(ServerCookieEncoder.encode(cookie));
  return ResponseBuilder.this;
}
 
开发者ID:outbrain,项目名称:ob1k,代码行数:5,代码来源:ResponseBuilder.java


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