예제 #1
0
  public static String postExecute(
      IRuntimeContext runtime,
      boolean debugMessages,
      boolean doWrapper,
      IOutputHandler outputHandler,
      Map<String, IParameterProvider> parameterProviders,
      HttpServletRequest request,
      HttpServletResponse response,
      List<?> messages,
      boolean deleteGeneratedFiles)
      throws Exception {
    StringBuffer buffer = new StringBuffer();

    boolean hasResponse = outputHandler.isResponseExpected();
    IContentItem responseContentItem =
        outputHandler.getOutputContentItem(
            IOutputHandler.RESPONSE, IOutputHandler.CONTENT, null, null);

    boolean success =
        (runtime != null && runtime.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS);
    boolean printSuccess = (runtime != null) && success && (!hasResponse || debugMessages);
    boolean printError = (runtime != null) && !success && !response.isCommitted();

    if (printSuccess || printError) {
      final String htmlMimeType = "text/html"; // $NON-NLS-1$
      responseContentItem.setMimeType(htmlMimeType);
      response.setContentType(htmlMimeType);
      IMessageFormatter formatter =
          PentahoSystem.get(IMessageFormatter.class, PentahoSessionHolder.getSession());

      if (printSuccess) {
        formatter.formatSuccessMessage(htmlMimeType, runtime, buffer, debugMessages, doWrapper);
      } else {
        response.resetBuffer();
        formatter.formatFailureMessage(htmlMimeType, runtime, buffer, messages);
      }
    }
    // clear files which was generated during action execution
    // http://jira.pentaho.com/browse/BISERVER-12639
    IUnifiedRepository unifiedRepository = PentahoSystem.get(IUnifiedRepository.class, null);
    if (unifiedRepository != null) {
      for (IContentItem contentItem : runtime.getOutputContentItems()) {
        if (contentItem != null) {
          try {
            contentItem.closeOutputStream();
            if (deleteGeneratedFiles) {
              deleteContentItem(contentItem, unifiedRepository);
            }
          } catch (Exception e) {
            logger.warn(
                Messages.getInstance()
                    .getString("XactionUtil.CANNOT_REMOVE_OUTPUT_FILE", contentItem.getPath()),
                e);
          }
        }
      }
    }
    return buffer.toString();
  }
예제 #2
0
  public static Document createSoapResponseDocument(
      IRuntimeContext context,
      IOutputHandler outputHandler,
      OutputStream contentStream,
      List messages) {
    Document document = createSoapDocument();
    if ((context == null) || (context.getStatus() != IRuntimeContext.RUNTIME_STATUS_SUCCESS)) {
      document
          .getRootElement()
          .element("SOAP-ENV:Body")
          .add(createSoapFaultElement(messages)); // $NON-NLS-1$
    } else {
      Element activityResponse = createActivityResponseElement();
      document.getRootElement().element("SOAP-ENV:Body").add(activityResponse); // $NON-NLS-1$

      IContentItem contentItem = outputHandler.getFeedbackContentItem();

      // hmm do we need this to be ordered?
      Set outputNames = context.getOutputNames();

      Iterator outputNameIterator = outputNames.iterator();
      while (outputNameIterator.hasNext()) {
        String outputName = (String) outputNameIterator.next();
        contentItem =
            outputHandler.getOutputContentItem(
                IOutputHandler.RESPONSE,
                IOutputHandler.CONTENT,
                context.getInstanceId(),
                "text/xml"); //$NON-NLS-1$
        if ((outputNames.size() == 1) && (contentItem != null)) {
          String mimeType = contentItem.getMimeType();
          if ((mimeType != null) && mimeType.startsWith("text/")) { // $NON-NLS-1$
            if (mimeType.equals("text/xml")) { // $NON-NLS-1$
              activityResponse.addElement(outputName).setText(contentStream.toString());
            } else if (mimeType.startsWith("text/")) { // $NON-NLS-1$
              activityResponse.addElement(outputName).addCDATA(contentStream.toString());
            }
          } else {
            Object value = context.getOutputParameter(outputName).getValue();
            if (value == null) {
              value = ""; // $NON-NLS-1$
            }
            activityResponse.add(createSoapElement(outputName, value));
          }
        } else {
          Object value = context.getOutputParameter(outputName).getValue();
          if (value == null) {
            value = ""; // $NON-NLS-1$
          }
          activityResponse.add(createSoapElement(outputName, value));
        }
      }
    }
    return document;
  }
예제 #3
0
  public static String postExecute(
      IRuntimeContext runtime,
      boolean debugMessages,
      boolean doWrapper,
      IOutputHandler outputHandler,
      Map<String, IParameterProvider> parameterProviders,
      HttpServletRequest request,
      HttpServletResponse response,
      List<?> messages)
      throws Exception {
    StringBuffer buffer = new StringBuffer();

    boolean hasResponse = outputHandler.isResponseExpected();
    IContentItem responseContentItem =
        outputHandler.getOutputContentItem(
            IOutputHandler.RESPONSE, IOutputHandler.CONTENT, null, null);

    boolean success =
        (runtime != null && runtime.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS);
    boolean printSuccess = (runtime != null) && success && (!hasResponse || debugMessages);
    boolean printError = (runtime != null) && !success && !response.isCommitted();

    if (printSuccess || printError) {
      final String htmlMimeType = "text/html"; // $NON-NLS-1$
      responseContentItem.setMimeType(htmlMimeType);
      response.setContentType(htmlMimeType);
      IMessageFormatter formatter =
          PentahoSystem.get(IMessageFormatter.class, PentahoSessionHolder.getSession());

      if (printSuccess) {
        formatter.formatSuccessMessage(htmlMimeType, runtime, buffer, debugMessages, doWrapper);
      } else {
        response.resetBuffer();
        formatter.formatFailureMessage(htmlMimeType, runtime, buffer, messages);
      }
    }
    return buffer.toString();
  }
예제 #4
0
  @SuppressWarnings("rawtypes")
  public static void createOutputFileName(RepositoryFile file, IOutputHandler outputHandler) {
    IPentahoSession userSession = PentahoSessionHolder.getSession();
    ActionSequenceJCRHelper actionHelper = new ActionSequenceJCRHelper(userSession);
    IActionSequence actionSequence =
        actionHelper.getActionSequence(
            file.getPath(), PentahoSystem.loggingLevel, RepositoryFilePermission.READ);

    String fileName = "content"; // $NON-NLS-1$
    if (actionSequence != null) {
      String title = actionSequence.getTitle();
      if ((title != null) && (title.length() > 0)) {
        fileName = title;
      } else {
        String sequenceName = actionSequence.getSequenceName();

        if ((sequenceName != null) && (sequenceName.length() > 0)) {
          fileName = sequenceName;
        } else {
          List actionDefinitionsList = actionSequence.getActionDefinitionsAndSequences();
          int i = 0;
          boolean done = false;

          while ((actionDefinitionsList.size() > i) && (!done)) {
            IActionDefinition actionDefinition = (IActionDefinition) actionDefinitionsList.get(i);
            String componentName = actionDefinition.getComponentName();
            if ((componentName != null) && (componentName.length() > 0)) {
              fileName = componentName;
              done = true;
            } else {
              ++i;
            }
          }
        }
      }
    }
    IMimeTypeListener mimeTypeListener = outputHandler.getMimeTypeListener();
    if (mimeTypeListener != null) {
      mimeTypeListener.setName(fileName);
    }
  }
예제 #5
0
  /**
   * This method executes an xaction with forcePrompt=true and outputPreference=PARAMETERS, allowing
   * for the xaction to render the secure filter appropriately when being executed in the background
   * or while being scheduled.
   *
   * @param file the location of the xaction
   * @param httpServletRequest the request object
   * @param httpServletResponse the response object
   * @param userSession the user session
   * @return potential response message
   * @throws Exception
   */
  @SuppressWarnings({"unchecked", "rawtypes"})
  public static String executeScheduleUi(
      RepositoryFile file,
      HttpServletRequest httpServletRequest,
      HttpServletResponse httpServletResponse,
      IPentahoSession userSession,
      IMimeTypeListener mimeTypeListener)
      throws Exception {
    IParameterProvider requestParams = new HttpRequestParameterProvider(httpServletRequest);
    IRuntimeContext runtime = null;
    try {
      HttpSessionParameterProvider sessionParameters =
          new HttpSessionParameterProvider(userSession);
      HttpRequestParameterProvider requestParameters =
          new HttpRequestParameterProvider(httpServletRequest);

      boolean doMessages =
          "true"
              .equalsIgnoreCase(
                  requestParams.getStringParameter(
                      "debug", "false")); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      boolean doWrapper =
          "true"
              .equalsIgnoreCase(
                  requestParams.getStringParameter(
                      "wrapper", "true")); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

      IOutputHandler outputHandler =
          createOutputHandler(
              httpServletResponse, getOutputStream(httpServletResponse, doMessages));
      if (mimeTypeListener == null) {
        mimeTypeListener = new HttpMimeTypeListener(httpServletRequest, httpServletResponse, null);
      }
      outputHandler.setMimeTypeListener(mimeTypeListener);
      outputHandler.setSession(userSession);

      Map parameterProviders = new HashMap();
      parameterProviders.put("request", requestParameters); // $NON-NLS-1$
      parameterProviders.put("session", sessionParameters); // $NON-NLS-1$
      createOutputFileName(file, outputHandler);
      int outputPreference = IOutputHandler.OUTPUT_TYPE_PARAMETERS;
      outputHandler.setOutputPreference(outputPreference);
      List messages = new ArrayList();

      // forcePrompt=true when displaying the scheduling UI
      runtime =
          executeInternal(
              file,
              requestParams,
              httpServletRequest,
              outputHandler,
              parameterProviders,
              userSession,
              true,
              messages);
      String str =
          postExecute(
              runtime,
              doMessages,
              doWrapper,
              outputHandler,
              parameterProviders,
              httpServletRequest,
              httpServletResponse,
              messages,
              false);
      return str;
    } catch (Exception e) {
      logger.error(
          Messages.getInstance()
              .getString("XactionUtil.ERROR_EXECUTING_ACTION_SEQUENCE", file.getName()),
          e); //$NON-NLS-1$
      throw e;
    } finally {
      if (runtime != null) {
        runtime.dispose();
      }
    }
  }