use of com.bonree.brfs.disknode.server.netty.MessageHandler 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));
}
Aggregations