use of com.bonree.brfs.disknode.server.handler.DiskMessage in project BRFS by zhangnianli.
the class DiskJettyHttpRequestHandler method handle.
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
LOG.debug("handle request[{}:{}]", request.getMethod(), target);
MessageHandler handler = methodToOps.get(request.getMethod());
if (handler == null) {
baseRequest.setHandled(true);
responseError(response, HttpStatus.Code.METHOD_NOT_ALLOWED);
return;
}
DiskMessage message = new DiskMessage();
message.setFilePath(target);
int contentLength = request.getContentLength();
System.out.println("content length############" + contentLength);
byte[] data = new byte[Math.max(contentLength, 0)];
if (request.getContentLength() > 0) {
InputUtils.readBytes(request.getInputStream(), data, 0, data.length);
System.out.println(new String(data));
}
message.setData(data);
Map<String, String> params = new HashMap<String, String>();
for (String paramName : request.getParameterMap().keySet()) {
params.put(paramName, request.getParameter(paramName));
System.out.println(paramName + "---" + request.getParameter(paramName));
}
message.setParams(params);
baseRequest.setHandled(true);
// 采用异步方式处理Http响应
AsyncContext context = request.startAsync();
System.out.println("########################START HANDLING##########################");
handler.handle(message, new DefaultHandleResultCallback(context));
}
use of com.bonree.brfs.disknode.server.handler.DiskMessage 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));
}
Aggregations