Exemplo n.º 1
0
  @Override
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    try {
      AuthTokenUtil.checkCSRFToken(request, SessionClickAction.class.getName());

      HttpSession session = request.getSession();

      Enumeration<String> enu = request.getParameterNames();

      boolean useHttpSession = ParamUtil.getBoolean(request, "useHttpSession");

      while (enu.hasMoreElements()) {
        String name = enu.nextElement();

        if (!name.equals("doAsUserId") && !name.equals("p_auth")) {
          String value = ParamUtil.getString(request, name);

          if (useHttpSession) {
            SessionClicks.put(session, name, value);
          } else {
            SessionClicks.put(request, name, value);
          }
        }
      }

      String value = getValue(request);

      if (value != null) {
        String cmd = ParamUtil.getString(request, Constants.CMD);

        if (cmd.equals("get")) {
          response.setContentType(ContentTypes.TEXT_PLAIN);
        } else {
          response.setContentType(ContentTypes.APPLICATION_JSON);
        }

        ServletOutputStream servletOutputStream = response.getOutputStream();

        servletOutputStream.print(value);
      }

      return null;
    } catch (Exception e) {
      PortalUtil.sendError(e, request, response);

      return null;
    }
  }
Exemplo n.º 2
0
  protected String getValue(HttpServletRequest request) {
    HttpSession session = request.getSession();

    String cmd = ParamUtil.getString(request, Constants.CMD);

    boolean useHttpSession = ParamUtil.getBoolean(request, "useHttpSession");

    if (cmd.equals("get")) {
      String key = ParamUtil.getString(request, "key");
      String value = StringPool.BLANK;

      if (useHttpSession) {
        value = SessionClicks.get(session, key, cmd);
      } else {
        value = SessionClicks.get(request, key, cmd);
      }

      return value;
    } else if (cmd.equals("getAll")) {
      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      String[] keys = request.getParameterValues("key");

      for (String key : keys) {
        String value = StringPool.BLANK;

        if (useHttpSession) {
          value = SessionClicks.get(session, key, cmd);
        } else {
          value = SessionClicks.get(request, key, cmd);
        }

        jsonObject.put(key, value);
      }

      return jsonObject.toString();
    }

    return null;
  }