Search in sources :

Example 1 with IOutputHandler

use of org.pentaho.platform.api.engine.IOutputHandler in project pentaho-platform by pentaho.

the class AxisServiceExecutorTest method setUp.

@Before
public void setUp() throws Exception {
    StandaloneSession session = new StandaloneSession("test");
    StubServiceSetup serviceSetup = new StubServiceSetup();
    serviceSetup.setSession(session);
    AxisConfiguration axisCfg = serviceSetup.getAxisConfiguration();
    ConfigurationContext configContext = new ConfigurationContext(axisCfg);
    serviceSetup.loadServices();
    TransportInDescription tIn = new TransportInDescription(DEAFULT_TRANSPOT_PROTOCOL);
    StubTransportListener receiver = new StubTransportListener();
    tIn.setReceiver(receiver);
    axisCfg.addTransportIn(tIn);
    TransportOutDescription tOut = new TransportOutDescription(DEAFULT_TRANSPOT_PROTOCOL);
    StubTransportSender sender = new StubTransportSender();
    tOut.setSender(sender);
    axisCfg.addTransportOut(tOut);
    AxisWebServiceManager.currentAxisConfiguration = axisCfg;
    AxisWebServiceManager.currentAxisConfigContext = configContext;
    out = new ByteArrayOutputStream();
    IOutputHandler outputHandler = new SimpleOutputHandler(out, false);
    outputHandler.setMimeTypeListener(new MimeTypeListener());
    contentGenerator = new AxisServiceExecutor();
    contentGenerator.setOutputHandler(outputHandler);
    contentGenerator.setMessagesList(new ArrayList<String>());
    contentGenerator.setSession(session);
    contentGenerator.setUrlFactory(new SimpleUrlFactory(BASE_URL + "?"));
    assertNotNull("contentGenerator is null", contentGenerator);
    assertNotNull("Logger is null", contentGenerator.getLogger());
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StubTransportSender(org.pentaho.test.platform.plugin.services.webservices.StubTransportSender) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) TransportInDescription(org.apache.axis2.description.TransportInDescription) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) StubServiceSetup(org.pentaho.test.platform.plugin.services.webservices.StubServiceSetup) MimeTypeListener(org.pentaho.test.platform.plugin.services.webservices.MimeTypeListener) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) StubTransportListener(org.pentaho.test.platform.plugin.services.webservices.StubTransportListener) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) Before(org.junit.Before)

Example 2 with IOutputHandler

use of org.pentaho.platform.api.engine.IOutputHandler in project pentaho-platform by pentaho.

the class ActionSequenceAction method execute.

public void execute() throws Exception {
    IOutputHandler outputHandler = null;
    if (xactionResultsOutputStream instanceof RepositoryFileOutputStream) {
        outputHandler = new RepositoryFileOutputHandler(((RepositoryFileOutputStream) xactionResultsOutputStream));
    } else {
        outputHandler = new SimpleOutputHandler(xactionResultsOutputStream, false);
    }
    IRuntimeContext rt = null;
    try {
        ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, null);
        solutionEngine.setCreateFeedbackParameterCallback(null);
        solutionEngine.setLoggingLevel(ILogger.DEBUG);
        solutionEngine.setForcePrompt(false);
        ArrayList messages = new ArrayList();
        HashMap<String, Object> parameterProviders = new HashMap<String, Object>();
        parameterProviders.put(IParameterProvider.SCOPE_REQUEST, new SimpleParameterProvider(xActionInputParams));
        parameterProviders.put(IParameterProvider.SCOPE_SESSION, new PentahoSessionParameterProvider(PentahoSessionHolder.getSession()));
        String xactionPath = null;
        if (xactionDefInputStream instanceof RepositoryFileInputStream) {
            xactionPath = ((RepositoryFileInputStream) xactionDefInputStream).getFile().getPath();
        }
        rt = solutionEngine.execute(xactionPath, this.getClass().getName(), false, true, null, true, parameterProviders, outputHandler, null, null, messages);
        if (!outputHandler.contentDone()) {
            if ((rt != null) && (rt.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS)) {
                // set content which generated by sequence for pass it to caller
                List<IContentItem> components = new ArrayList<IContentItem>(rt.getOutputContentItems());
                setActionOutputContents(components);
                boolean isFlushed = false;
                boolean isEmpty;
                if (xactionResultsOutputStream instanceof RepositoryFileOutputStream) {
                    RepositoryFileOutputStream repositoryFileOutputStream = (RepositoryFileOutputStream) xactionResultsOutputStream;
                    isFlushed = repositoryFileOutputStream.isFlushed();
                    isEmpty = repositoryFileOutputStream.size() > 0 ? false : true;
                    String extension = RepositoryFilenameUtils.getExtension(repositoryFileOutputStream.getFilePath());
                    String mimeTypeFromExtension = MimeHelper.getMimeTypeFromExtension("." + extension);
                    if (mimeTypeFromExtension == null) {
                        // unknown type, treat it not as an extension but part of the name
                        extension = "";
                    }
                    if (extension.isEmpty() && xactionResultsOutputStream.toString().isEmpty()) {
                        repositoryFileOutputStream.setFilePath(repositoryFileOutputStream.getFilePath() + ".html");
                    }
                } else {
                    isEmpty = xactionResultsOutputStream.toString().isEmpty();
                }
                if (!isFlushed) {
                    if (isEmpty) {
                        StringBuffer buffer = new StringBuffer();
                        // $NON-NLS-1$
                        MessageFormatUtils.formatSuccessMessage("text/html", rt, buffer, false);
                        xactionResultsOutputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
                    }
                    xactionResultsOutputStream.close();
                }
            } else {
                // we need an error message...
                StringBuffer buffer = new StringBuffer();
                // $NON-NLS-1$
                MessageFormatUtils.formatFailureMessage("text/html", rt, buffer, messages);
                xactionResultsOutputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
                xactionResultsOutputStream.close();
            }
        }
    } finally {
        if (rt != null) {
            rt.dispose();
        }
    }
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) RepositoryFileOutputHandler(org.pentaho.platform.repository2.unified.fileio.RepositoryFileOutputHandler) HashMap(java.util.HashMap) PentahoSessionParameterProvider(org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream) RepositoryFileOutputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileOutputStream) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) IContentItem(org.pentaho.platform.api.repository.IContentItem) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 3 with IOutputHandler

use of org.pentaho.platform.api.engine.IOutputHandler in project pentaho-platform by pentaho.

the class SoapHelperTest method testCreateSoapResponseDocumentFromContext.

/**
 * Tests for SoapHelper.createSoapResponseDocument(IRuntimeContext, IOutputHandler, OutputStream, List)
 */
public void testCreateSoapResponseDocumentFromContext() {
    // Set up test data
    Set<Object> outputNames = new HashSet<>();
    IActionParameter actionParameter = mock(IActionParameter.class);
    when(actionParameter.getValue()).thenReturn("testValue");
    IRuntimeContext context = mock(IRuntimeContext.class);
    when(context.getOutputNames()).thenReturn(outputNames);
    when(context.getStatus()).thenReturn(IRuntimeContext.RUNTIME_STATUS_SUCCESS);
    when(context.getOutputParameter(anyString())).thenReturn(actionParameter);
    List messages = new ArrayList();
    IOutputHandler outputHandler = mock(IOutputHandler.class);
    IContentItem contentItem = mock(IContentItem.class);
    when(outputHandler.getOutputContentItem(anyString(), anyString(), anyString(), anyString())).thenReturn(contentItem);
    when(contentItem.getMimeType()).thenReturn("text/xml");
    OutputStream contentStream = mock(OutputStream.class);
    when(contentStream.toString()).thenReturn("contentStreamTestString");
    // Tests for document with two output names
    outputNames.add("outputName1");
    outputNames.add("outputName2");
    Document d1 = SoapHelper.createSoapResponseDocument(context, outputHandler, contentStream, messages);
    Element activityResponse1 = d1.getRootElement().element("SOAP-ENV:Body").element("ExecuteActivityResponse");
    assertEquals(activityResponse1.elements().size(), 2);
    assertNotNull(activityResponse1.element("outputName1"));
    assertNotNull(activityResponse1.element("outputName2"));
    // Test for document with one output name (different branch in createSoapResponseDocument())
    outputNames.clear();
    outputNames.add("outputName1");
    Document d2 = SoapHelper.createSoapResponseDocument(context, outputHandler, contentStream, messages);
    Element activityResponse2 = d2.getRootElement().element("SOAP-ENV:Body").element("ExecuteActivityResponse");
    assertEquals(activityResponse2.elements().size(), 1);
    assertNotNull(activityResponse2.element("outputName1"));
    // Tests for document with no output names
    outputNames.clear();
    Document d3 = SoapHelper.createSoapResponseDocument(context, outputHandler, contentStream, messages);
    Element activityResponse3 = d3.getRootElement().element("SOAP-ENV:Body").element("ExecuteActivityResponse");
    assertTrue(activityResponse3.elements().isEmpty());
}
Also used : IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) OutputStream(java.io.OutputStream) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) IContentItem(org.pentaho.platform.api.repository.IContentItem) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.dom4j.Document) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) HashSet(java.util.HashSet)

Example 4 with IOutputHandler

use of org.pentaho.platform.api.engine.IOutputHandler in project pentaho-platform by pentaho.

the class XactionUtil method executeScheduleUi.

/**
 * 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);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        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"));
        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();
        // $NON-NLS-1$
        parameterProviders.put("request", requestParameters);
        // $NON-NLS-1$
        parameterProviders.put("session", sessionParameters);
        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) {
        // $NON-NLS-1$
        logger.error(Messages.getInstance().getString("XactionUtil.ERROR_EXECUTING_ACTION_SEQUENCE", file.getName()), e);
        throw e;
    } finally {
        if (runtime != null) {
            runtime.dispose();
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServletException(javax.servlet.ServletException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IOException(java.io.IOException) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpMimeTypeListener(org.pentaho.platform.web.servlet.HttpMimeTypeListener) HttpSessionParameterProvider(org.pentaho.platform.web.http.session.HttpSessionParameterProvider) HttpRequestParameterProvider(org.pentaho.platform.web.http.request.HttpRequestParameterProvider) List(java.util.List) ArrayList(java.util.ArrayList) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with IOutputHandler

use of org.pentaho.platform.api.engine.IOutputHandler in project pentaho-platform by pentaho.

the class XactionUtil method executeHtml.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static String executeHtml(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);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        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"));
        IOutputHandler outputHandler = createOutputHandler(httpServletResponse, getOutputStream(httpServletResponse, doMessages));
        // disposition is set on the response header
        if (mimeTypeListener == null) {
            mimeTypeListener = new HttpMimeTypeListener(httpServletRequest, httpServletResponse, null);
        }
        outputHandler.setMimeTypeListener(mimeTypeListener);
        outputHandler.setSession(userSession);
        Map parameterProviders = new HashMap();
        // $NON-NLS-1$
        parameterProviders.put("request", requestParameters);
        // $NON-NLS-1$
        parameterProviders.put("session", sessionParameters);
        createOutputFileName(file, outputHandler);
        int outputPreference = IOutputHandler.OUTPUT_TYPE_DEFAULT;
        outputHandler.setOutputPreference(outputPreference);
        // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
        boolean forcePrompt = "true".equalsIgnoreCase(requestParams.getStringParameter("prompt", "false"));
        List messages = new ArrayList();
        runtime = executeInternal(file, requestParams, httpServletRequest, outputHandler, parameterProviders, userSession, forcePrompt, messages);
        String str = postExecute(runtime, doMessages, doWrapper, outputHandler, parameterProviders, httpServletRequest, httpServletResponse, messages, true);
        return str;
    } catch (Exception e) {
        // $NON-NLS-1$
        logger.error(Messages.getInstance().getString("XactionUtil.ERROR_EXECUTING_ACTION_SEQUENCE", file.getName()), e);
        throw e;
    } finally {
        if (runtime != null) {
            runtime.dispose();
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServletException(javax.servlet.ServletException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IOException(java.io.IOException) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpMimeTypeListener(org.pentaho.platform.web.servlet.HttpMimeTypeListener) HttpSessionParameterProvider(org.pentaho.platform.web.http.session.HttpSessionParameterProvider) HttpRequestParameterProvider(org.pentaho.platform.web.http.request.HttpRequestParameterProvider) List(java.util.List) ArrayList(java.util.ArrayList) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

IOutputHandler (org.pentaho.platform.api.engine.IOutputHandler)11 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)6 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)5 List (java.util.List)4 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)4 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)4 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)4 IOException (java.io.IOException)3 OutputStream (java.io.OutputStream)3 ServletException (javax.servlet.ServletException)3 HttpRequestParameterProvider (org.pentaho.platform.web.http.request.HttpRequestParameterProvider)3 HttpSessionParameterProvider (org.pentaho.platform.web.http.session.HttpSessionParameterProvider)3 Map (java.util.Map)2 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)2 Before (org.junit.Before)2