Exemplo n.º 1
0
  @Override
  protected synchronized RequestProcessor getRequestProcessor(ModuleConfig moduleConfig)
      throws ServletException {

    ServletContext servletContext = getServletContext();

    String key = Globals.REQUEST_PROCESSOR_KEY + moduleConfig.getPrefix();

    RequestProcessor requestProcessor = (RequestProcessor) servletContext.getAttribute(key);

    if (requestProcessor == null) {
      ControllerConfig controllerConfig = moduleConfig.getControllerConfig();

      try {
        requestProcessor =
            (RequestProcessor)
                InstanceFactory.newInstance(
                    ClassLoaderUtil.getPortalClassLoader(), controllerConfig.getProcessorClass());
      } catch (Exception e) {
        throw new ServletException(e);
      }

      requestProcessor.init(this, moduleConfig);

      servletContext.setAttribute(key, requestProcessor);
    }

    return requestProcessor;
  }
  /**
   * Initialize this request processor instance.
   *
   * @param servlet The ActionServlet we are associated with
   * @param moduleConfig The ModuleConfig we are associated with.
   * @throws ServletException If an error occurs during initialization
   */
  public void init(ActionServlet servlet, ModuleConfig moduleConfig) throws ServletException {
    LOG.info(
        "Initializing composable request processor for module prefix '"
            + moduleConfig.getPrefix()
            + "'");
    super.init(servlet, moduleConfig);

    initCatalogFactory(servlet, moduleConfig);

    ControllerConfig controllerConfig = moduleConfig.getControllerConfig();

    String catalogName = controllerConfig.getCatalog();

    catalog = this.catalogFactory.getCatalog(catalogName);

    if (catalog == null) {
      throw new ServletException("Cannot find catalog '" + catalogName + "'");
    }

    String commandName = controllerConfig.getCommand();

    command = catalog.getCommand(commandName);

    if (command == null) {
      throw new ServletException("Cannot find command '" + commandName + "'");
    }

    this.setActionContextClassName(controllerConfig.getProperty(ACTION_CONTEXT_CLASS));
  }
 /** Clean up in preparation for a shutdown of this application. */
 public void destroy() {
   super.destroy();
   catalogFactory = null;
   catalog = null;
   command = null;
   actionContextClass = null;
   servletActionContextConstructor = null;
 }
Exemplo n.º 4
0
  /** Hooks into populate process to call form populate method if form is an instanceof PojoForm. */
  @Override
  protected void processPopulate(
      HttpServletRequest request,
      HttpServletResponse response,
      ActionForm form,
      ActionMapping mapping)
      throws ServletException {
    if (form instanceof KualiForm) {
      // Add the ActionForm to GlobalVariables
      // This will allow developers to retrieve both the Document and any
      // request parameters that are not
      // part of the Form and make them available in ValueFinder classes
      // and other places where they are needed.
      KNSGlobalVariables.setKualiForm((KualiForm) form);
    }

    // if not PojoForm, call struts populate
    if (!(form instanceof PojoForm)) {
      super.processPopulate(request, response, form, mapping);
      return;
    }

    final String previousRequestGuid =
        request.getParameter(
            KualiRequestProcessor.PREVIOUS_REQUEST_EDITABLE_PROPERTIES_GUID_PARAMETER_NAME);

    ((PojoForm) form).clearEditablePropertyInformation();
    ((PojoForm) form).registerStrutsActionMappingScope(mapping.getScope());

    String multipart = mapping.getMultipartClass();
    if (multipart != null) {
      request.setAttribute(Globals.MULTIPART_KEY, multipart);
    }

    form.setServlet(this.servlet);
    form.reset(mapping, request);

    ((PojoForm) form).setPopulateEditablePropertiesGuid(previousRequestGuid);
    // call populate on ActionForm
    ((PojoForm) form).populate(request);
    request.setAttribute("UnconvertedValues", ((PojoForm) form).getUnconvertedValues().keySet());
    request.setAttribute("UnconvertedHash", ((PojoForm) form).getUnconvertedValues());
  }
Exemplo n.º 5
0
  /**
   * Hooks into validate to catch any errors from the populate, and translate the ErrorMap to
   * ActionMessages.
   */
  @Override
  protected boolean processValidate(
      HttpServletRequest request,
      HttpServletResponse response,
      ActionForm form,
      ActionMapping mapping)
      throws IOException, ServletException, InvalidCancelException {

    // skip form validate if we had errors from populate
    if (GlobalVariables.getMessageMap().hasNoErrors()) {
      if (form == null) {
        return (true);
      }
      // Was this request cancelled?
      if (request.getAttribute(Globals.CANCEL_KEY) != null) {
        if (LOG.isDebugEnabled()) {
          LOG.debug(" Cancelled transaction, skipping validation");
        }
        return (true);
      }

      // Has validation been turned off for this mapping?
      if (!mapping.getValidate()) {
        return (true);
      }

      // call super to call forms validate
      super.processValidate(request, response, form, mapping);
    }

    publishMessages(request);
    if (!GlobalVariables.getMessageMap().hasNoErrors()) {
      // Special handling for multipart request
      if (form.getMultipartRequestHandler() != null) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("  Rolling back multipart request");
        }
        form.getMultipartRequestHandler().rollback();
      }

      // Fix state that could be incorrect because of validation failure
      if (form instanceof PojoForm) {
        ((PojoForm) form).processValidationFail();
      }

      // Was an input path (or forward) specified for this mapping?
      String input = mapping.getInput();
      if (input == null) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("  Validation failed but no input form available");
        }
        response.sendError(
            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
            getInternal().getMessage("noInput", mapping.getPath()));
        return (false);
      }

      if (moduleConfig.getControllerConfig().getInputForward()) {
        ForwardConfig forward = mapping.findForward(input);
        processForwardConfig(request, response, forward);
      } else {
        internalModuleRelativeForward(input, request, response);
      }

      return (false);
    }
    return true;
  }
  public void process(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    Orgao orgao = null;
    OrgaoCtrl orgaoCtrl = new OrgaoCtrl(daoFactory);

    // Instancia a sessao
    HttpSession session = request.getSession(true);

    boolean flagPesquisa = false;

    // se houverem dados de pesquisa na sessao entao starta o flag
    if (session.getAttribute("possuiPesquisa") != null) {
      if (session.getAttribute("possuiPesquisa").equals("sim")) {
        flagPesquisa = true;
      }
    }

    if (flagPesquisa) {

      int caminho = 0;

      // qq um desses links preservam os dados da sessao
      if ((request.getServletPath().equals("/andamento/ExibeMsgPorRespons.do"))
          || (request.getServletPath().equals("/andamento/ConsultaSolucoes.do"))
          || (request.getServletPath().equals("/andamento/ConsultarBancoScriptsMsg.do"))
          || (request.getServletPath().equals("/andamento/RedirecionarMensagem.do"))
          || (request.getServletPath().equals("/andamento/ReclassificarMensagem.do"))
          || (request.getServletPath().equals("/andamento/ConfirmaResposta.do"))
          || (request.getServletPath().equals("/andamento/RespondeAcionamento.do"))
          || (request.getServletPath().equals("/andamento/ConsultaMsgPorRespons.do"))
          || (request.getServletPath().equals("/andamento/SalvaRascunhoResp.do"))
          || (request.getServletPath().equals("/andamento/ListaMsgPorRespons.do"))
          || (request.getServletPath().equals("/andamento/ConfirmaRedirecionarMensagem.do"))) {

        caminho = 1;
      }

      switch (caminho) {
        case 0:
          // caso saia da tela, então a sessao é limpa
          limpaSessao(request, session);
          break;
        case 1:
          break;
      }
    }

    // obter o ID da sessão
    String orgaoSessionId = request.getParameter(Constants.ID_SESSAO_ORGAO);
    if (orgaoSessionId == null) {

      // verificar se a sessão expirou
      if (request.getSession() == null) {
        doForward(Constants.LOGIN_EXPIRED_ACTION, request, response);
        return;
      }

      // tentar obter o ID do atributo correspondente na sessão
      orgaoSessionId = (String) request.getSession().getAttribute(Constants.ID_SESSAO_ORGAO);

      // se não achou o ID no atributo da sessão, procurar pelo cookie
      if (orgaoSessionId == null) {
        Cookie[] cookies = request.getCookies();
        for (int i = 0; (cookies != null && i < cookies.length); i++) {
          Cookie cookie = cookies[i];
          if (cookie.getName().equals(Constants.ID_SESSAO_ORGAO)) {
            orgaoSessionId = cookie.getValue();
          }
        }
      }
    }

    // se não obteve o ID, redirecionar o usuário para página adequada
    if (orgaoSessionId == null) {
      doForward(Constants.NOT_FOUND_PAGE, request, response);
      return;
    }

    // obter o órgão
    orgao = orgaoCtrl.get(orgaoSessionId);
    if (orgao == null) {
      doForward(Constants.NOT_FOUND_PAGE, request, response);
      return;
    }

    /* adiciono o sessionId na sessão */
    HttpSession ses = request.getSession(true);
    ses.setAttribute(Constants.ID_SESSAO_ORGAO, orgaoSessionId);

    ses.setAttribute("_ORGAO_", new OrgaoDto(orgao));

    /* adiciono um cookie com o id do orgão */
    if (orgaoSessionId != null) {
      Cookie cookie = new Cookie(Constants.ID_SESSAO_ORGAO, orgaoSessionId);
      cookie.setPath("/");
      response.addCookie(cookie);
    }

    /*
     * adiciono um cookie com um identificador único para verificação do
     * timeout da sessão
     */
    if (request.getSession().getAttribute(Constants.PA_FUNCIONARIO) != null) {
      Cookie cookie = new Cookie(Constants.PA_EXPIRE, String.valueOf(System.currentTimeMillis()));
      cookie.setPath("/");
      response.addCookie(cookie);
    }

    /* adiciono o layout à sessão */
    setOrgaoLayout(request, orgao);

    try {

      ConfiguracoesOrgao configuracaoes = orgao.getConfiguracoes();
      request.setAttribute("configuracoes", configuracaoes);

      if (configuracaoes.getNotificacaoEmail() != null
          && configuracaoes.getNotificacaoEmail().equals("S")) {

        if ((OuvidoriaScheduler.sched == null)
            || (OuvidoriaScheduler.sched != null && !OuvidoriaScheduler.sched.isStarted())) {

          OuvidoriaScheduler.init(request);
        }
      }

    } catch (SchedulerException se) {

      se.printStackTrace();

    } catch (Exception e) {

      e.printStackTrace();
    }

    super.process(request, response);
  }