热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

io.netty.handler.codec.http.FullHttpRequest.content()方法的使用及代码示例

本文整理了Java中io.netty.handler.codec.http.FullHttpRequest.content()方法的一些代码示例,展示了Fu

本文整理了Java中io.netty.handler.codec.http.FullHttpRequest.content()方法的一些代码示例,展示了FullHttpRequest.content()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FullHttpRequest.content()方法的具体详情如下:
包路径:io.netty.handler.codec.http.FullHttpRequest
类名称:FullHttpRequest
方法名:content

FullHttpRequest.content介绍

暂无

代码示例

代码示例来源:origin: jamesdbloom/mockserver

private void setBody(HttpRequest httpRequest, FullHttpRequest fullHttpRequest) {
if (fullHttpRequest.content() != null && fullHttpRequest.content().readableBytes() > 0) {
byte[] bodyBytes = new byte[fullHttpRequest.content().readableBytes()];
fullHttpRequest.content().readBytes(bodyBytes);
if (bodyBytes.length > 0) {
if (ContentTypeMapper.isBinary(fullHttpRequest.headers().get(CONTENT_TYPE))) {
httpRequest.withBody(new BinaryBody(bodyBytes));
} else {
Charset requestCharset = ContentTypeMapper.getCharsetFromContentTypeHeader(fullHttpRequest.headers().get(CONTENT_TYPE));
httpRequest.withBody(new StringBody(new String(bodyBytes, requestCharset), DEFAULT_HTTP_CHARACTER_SET.equals(requestCharset) ? null : requestCharset));
}
}
}
}
}

代码示例来源:origin: weibocom/motan

protected void processHttpRequest(ChannelHandlerContext ctx, FullHttpRequest httpRequest) {
FullHttpResponse httpRespOnse= null;
try {
httpRespOnse= (FullHttpResponse) messageHandler.handle(serverChannel, httpRequest);
} catch (Exception e) {
LoggerUtil.error("NettyHttpHandler process http request fail.", e);
httpRespOnse= buildErrorResponse(e.getMessage());
} finally {
httpRequest.content().release();
}
sendResponse(ctx, httpResponse);
}

代码示例来源:origin: ffay/lanproxy

@Override
public ResponseInfo request(FullHttpRequest request) {
byte[] buf = new byte[request.content().readableBytes()];
request.content().readBytes(buf);
String cOnfig= new String(buf, Charset.forName("UTF-8"));
List clients = JsonUtil.json2object(config, new TypeToken>() {
});
if (clients == null) {
return ResponseInfo.build(ResponseInfo.CODE_INVILID_PARAMS, "Error json config");
}
try {
ProxyConfig.getInstance().update(config);
} catch (Exception ex) {
logger.error("config update error", ex);
return ResponseInfo.build(ResponseInfo.CODE_INVILID_PARAMS, ex.getMessage());
}
return ResponseInfo.build(ResponseInfo.CODE_OK, "success");
}
});

代码示例来源:origin: micronaut-projects/micronaut-core

private void prepareHttpHeaders(URI requestURI, io.micronaut.http.HttpRequest request, io.netty.handler.codec.http.HttpRequest nettyRequest, boolean permitsBody, boolean closeConnection) {
HttpHeaders headers = nettyRequest.headers();
headers.set(HttpHeaderNames.HOST, getHostHeader(requestURI));
if (closeConnection) {
headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
} else {
headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
}
if (permitsBody) {
Optional body = request.getBody();
if (body.isPresent()) {
if (!headers.contains(HttpHeaderNames.CONTENT_TYPE)) {
MediaType mediaType = request.getContentType().orElse(MediaType.APPLICATION_JSON_TYPE);
headers.set(HttpHeaderNames.CONTENT_TYPE, mediaType);
}
if (nettyRequest instanceof FullHttpRequest) {
FullHttpRequest fullHttpRequest = (FullHttpRequest) nettyRequest;
headers.set(HttpHeaderNames.CONTENT_LENGTH, fullHttpRequest.content().readableBytes());
} else {
headers.set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
}
} else {
headers.set(HttpHeaderNames.CONTENT_LENGTH, 0);
}
}
}

代码示例来源:origin: alibaba/Sentinel

private CommandRequest parseRequest(FullHttpRequest request) {
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.uri());
CommandRequest serverRequest = new CommandRequest();
Map> paramMap = queryStringDecoder.parameters();
// Parse request parameters.
if (!paramMap.isEmpty()) {
for (Entry> p : paramMap.entrySet()) {
if (!p.getValue().isEmpty()) {
serverRequest.addParam(p.getKey(), p.getValue().get(0));
}
}
}
// Parse command name.
String target = parseTarget(queryStringDecoder.rawPath());
serverRequest.addMetadata(HttpCommandUtils.REQUEST_TARGET, target);
// Parse body.
if (request.content().readableBytes() <= 0) {
serverRequest.setBody(null);
} else {
byte[] body = new byte[request.content().readableBytes()];
request.content().getBytes(0, body);
serverRequest.setBody(body);
}
return serverRequest;
}

代码示例来源:origin: micronaut-projects/micronaut-core

private void traceRequest(io.micronaut.http.HttpRequest request, io.netty.handler.codec.http.HttpRequest nettyRequest) {
HttpHeaders headers = nettyRequest.headers();
traceHeaders(headers);
if (io.micronaut.http.HttpMethod.permitsRequestBody(request.getMethod()) && request.getBody().isPresent() && nettyRequest instanceof FullHttpRequest) {
FullHttpRequest fullHttpRequest = (FullHttpRequest) nettyRequest;
ByteBuf cOntent= fullHttpRequest.content();
if (log.isTraceEnabled()) {
traceBody("Request", content);
}
}
}

代码示例来源:origin: ffay/lanproxy

@Override
public ResponseInfo request(FullHttpRequest request) {
byte[] buf = new byte[request.content().readableBytes()];
request.content().readBytes(buf);
String cOnfig= new String(buf);
Map loginParams = JsonUtil.json2object(config, new TypeToken>() {
});
if (loginParams == null) {
return ResponseInfo.build(ResponseInfo.CODE_INVILID_PARAMS, "Error login info");
}
String username = loginParams.get("username");
String password = loginParams.get("password");
if (username == null || password == null) {
return ResponseInfo.build(ResponseInfo.CODE_INVILID_PARAMS, "Error username or password");
}
if (username.equals(ProxyConfig.getInstance().getConfigAdminUsername()) && password.equals(ProxyConfig.getInstance().getConfigAdminPassword())) {
token = UUID.randomUUID().toString().replace("-", "");
return ResponseInfo.build(token);
}
return ResponseInfo.build(ResponseInfo.CODE_INVILID_PARAMS, "Error username or password");
}
});

代码示例来源:origin: docker-java/docker-java

private HttpRequest prepareEntityRequest(String uri, Object entity, HttpMethod httpMethod) {
HttpRequest request = null;
if (entity != null) {
FullHttpRequest fullRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, httpMethod, uri);
byte[] bytes;
try {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
bytes = objectMapper.writeValueAsBytes(entity);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
fullRequest.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json");
fullRequest.content().clear().writeBytes(Unpooled.copiedBuffer(bytes));
fullRequest.headers().set(HttpHeaderNames.CONTENT_LENGTH, bytes.length);
request = fullRequest;
} else {
request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, httpMethod, uri);
request.headers().set(HttpHeaderNames.CONTENT_LENGTH, 0);
}
setDefaultHeaders(request);
return request;
}

代码示例来源:origin: weibocom/motan

String packagerName = "JSON";
try {
ByteBuf buf = httpRequest.content();
final byte[] cOntentBytes= new byte[buf.readableBytes()];
buf.getBytes(0, contentBytes);

代码示例来源:origin: traccar/traccar

@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
FullHttpRequest request = (FullHttpRequest) msg;
Document document = documentBuilder.parse(new ByteBufferBackedInputStream(request.content().nioBuffer()));
NodeList nodes = (NodeList) messageExpression.evaluate(document, XPathConstants.NODESET);
List positiOns= new LinkedList<>();
for (int i = 0; i Node node = nodes.item(i);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, xPath.evaluate("esnName", node));
if (deviceSession != null) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(true);
position.setTime(DateUtil.parseDate(xPath.evaluate("timestamp", node)));
position.setLatitude(Double.parseDouble(xPath.evaluate("latitude", node)));
position.setLongitude(Double.parseDouble(xPath.evaluate("longitude", node)));
position.set(Position.KEY_EVENT, xPath.evaluate("messageType", node));
positions.add(position);
}
}
sendResponse(channel, HttpResponseStatus.OK);
return positions;
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpRequest request) throws Exception {
final Channel channel = ctx.channel();
final boolean keepAlive = HttpUtil.isKeepAlive(request);
final HttpVersion httpRequestVersion = request.protocolVersion();
final String origin = request.headers().get(HttpHeaderNames.ORIGIN);
// to allow for future changes, let's be at least a little strict in what we accept here.
if (HttpMethod.OPTIONS.equals(request.method())) {
writeResponse(channel, keepAlive, httpRequestVersion, HttpResponseStatus.OK, origin);
return;
} else if (!HttpMethod.POST.equals(request.method())) {
writeResponse(channel, keepAlive, httpRequestVersion, HttpResponseStatus.METHOD_NOT_ALLOWED, origin);
return;
}
final boolean correctPath = "/gelf".equals(request.uri());
if (correctPath && request instanceof FullHttpRequest) {
final FullHttpRequest fullHttpRequest = (FullHttpRequest) request;
final ByteBuf buffer = fullHttpRequest.content();
// send on to raw message handler
writeResponse(channel, keepAlive, httpRequestVersion, HttpResponseStatus.ACCEPTED, origin);
ctx.fireChannelRead(buffer.retain());
} else {
writeResponse(channel, keepAlive, httpRequestVersion, HttpResponseStatus.NOT_FOUND, origin);
}
}

代码示例来源:origin: weibocom/motan

httpRequest.content().retain();
}catch(Exception e){
LoggerUtil.error("request is rejected by threadpool!", e);
httpRequest.content().release();
sendResponse(ctx, buildErrorResponse("request is rejected by threadpool!"));

代码示例来源:origin: weibocom/motan

httpRequest.content().retain();
} catch (Exception e) {
LoggerUtil.error("request is rejected by threadpool!", e);
httpRequest.content().release();
sendResponse(ctx, buildErrorResponse("request is rejected by threadpool!"));

代码示例来源:origin: weibocom/motan

@SuppressWarnings("rawtypes")
protected void processHttpRequest(ChannelHandlerContext ctx, FullHttpRequest httpRequest) {
FullHttpResponse httpRespOnse= null;
try {
DefaultRequest rpcRequest = buildRpcRequest(httpRequest);
String ip = NetUtils.getHostName(ctx.channel().remoteAddress());
if(ip != null){
rpcRequest.setAttachment(URLParamType.host.getName(), ip);
}

Provider provider = providerMap.get(rpcRequest.getInterfaceName());
if (provider == null) {
httpRespOnse= buildErrorResponse("request service not exist. service:" + rpcRequest.getInterfaceName());
} else {
Response respOnse= provider.call(rpcRequest);
httpRespOnse= buildHttpResponse(response, HttpUtil.isKeepAlive(httpRequest));
}
} catch (Exception e) {
LoggerUtil.error("NettyHttpHandler process http request fail.", e);
httpRespOnse= buildErrorResponse(e.getMessage());
} finally {
httpRequest.content().release();
}
sendResponse(ctx, httpResponse);
}

代码示例来源:origin: dreamhead/moco

private HttpRequestBase prepareRemoteRequest(final FullHttpRequest request, final URL url) {
HttpRequestBase remoteRequest = createRemoteRequest(request, url);
remoteRequest.setConfig(createRequestConfig());
long cOntentLength= HttpUtil.getContentLength(request, -1);
if (contentLength > 0 && remoteRequest instanceof HttpEntityEnclosingRequest) {
HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) remoteRequest;
entityRequest.setEntity(createEntity(request.content(), contentLength));
}
return remoteRequest;
}

代码示例来源:origin: mrniko/netty-socketio

private void handleMessage(FullHttpRequest req, UUID sessionId, QueryStringDecoder queryDecoder, ChannelHandlerContext ctx)
throws IOException {
String origin = req.headers().get(HttpHeaderNames.ORIGIN);
if (queryDecoder.parameters().containsKey("disconnect")) {
ClientHead client = clientsBox.get(sessionId);
client.onChannelDisconnect();
ctx.channel().writeAndFlush(new XHRPostMessage(origin, sessionId));
} else if (HttpMethod.POST.equals(req.method())) {
onPost(sessionId, ctx, origin, req.content());
} else if (HttpMethod.GET.equals(req.method())) {
onGet(sessionId, ctx, origin);
} else if (HttpMethod.OPTIONS.equals(req.method())) {
onOptions(sessionId, ctx, origin);
} else {
log.error("Wrong {} method invocation for {}", req.method(), sessionId);
sendError(ctx);
}
}

代码示例来源:origin: weibocom/motan

addParams(params, uriInfo[1]);
ByteBuf buf = httpRequest.content();
final byte[] cOntentBytes= new byte[buf.readableBytes()];
buf.getBytes(0, contentBytes);

代码示例来源:origin: line/armeria

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof UpgradeEvent) {
// Generate the initial Http2Settings frame,
// so that the next handler knows the protocol upgrade occurred as well.
ctx.fireChannelRead(DEFAULT_HTTP2_SETTINGS);
// Continue handling the upgrade request after the upgrade is complete.
final FullHttpRequest nettyReq = ((UpgradeEvent) evt).upgradeRequest();
// Remove the headers related with the upgrade.
nettyReq.headers().remove(HttpHeaderNames.CONNECTION);
nettyReq.headers().remove(HttpHeaderNames.UPGRADE);
nettyReq.headers().remove(Http2CodecUtil.HTTP_UPGRADE_SETTINGS_HEADER);
if (logger.isDebugEnabled()) {
logger.debug("{} Handling the pre-upgrade request ({}): {} {} {} ({}B)",
ctx.channel(), ((UpgradeEvent) evt).protocol(),
nettyReq.method(), nettyReq.uri(), nettyReq.protocolVersion(),
nettyReq.content().readableBytes());
}
channelRead(ctx, nettyReq);
channelReadComplete(ctx);
return;
}
ctx.fireUserEventTriggered(evt);
}
}

代码示例来源:origin: traccar/traccar

@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
FullHttpRequest request = (FullHttpRequest) msg;
JsonArray result = Json.createReader(new StringReader(request.content().toString(StandardCharsets.UTF_8)))
.readArray();
List positiOns= new LinkedList<>();
for (int i = 0; i JsonObject message = result.getJsonObject(i);
JsonString ident = message.getJsonString("ident");
if (ident == null) {
continue;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ident.getString());
if (deviceSession == null) {
continue;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
decodePosition(message, position);
positions.add(position);
}
sendResponse(channel, HttpResponseStatus.OK);
return positions;
}

代码示例来源:origin: dreamhead/moco

private static MessageContent toMessageContent(final FullHttpRequest request) {
long cOntentLength= HttpUtil.getContentLength(request, -1);
if (contentLength <= 0) {
return content().build();
}
return content()
.withCharset(HttpUtil.getCharset(request))
.withContent(new ByteBufInputStream(request.content()))
.build();
}

推荐阅读
  • Web动态服务器Python基本实现
    Web动态服务器Python基本实现 ... [详细]
  • 【MySQL】frm文件解析
    官网说明:http:dev.mysql.comdocinternalsenfrm-file-format.htmlfrm是MySQL表结构定义文件,通常frm文件是不会损坏的,但是如果 ... [详细]
  • Python3爬虫入门:pyspider的基本使用[python爬虫入门]
    Python学习网有大量免费的Python入门教程,欢迎大家来学习。本文主要通过爬取去哪儿网的旅游攻略来给大家介绍pyspid ... [详细]
  • 本文将从基础概念入手,详细探讨SpringMVC框架中DispatcherServlet如何通过HandlerMapping进行请求分发,以及其背后的源码实现细节。 ... [详细]
  • 深入理解:AJAX学习指南
    本文详细探讨了AJAX的基本概念、工作原理及其在现代Web开发中的应用,旨在为初学者提供全面的学习资料。 ... [详细]
  • 本文探讨了如何使用Scrapy框架构建高效的数据采集系统,以及如何通过异步处理技术提升数据存储的效率。同时,文章还介绍了针对不同网站采用的不同采集策略。 ... [详细]
  • 本文详细介绍如何在SSM(Spring + Spring MVC + MyBatis)框架中实现分页功能。包括分页的基本概念、数据准备、前端分页栏的设计与实现、后端分页逻辑的编写以及最终的测试步骤。 ... [详细]
  • 基于SSM框架的在线考试系统:随机组卷功能详解
    本文深入探讨了基于SSM(Spring, Spring MVC, MyBatis)框架构建的在线考试系统中,随机组卷功能的设计与实现方法。 ... [详细]
  • 尽管在WPF中工作了一段时间,但在菜单控件的样式设置上遇到了一些基础问题,特别是关于如何正确配置前景色和背景色。 ... [详细]
  • 本文探讨了如何在PHP与MySQL环境中实现高效的分页查询,包括基本的分页实现、性能优化技巧以及高级的分页策略。 ... [详细]
  • 本文介绍了SIP(Session Initiation Protocol,会话发起协议)的基本概念、功能、消息格式及其实现机制。SIP是一种在IP网络上用于建立、管理和终止多媒体通信会话的应用层协议。 ... [详细]
  • 本文详细介绍了在Windows系统中如何配置Nginx以实现高效的缓存加速功能,包括关键的配置文件设置和示例代码。 ... [详细]
  • Requests库的基本使用方法
    本文介绍了Python中Requests库的基础用法,包括如何安装、GET和POST请求的实现、如何处理Cookies和Headers,以及如何解析JSON响应。相比urllib库,Requests库提供了更为简洁高效的接口来处理HTTP请求。 ... [详细]
  • 本文详细介绍了如何正确设置Shadowsocks公共代理,包括调整超时设置、检查系统限制、防止滥用及遵守DMCA法规等关键步骤。 ... [详细]
  • 本文探讨了如何通过Service Locator模式来简化和优化在B/S架构中的服务命名访问,特别是对于需要频繁访问的服务,如JNDI和XMLNS。该模式通过缓存机制减少了重复查找的成本,并提供了对多种服务的统一访问接口。 ... [详细]
author-avatar
花痴-耐你们_304
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有