本文整理匯總了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;
}
示例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")));
}
}
}
}
示例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();
}
示例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;
}
示例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;
}
示例6: ServletInputStreamImpl
import io.netty.handler.codec.http.FullHttpRequest; //導入方法依賴的package包/類
public ServletInputStreamImpl(FullHttpRequest request) {
this.request = request;
this.in = new ByteBufInputStream(request.content());
}
示例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());
}
示例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));
}