本文整理了Java中io.netty.handler.codec.http.FullHttpRequest.content()
方法的一些代码示例,展示了FullHttpRequest.content()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FullHttpRequest.content()
方法的具体详情如下:
包路径:io.netty.handler.codec.http.FullHttpRequest
类名称: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>() {
});
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
// Parse request parameters.
if (!paramMap.isEmpty()) {
for (Entry
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
代码示例来源: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
for (int i = 0; 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
for (int i = 0; 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();
}