@Override
    public void createContent() throws Exception {
      try {
        IContentItem responseContentItem =
            outputHandler.getOutputContentItem(
                IOutputHandler.RESPONSE, IOutputHandler.CONTENT, null, null);
        // mime type setting will blow up since servlet api used by grizzly is too old
        try {
          responseContentItem.setMimeType("text/plain");
        } catch (Throwable t) {
        }
        OutputStream outputStream = responseContentItem.getOutputStream(null);
        IParameterProvider pathParams = parameterProviders.get("path");
        String command = pathParams.getStringParameter("cmd", "");

        Object testParamValue =
            parameterProviders.get(IParameterProvider.SCOPE_REQUEST).getParameter("testParam");
        assertEquals("testParam is missing from request", "testParamValue", testParamValue);

        IOUtils.write(
            "hello this is service content generator servicing command " + command, outputStream);
        outputStream.close();
      } catch (Throwable t) {
        t.printStackTrace();
      }
    }
  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();
  }
  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;
  }
 @Override
 public void createContent() throws Exception {
   try {
     IContentItem responseContentItem =
         outputHandler.getOutputContentItem(
             IOutputHandler.RESPONSE, IOutputHandler.CONTENT, null, null);
     // mime type setting will blow up since servlet api used by grizzly is too old
     try {
       responseContentItem.setMimeType("text/plain");
     } catch (Throwable t) {
     }
     OutputStream outputStream = responseContentItem.getOutputStream(null);
     IOUtils.write("hello viewer content generator", outputStream);
     outputStream.close();
   } catch (Throwable t) {
     t.printStackTrace();
   }
 }
  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();
  }
 static void deleteContentItem(IContentItem contentItem, IUnifiedRepository unifiedRepository) {
   if (contentItem instanceof RepositoryFileContentItem) {
     String path = contentItem.getPath();
     RepositoryFile repositoryFile = unifiedRepository.getFile(path);
     // repositoryFile can be null if we have not access or file does not exist
     if (repositoryFile != null) {
       unifiedRepository.deleteFile(repositoryFile.getId(), true, null);
     }
   } else if (contentItem instanceof FileContentItem) {
     // Files in the file system must not be deleted here
     String path = ((FileContentItem) contentItem).getFile().getName();
     logger.warn(Messages.getInstance().getString("XactionUtil.SKIP_REMOVING_OUTPUT_FILE", path));
   }
 }