Пример #1
0
  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;

    long start = 0;
    if (enabled && filter(req)) {
      start = System.currentTimeMillis();
    }
    chain.doFilter(request, response);
    if (enabled && filter(req)) {
      long end = System.currentTimeMillis();
      User user = OnlineUserService.getUser(req.getSession().getId());
      ProcessTime logger = new ProcessTime();
      logger.setUsername(user.getUsername());
      logger.setUserIP(req.getRemoteAddr());
      try {
        logger.setServerIP(InetAddress.getLocalHost().getHostAddress());
      } catch (UnknownHostException ex) {
        LOG.error("保存日志出错(Error in saving log)", ex);
      }
      logger.setAppName(SystemListener.getContextPath());
      String resource = req.getRequestURI().replace(logger.getAppName(), "");
      logger.setResource(resource);
      logger.setStartTime(new Date(start));
      logger.setEndTime(new Date(end));
      logger.setProcessTime(end - start);
      LogQueue.addLog(logger);
    }
  }
Пример #2
0
  protected void genernateCaptchaImage(
      final HttpServletRequest request, final HttpServletResponse response) {

    ServletUtils.setDisableCacheHeader(response);
    response.setContentType("image/png");
    ServletOutputStream out = null;
    try {
      out = response.getOutputStream();
      String captchaId = request.getSession(true).getId();
      BufferedImage challenge =
          (BufferedImage) captchaService.getChallengeForID(captchaId, request.getLocale());
      // String writerNames[] = ImageIO.getWriterFormatNames();
      ImageIO.write(challenge, "png", out);
      out.flush();
    } catch (IOException | CaptchaServiceException e) {
      log.error("生成验证码出错", e);
    } finally {
      try {
        out.close();
      } catch (IOException e) {
        log.error("生成验证码出错", e);
      }
    }
  }