Exemplo n.º 1
0
  @Override
  public void process(final HttpServletRequest request, final HttpServletResponse response)
      throws IOException, ServletException {
    // indicates that we are running in legacy KNS context
    LegacyUtils.beginLegacyContext();
    try {
      if (LOG.isInfoEnabled()) {
        LOG.info(
            new StringBuffer("Started processing request: '")
                .append(request.getRequestURI())
                .append("' w/ query string: '")
                .append(request.getQueryString())
                .append("'"));
      }

      try {
        strutsProcess(request, response);
      } catch (FileUploadLimitExceededException e) {
        ActionForward actionForward =
            processException(request, response, e, e.getActionForm(), e.getActionMapping());
        processForwardConfig(request, response, actionForward);
      } finally {
        KNSGlobalVariables.setKualiForm(null);
      }

      try {
        ActionForm form = WebUtils.getKualiForm(request);

        if (form != null && form instanceof KualiDocumentFormBase) {
          String docId = ((KualiDocumentFormBase) form).getDocId();
          if (docId != null) {
            MDC.put(MDC_DOC_ID, docId);
          }
        }

        String refreshCaller = request.getParameter(KRADConstants.REFRESH_CALLER);
        if (form != null
            && KualiDocumentFormBase.class.isAssignableFrom(form.getClass())
            && !KRADConstants.QUESTION_REFRESH.equalsIgnoreCase(refreshCaller)) {
          KualiDocumentFormBase docForm = (KualiDocumentFormBase) form;
          Document document = docForm.getDocument();
          String docFormKey = docForm.getFormKey();

          UserSession userSession =
              (UserSession) request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY);

          if (WebUtils.isDocumentSession(document, docForm)) {
            getSessionDocumentService()
                .setDocumentForm(docForm, userSession, request.getRemoteAddr());
          }

          Boolean exitingDocument = (Boolean) request.getAttribute(KRADConstants.EXITING_DOCUMENT);

          if (exitingDocument != null && exitingDocument.booleanValue()) {
            // remove KualiDocumentFormBase object from session and
            // table.
            getSessionDocumentService()
                .purgeDocumentForm(
                    docForm.getDocument().getDocumentNumber(),
                    docFormKey,
                    userSession,
                    request.getRemoteAddr());
          }
        }

        if (LOG.isInfoEnabled()) {
          LOG.info(
              new StringBuffer("Finished processing request: '")
                  .append(request.getRequestURI())
                  .append("' w/ query string: '")
                  .append(request.getQueryString())
                  .append("'"));
        }

      } finally {
        // MDC docId key is set above, and also during super.process() in the call to
        // processActionForm
        MDC.remove(MDC_DOC_ID);
      }
    } finally {
      LegacyUtils.endLegacyContext();
    }
  }
Exemplo n.º 2
0
  /**
   * Checks for return from a lookup or question, and restores the action form stored under the
   * request parameter docFormKey.
   */
  @Override
  protected ActionForm processActionForm(
      HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) {

    String documentNumber = getDocumentNumber(request);
    if (documentNumber != null) {
      MDC.put(MDC_DOC_ID, documentNumber);
    }

    UserSession userSession =
        (UserSession) request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY);

    String docFormKey = request.getParameter(KRADConstants.DOC_FORM_KEY);
    String methodToCall = request.getParameter(KRADConstants.DISPATCH_REQUEST_PARAMETER);
    String refreshCaller = request.getParameter(KRADConstants.REFRESH_CALLER);
    //		String searchListRequestKey = request.getParameter(KRADConstants.SEARCH_LIST_REQUEST_KEY);
    String documentWebScope = request.getParameter(KRADConstants.DOCUMENT_WEB_SCOPE);

    if (mapping.getPath().startsWith(KRADConstants.REFRESH_MAPPING_PREFIX)
        || KRADConstants.RETURN_METHOD_TO_CALL.equalsIgnoreCase(methodToCall)
        || KRADConstants.QUESTION_REFRESH.equalsIgnoreCase(refreshCaller)
        || KRADConstants.TEXT_AREA_REFRESH.equalsIgnoreCase(refreshCaller)
        || KRADConstants.SESSION_SCOPE.equalsIgnoreCase(documentWebScope)) {
      ActionForm form = null;
      // check for search result storage and clear
      GlobalVariables.getUserSession().removeObjectsByPrefix(KRADConstants.SEARCH_LIST_KEY_PREFIX);

      // We put different type of forms such as document form, lookup form
      // in session but we only store document form in
      // database.
      if (userSession.retrieveObject(docFormKey) != null) {
        LOG.debug("getDecomentForm KualiDocumentFormBase from session");
        form = (ActionForm) userSession.retrieveObject(docFormKey);
      } else if (StringUtils.isNotBlank(documentNumber)) {
        form =
            getSessionDocumentService()
                .getDocumentForm(documentNumber, docFormKey, userSession, request.getRemoteAddr());
      }
      request.setAttribute(mapping.getAttribute(), form);
      if (!KRADConstants.SESSION_SCOPE.equalsIgnoreCase(documentWebScope)) {
        userSession.removeObject(docFormKey);
      }
      // we should check whether this is a multipart request because we
      // could have had a combination of query parameters and a multipart
      // request
      String contentType = request.getContentType();
      String method = request.getMethod();
      if (("POST".equalsIgnoreCase(method)
          && contentType != null
          && contentType.startsWith("multipart/form-data"))) {
        // this method parses the multipart request and adds new
        // non-file parameters into the request
        WebUtils.getMultipartParameters(request, null, form, mapping);
      }
      // The form can be null if the document is not a session document
      if (form != null) {
        return form;
      }
    }

    // Rice has the ability to limit file upload sizes on a per-form basis,
    // so the max upload sizes may be accessed by calling methods on
    // PojoFormBase.
    // This requires that we are able know the file upload size limit (i.e.
    // retrieve a form instance) before we parse a mulitpart request.
    ActionForm form = super.processActionForm(request, response, mapping);

    // for sessiondocument with multipart request
    String contentType = request.getContentType();
    String method = request.getMethod();

    if ("GET".equalsIgnoreCase(method)
        && StringUtils.isNotBlank(methodToCall)
        && form instanceof PojoForm
        && ((PojoForm) form)
            .getMethodToCallsToBypassSessionRetrievalForGETRequests()
            .contains(methodToCall)) {
      return createNewActionForm(mapping, request);
    }

    // if we have a multipart request, parse it and return the stored form
    // from session if the doc form key is not blank. If it is blank, then
    // we just return the form
    // generated from the superclass processActionForm method. Either way,
    // we need to parse the mulitpart request now so that we may determine
    // what the value of the doc form key is.
    // This is generally against the contract of processActionForm, because
    // processPopulate should be responsible for parsing the mulitpart
    // request, but we need to parse it now
    // to determine the doc form key value.
    if (("POST".equalsIgnoreCase(method)
        && contentType != null
        && contentType.startsWith("multipart/form-data"))) {
      WebUtils.getMultipartParameters(request, null, form, mapping);
      docFormKey = request.getParameter(KRADConstants.DOC_FORM_KEY);
      documentWebScope = request.getParameter(KRADConstants.DOCUMENT_WEB_SCOPE);

      documentNumber = getDocumentNumber(request);

      if (KRADConstants.SESSION_SCOPE.equalsIgnoreCase(documentWebScope)
          || (form instanceof KualiDocumentFormBase
              && WebUtils.isDocumentSession(
                  ((KualiDocumentFormBase) form).getDocument(), (KualiDocumentFormBase) form))) {

        Object userSessionObject = userSession.retrieveObject(docFormKey);
        if (userSessionObject != null && userSessionObject instanceof ActionForm) {
          LOG.debug("getDocumentForm KualiDocumentFormBase from session");
          form = (ActionForm) userSessionObject;
        } else {
          ActionForm tempForm =
              getSessionDocumentService()
                  .getDocumentForm(
                      documentNumber, docFormKey, userSession, request.getRemoteAddr());
          if (tempForm != null) {
            form = tempForm;
          }
        }

        request.setAttribute(mapping.getAttribute(), form);
        if (form != null) {
          return form;
        }
      }
    }
    return form;
  }