use of io.netty.handler.codec.http.QueryStringDecoder in project sidewinder by srotya.
the class HTTPDataPointDecoder method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
try {
if (ResourceMonitor.getInstance().isReject()) {
logger.warning("Write rejected, insufficient memory");
if (writeResponse(request, ctx)) {
ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
}
return;
}
if (msg instanceof HttpRequest) {
HttpRequest request = this.request = (HttpRequest) msg;
if (HttpUtil.is100ContinueExpected(request)) {
send100Continue(ctx);
}
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.uri());
path = queryStringDecoder.path();
Map<String, List<String>> params = queryStringDecoder.parameters();
if (!params.isEmpty()) {
for (Entry<String, List<String>> p : params.entrySet()) {
String key = p.getKey();
if (key.equalsIgnoreCase("db")) {
dbName = p.getValue().get(0);
}
}
}
if (path != null && path.contains("query")) {
Gson gson = new Gson();
JsonObject obj = new JsonObject();
JsonArray ary = new JsonArray();
ary.add(new JsonObject());
obj.add("results", ary);
responseString.append(gson.toJson(obj));
}
}
if (msg instanceof HttpContent) {
HttpContent httpContent = (HttpContent) msg;
ByteBuf byteBuf = httpContent.content();
if (byteBuf.isReadable()) {
requestBuffer.append(byteBuf.toString(CharsetUtil.UTF_8));
}
if (msg instanceof LastHttpContent) {
if (dbName == null) {
responseString.append("Invalid database null");
logger.severe("Invalid database null");
} else {
String payload = requestBuffer.toString();
logger.fine("Request:" + payload);
List<Point> dps = InfluxDecoder.pointsFromString(dbName, payload);
meter.inc(dps.size());
for (Point dp : dps) {
try {
engine.writeDataPointWithLock(dp, false);
logger.fine("Accepted:" + dp + "\t" + new Date(dp.getTimestamp()));
} catch (IOException e) {
logger.fine("Dropped:" + dp + "\t" + e.getMessage());
responseString.append("Dropped:" + dp);
}
}
}
if (writeResponse(request, ctx)) {
ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of io.netty.handler.codec.http.QueryStringDecoder in project hadoop by apache.
the class FSImageHandler method channelRead0.
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpRequest request) throws Exception {
if (request.getMethod() != HttpMethod.GET) {
DefaultHttpResponse resp = new DefaultHttpResponse(HTTP_1_1, METHOD_NOT_ALLOWED);
resp.headers().set(CONNECTION, CLOSE);
ctx.write(resp).addListener(ChannelFutureListener.CLOSE);
return;
}
QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
final String op = getOp(decoder);
final String content;
String path = getPath(decoder);
switch(op) {
case "GETFILESTATUS":
content = image.getFileStatus(path);
break;
case "LISTSTATUS":
content = image.listStatus(path);
break;
case "GETACLSTATUS":
content = image.getAclStatus(path);
break;
case "GETXATTRS":
List<String> names = getXattrNames(decoder);
String encoder = getEncoder(decoder);
content = image.getXAttrs(path, names, encoder);
break;
case "LISTXATTRS":
content = image.listXAttrs(path);
break;
case "GETCONTENTSUMMARY":
content = image.getContentSummary(path);
break;
default:
throw new IllegalArgumentException("Invalid value for webhdfs parameter" + " \"op\"");
}
LOG.info("op=" + op + " target=" + path);
DefaultFullHttpResponse resp = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(content.getBytes(Charsets.UTF_8)));
resp.headers().set(CONTENT_TYPE, APPLICATION_JSON_UTF8);
resp.headers().set(CONTENT_LENGTH, resp.content().readableBytes());
resp.headers().set(CONNECTION, CLOSE);
ctx.write(resp).addListener(ChannelFutureListener.CLOSE);
}
use of io.netty.handler.codec.http.QueryStringDecoder in project asterixdb by apache.
the class BaseRequest method create.
public static IServletRequest create(FullHttpRequest request) throws IOException {
QueryStringDecoder decoder = new QueryStringDecoder(request.uri());
Map<String, List<String>> param = decoder.parameters();
return new BaseRequest(request, param);
}
use of io.netty.handler.codec.http.QueryStringDecoder in project BRFS by zhangnianli.
the class DiskNettyHttpRequestHandler method requestReceived.
@Override
public void requestReceived(ChannelHandlerContext ctx, FullHttpRequest request) {
LOG.debug("handle request[{}:{}]", request.method(), request.uri());
MessageHandler<DiskMessage> handler = methodToOps.get(request.method());
if (handler == null) {
ResponseSender.sendError(ctx, HttpResponseStatus.METHOD_NOT_ALLOWED);
return;
}
QueryStringDecoder decoder = new QueryStringDecoder(request.uri(), CharsetUtil.UTF_8, true);
DiskMessage message = new DiskMessage();
message.setFilePath(decoder.path());
Map<String, String> params = new HashMap<String, String>();
for (String paramName : decoder.parameters().keySet()) {
params.put(paramName, decoder.parameters().get(paramName).get(0));
}
message.setParams(params);
byte[] data = new byte[request.content().readableBytes()];
request.content().readBytes(data);
message.setData(data);
handler.handle(message, new DefaultHandleResultCallback(ctx));
}
use of io.netty.handler.codec.http.QueryStringDecoder in project BRFS by zhangnianli.
the class StorageNameRequestHandler method requestReceived.
@Override
public void requestReceived(ChannelHandlerContext ctx, FullHttpRequest request) {
LOG.debug("handle request[{}:{}]", request.method(), request.uri());
MessageHandler<StorageNameMessage> handler = handlers.get(request.method().name());
if (handler == null) {
ResponseSender.sendError(ctx, HttpResponseStatus.METHOD_NOT_ALLOWED);
return;
}
QueryStringDecoder decoder = new QueryStringDecoder(request.uri(), CharsetUtil.UTF_8, true);
StorageNameMessage message = new StorageNameMessage();
message.setName(parseName(decoder.path()));
System.out.println("name----" + message.getName());
byte[] data = new byte[request.content().readableBytes()];
request.content().readBytes(data);
// TODO set other properties of StorageNameMessage
handler.handle(message, new DefaultHandleResultCallback(ctx));
}
Aggregations