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

    String text = null;

    try {
      text = getText(actionMapping, actionForm, request, response);
    } catch (Exception e) {
      PortalUtil.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e, request, response);

      return null;
    }

    response.setContentType(ContentTypes.TEXT_PLAIN_UTF8);
    response.setHeader(HttpHeaders.CACHE_CONTROL, HttpHeaders.CACHE_CONTROL_NO_CACHE_VALUE);

    try (PrintWriter printWriter = response.getWriter()) {
      printWriter.write(text);
    }

    return null;
  }
Ejemplo n.º 2
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;
    }
  }
Ejemplo n.º 3
0
  @Override
  public void service(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    try {
      I18nData i18nData = getI18nData(request);

      if ((i18nData == null) || !PortalUtil.isValidResourceId(i18nData.getPath())) {

        PortalUtil.sendError(
            HttpServletResponse.SC_NOT_FOUND, new NoSuchLayoutException(), request, response);
      } else {
        request.setAttribute(WebKeys.I18N_LANGUAGE_CODE, i18nData.getLanguageCode());
        request.setAttribute(WebKeys.I18N_LANGUAGE_ID, i18nData.getLanguageId());
        request.setAttribute(WebKeys.I18N_PATH, i18nData.getI18nPath());

        Locale locale = LocaleUtil.fromLanguageId(i18nData.getLanguageId(), true, false);

        HttpSession session = request.getSession();

        session.setAttribute(Globals.LOCALE_KEY, locale);

        LanguageUtil.updateCookie(request, response, locale);

        ServletContext servletContext = getServletContext();

        RequestDispatcher requestDispatcher =
            servletContext.getRequestDispatcher(i18nData.getPath());

        requestDispatcher.forward(request, response);
      }
    } catch (Exception e) {
      _log.error(e, e);

      PortalUtil.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e, request, response);
    }
  }