Example #1
0
 protected void setUpLegacyContext() {
   if (getTestMethod().getAnnotation(Legacy.class) != null
       || getClass().getAnnotation(Legacy.class) != null) {
     LegacyUtils.beginLegacyContext();
     legacyContext = true;
   }
 }
  @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();
    }
  }