Esempio n. 1
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  @SuppressWarnings("unchecked")
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    logger.info(String.format("register page @ %s", request.getSession().getId()));

    PrintWriter writer = response.getWriter();

    // 获取画面名称
    String pageName = request.getParameter(FaceConstants.REQ_K_PAGENAME);
    // 获取注册点json字符串
    String tagsJson = request.getParameter(FaceConstants.REQ_K_TAGS);

    if (logger.isDebugEnabled()) {
      logger.debug("register page " + pageName);
    }

    // resolve the tags
    List<Tag> regTags = resolveTags(tagsJson);

    // check if the system already load this page
    Map<String, Page> container =
        (Map<String, Page>) getServletContext().getAttribute(FaceConstants.CTX_K_PAGES);
    Page page = container.get(pageName);
    if (page == null) {
      page = new Page();
      page.setPageName(pageName);
      container.put(pageName, page); // 加入context中
    }
    // 更新当前画面所有tag点
    page.setTags(regTags);

    HttpSession session = request.getSession();
    Map<String, SessionPage> seContainer =
        (Map<String, SessionPage>) session.getAttribute(FaceConstants.SEN_K_PAGES);
    // 判断session中是否包含该page
    if (seContainer == null) {
      // 当前sessionContainer为空
      seContainer = new HashMap<String, SessionPage>();
      // 添加sessionContainter到session对象中
      session.setAttribute(FaceConstants.SEN_K_PAGES, seContainer);
    }

    SessionPage sessionPage = seContainer.get(pageName);

    if (sessionPage == null) {
      // 如果当前session无该页面对象 新建page并加入
      // 用已有的context page 构建sessionpage对象
      SessionPage regPage = new SessionPage(container.get(pageName));
      seContainer.put(pageName, regPage);
    }

    logger.info("register done");
    writer.write(FaceCommonUtils.getInfoMsg(FaceConstants.IC_OK));
    writer.flush();
  }
Esempio n. 2
0
 /** 控制命令下发 */
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   HttpSession session = request.getSession();
   PrintWriter writer = response.getWriter();
   // 获取用户信息
   User user = (User) session.getAttribute(FaceConstants.SEN_K_USER);
   // 获取控制命令内容
   String cmdStr = request.getParameter(FaceConstants.REQ_K_CONTROL);
   Gson gson = new Gson();
   UserControlCmd userControlCmd = gson.fromJson(cmdStr, UserControlCmd.class);
   try {
     user.sendCommand(userControlCmd);
   } catch (Exception e) {
     logger.warn(ExceptionUtils.getStackTrace(e));
     logger.warn(
         String.format(
             "user[%s] send control command failed.[ec=%s]", user.getUsername(), e.getMessage()));
     writer.write(FaceCommonUtils.getErrorMsg(e.getMessage()));
     writer.flush();
   }
 }