當前位置: 首頁>>代碼示例>>Java>>正文


Java FullHttpRequest.content方法代碼示例

本文整理匯總了Java中io.netty.handler.codec.http.FullHttpRequest.content方法的典型用法代碼示例。如果您正苦於以下問題:Java FullHttpRequest.content方法的具體用法?Java FullHttpRequest.content怎麽用?Java FullHttpRequest.content使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.handler.codec.http.FullHttpRequest的用法示例。


在下文中一共展示了FullHttpRequest.content方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doDispatcher

import io.netty.handler.codec.http.FullHttpRequest; //導入方法依賴的package包/類
/**
 * 請求分發與處理
 *
 * @param request http協議請求
 * @return 處理結果
 * @throws InvocationTargetException 調用異常
 * @throws IllegalAccessException    參數異常
 */
public Object doDispatcher(FullHttpRequest request) throws InvocationTargetException, IllegalAccessException {
    Object[] args;
    String uri = request.uri();
    if (uri.endsWith("favicon.ico")) {
        return "";
    }

    AceServiceBean aceServiceBean = Context.getAceServiceBean(uri);
    AceHttpMethod aceHttpMethod = AceHttpMethod.getAceHttpMethod(request.method().toString());
    ByteBuf content = request.content();
    //如果要多次解析,請用 request.content().copy()
    QueryStringDecoder decoder = new QueryStringDecoder(uri);
    Map<String, List<String>> requestMap = decoder.parameters();
    Object result = aceServiceBean.exec(uri, aceHttpMethod, requestMap, content == null ? null : content.toString(CharsetUtil.UTF_8));
    String contentType = request.headers().get("Content-Type");
    if (result == null) {
        ApplicationInfo mock = new ApplicationInfo();
        mock.setName("ace");
        mock.setVersion("1.0");
        mock.setDesc(" mock  !!! ");
        result = mock;
    }
    return result;

}
 
開發者ID:ChenXun1989,項目名稱:ace,代碼行數:34,代碼來源:DefaultDispatcher.java

示例2: debugRequestInfo

import io.netty.handler.codec.http.FullHttpRequest; //導入方法依賴的package包/類
private void debugRequestInfo(HttpObject httpObject, String key) {
	if (m_debugInfo && httpObject instanceof HttpRequest) {
		if (key != null) {
			LOGGER.debug("Cache Key: " + key);
		}
		if (httpObject instanceof FullHttpRequest) {
			FullHttpRequest req = (FullHttpRequest) httpObject;
			HttpHeaders headers = req.headers();
			LOGGER.debug("Headers:");
			for (Iterator<Entry<String, String>> it = headers.iterator(); it
					.hasNext();) {
				Entry<String, String> entry = it.next();
				LOGGER.debug("\t" + entry.getKey() + ":\t"
						+ entry.getValue());
			}
			ByteBuf content = req.content();
			int length = content.readableBytes();
			LOGGER.debug("Content Length: " + length);
			if (length != 0) {
				LOGGER.debug("Content: "
						+ content.toString(Charset.forName("UTF-8")));
			}
		}
	}
}
 
開發者ID:eBay,項目名稱:ServiceCOLDCache,代碼行數:26,代碼來源:NettyRequestProxyFilter.java

示例3: channelRead0

import io.netty.handler.codec.http.FullHttpRequest; //導入方法依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception {

    ByteBuf buf = msg.content();
    byte[] bytes = new byte[buf.readableBytes()];
    buf.getBytes(0, bytes);

    YarRequest yarRequest = YarProtocol.buildRequest(bytes);
    YarResponse yarResponse = process(yarRequest);

    FullHttpResponse response =
            new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(YarProtocol
                    .toProtocolBytes(yarResponse)));
    response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "application/x-www-form-urlencoded");
    response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, response.content().readableBytes());
    if (HttpHeaders.isKeepAlive(msg)) {
        response.headers().set(HttpHeaders.Names.CONNECTION, Values.KEEP_ALIVE);
    }
    ctx.write(response);
    ctx.flush();
    ctx.close();
}
 
開發者ID:weibocom,項目名稱:yar-java,代碼行數:23,代碼來源:HttpServerHandler.java

示例4: toCamelMessage

import io.netty.handler.codec.http.FullHttpRequest; //導入方法依賴的package包/類
@Override
public Message toCamelMessage(FullHttpRequest request, Exchange exchange, NettyHttpConfiguration configuration) throws Exception {
    LOG.trace("toCamelMessage: {}", request);

    NettyHttpMessage answer = new NettyHttpMessage(request, null);
    answer.setExchange(exchange);
    if (configuration.isMapHeaders()) {
        populateCamelHeaders(request, answer.getHeaders(), exchange, configuration);
    }

    if (configuration.isDisableStreamCache()) {
        // keep the body as is, and use type converters
        answer.setBody(request.content());
    } else {
        // turn the body into stream cached (on the client/consumer side we can facade the netty stream instead of converting to byte array)
        NettyChannelBufferStreamCache cache = new NettyChannelBufferStreamCache(request.content());
        // add on completion to the cache which is needed for Camel to keep track of the lifecycle of the cache
        exchange.addOnCompletion(new NettyChannelBufferStreamCacheOnCompletion(cache));
        answer.setBody(cache);
    }
    return answer;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:23,代碼來源:DefaultNettyHttpBinding.java

示例5: readContent

import io.netty.handler.codec.http.FullHttpRequest; //導入方法依賴的package包/類
protected static byte[] readContent(FullHttpRequest request) {
    ByteBuf buf = request.content();
    if (buf == null) {
        return null;
    }
    byte[] bytes = new byte[buf.readableBytes()];
    buf.getBytes(buf.readerIndex(), bytes);
    return bytes;
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:10,代碼來源:AbstractHttpServlet.java

示例6: ServletInputStreamImpl

import io.netty.handler.codec.http.FullHttpRequest; //導入方法依賴的package包/類
public ServletInputStreamImpl(FullHttpRequest request) {
    this.request = request;

    this.in = new ByteBufInputStream(request.content());
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:6,代碼來源:ServletInputStreamImpl.java

示例7: getRequestHash

import io.netty.handler.codec.http.FullHttpRequest; //導入方法依賴的package包/類
private String getRequestHash(FullHttpRequest request) {
	HttpHeaders headers = request.headers();
	String requestURI = getRequestURI(request);
	HttpMethod requestMethod = request.getMethod();
	Set<String> skipHeaders = m_skipHeaders;
	boolean skipRequestContent = m_uriMatchEnabled
			&& WildcardMatcher.isPatternCanBeMatchedIn(
					m_uriMatchOnly,
					new CacheDecisionObject(requestURI, requestMethod
							.name()));
	if(skipRequestContent){
		skipHeaders = new HashSet<>(m_skipHeaders);
		skipHeaders.add(HttpHeaders.Names.CONTENT_LENGTH.toUpperCase());
	}

	int uriHashcode = requestURI.hashCode();
	int methodHashCode = requestMethod.hashCode();
	List<Entry<String, String>> entries = headers.entries();
	List<String> hashList = new ArrayList<>();
	for (Iterator<Entry<String, String>> it = entries.iterator(); it
			.hasNext();) {
		Entry<String, String> entry = it.next();
		if (skipHeaders.contains(entry.getKey().toUpperCase())) {
			continue;
		}
		hashList.add(entry.getKey());
		hashList.add(entry.getValue());
	}

	int headersHashcode = hashList.hashCode();

	StringBuilder sb = new StringBuilder(4);
	sb.append(uriHashcode).append(methodHashCode).append(headersHashcode);

	if (!skipRequestContent) {
		ByteBuf content = request.content();
		sb.append(content.hashCode());
	}

	return Checksum.checksum(sb.toString());
}
 
開發者ID:eBay,項目名稱:ServiceCOLDCache,代碼行數:42,代碼來源:RequestKeyGenerator.java

示例8: decode

import io.netty.handler.codec.http.FullHttpRequest; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 * @see io.netty.handler.codec.MessageToMessageDecoder#decode(io.netty.channel.ChannelHandlerContext, java.lang.Object, java.util.List)
 */
@Override
protected void decode(final ChannelHandlerContext ctx, final FullHttpRequest msg, final List<Object> out) throws Exception {
	int forwarded = 0;
	int nodes = 0;
	final ElapsedTime et = SystemClock.startClock();
	final ByteBuf buff = msg.content();
	if(buff.readableBytes()<2) {
		log.info("Request from [{}] had no content: {}", ctx.channel().remoteAddress(), buff);
		// send response
		return;
	}
	
	final ArrayList<ObjectNode> metricNodes = new ArrayList<ObjectNode>(256); 
	final JsonNode rootNode = JSONOps.parseToNode(buff);
	if(rootNode.isArray()) {
		for(JsonNode node: rootNode) {
			if(node.has("metric")) {
				metricNodes.add((ObjectNode)node);
				nodes++;
				if(nodes==batchSize) {
					try {			
						nodes = 0;
						forwarded += forwardMetrics(metricNodes);							
					} finally {
						metricNodes.clear();
					}
				}
			}
		}
		if(!metricNodes.isEmpty()) try {
			nodes += metricNodes.size();
			forwarded += forwardMetrics(metricNodes);							
		} finally {
			metricNodes.clear();
		}			
	} else {
		if(rootNode.has("metric")) {				
			forwarded += forwardMetrics(Collections.singletonList((ObjectNode)rootNode));
		}
	}		
	ctx.channel().pipeline().writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NO_CONTENT));
	log.info("Wrote [{}] metrics: {}", forwarded, et.printAvg("Metrics", forwarded));
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:48,代碼來源:HttpJsonRpcHandler.java


注:本文中的io.netty.handler.codec.http.FullHttpRequest.content方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。