Search in sources :

Example 1 with MessageHandler

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));
}
Also used : MessageHandler(com.bonree.brfs.disknode.server.netty.MessageHandler) DiskMessage(com.bonree.brfs.disknode.server.handler.DiskMessage) HashMap(java.util.HashMap) AsyncContext(javax.servlet.AsyncContext)

Aggregations

DiskMessage (com.bonree.brfs.disknode.server.handler.DiskMessage)1 MessageHandler (com.bonree.brfs.disknode.server.netty.MessageHandler)1 HashMap (java.util.HashMap)1 AsyncContext (javax.servlet.AsyncContext)1