模块 org.redkale

类 HttpServlet

    • 构造器详细资料

      • HttpServlet

        public HttpServlet()
    • 方法详细资料

      • finish404

        protected void finish404​(HttpRequest request,
                                 HttpResponse response)
                          throws IOException
        提供404状态码的可定制接口
        参数:
        request - HttpRequest
        response - HttpResponse
        抛出:
        IOException - IOException
        从以下版本开始:
        2.8.0
      • finish405

        protected void finish405​(HttpRequest request,
                                 HttpResponse response)
                          throws IOException
        提供405状态码的可定制接口
        参数:
        request - HttpRequest
        response - HttpResponse
        抛出:
        IOException - IOException
        从以下版本开始:
        2.8.0
      • preExecute

        protected void preExecute​(HttpRequest request,
                                  HttpResponse response)
                           throws IOException
        预执行方法,在execute方法之前运行,设置当前用户信息,或者加入常规统计和基础检测,例如 :
              @Override
              public void preExecute(final HttpRequest request, final HttpResponse response) throws IOException {
                  //设置当前用户信息
                  final String sessionid = request.getSessionid(false);
                  if (sessionid != null) request.setCurrentUserid(userService.currentUserid(sessionid));
        
                  if (finer) response.recycleListener((req, resp) -> {  //记录处理时间比较长的请求
                      long e = System.currentTimeMillis() - ((HttpRequest) req).getCreateTime();
                      if (e > 200) logger.finer("http-execute-cost-time: " + e + " ms. request = " + req);
                  });
                  response.nextEvent();
              }
         

        参数:
        request - HttpRequest
        response - HttpResponse
        抛出:
        IOException - IOException
      • authenticate

        protected void authenticate​(HttpRequest request,
                                    HttpResponse response)
                             throws IOException
        用户登录或权限验证, 注解为@HttpMapping.auth == true 的方法会执行authenticate方法, 若验证成功则必须调用response.nextEvent();进行下一步操作, 例如:
              @Override
              public void authenticate(HttpRequest request, HttpResponse response) throws IOException {
                  Serializable userid = request.currentUserid();
                  if (userid == null) {
                      response.finishJson(RET_UNLOGIN);
                      return;
                  }
                  response.nextEvent();
              }
         

        参数:
        request - HttpRequest
        response - HttpResponse
        抛出:
        IOException - IOException