Search in sources :

Example 31 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class ContentOutputComponentIT method testSuccessPaths.

public void testSuccessPaths() {
    startTest();
    // $NON-NLS-1$
    String testName = CO_TEST_NAME + "string_" + System.currentTimeMillis();
    SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
    IRuntimeContext context = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    run("/test/platform/ContentOutputTest.xaction", parameterProvider, testName, CO_TEST_EXTN);
    assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
    context.getStatus());
    // $NON-NLS-1$
    IActionParameter rtn = context.getOutputParameter("content");
    assertNotNull(rtn);
    InputStream is = this.getInputStreamFromOutput(testName, CO_TEST_EXTN);
    // Did the test execute properly...
    assertNotNull(is);
    // $NON-NLS-1$
    String lookingFor = "This is sample output from the content-output component.";
    String wasRead = FileHelper.getStringFromInputStream(is);
    assertTrue(wasRead.startsWith(lookingFor));
    // Test different path - Byte Array Output Stream
    // $NON-NLS-1$
    lookingFor = "This is as sample bytearray output stream";
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        baos.write(lookingFor.getBytes());
    } catch (Exception ex) {
        fail();
    }
    // $NON-NLS-1$
    testName = CO_TEST_NAME + "ByteArrayOutputStream_" + System.currentTimeMillis();
    // $NON-NLS-1$
    parameterProvider.setParameter("CONTENTOUTPUT", baos);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    context = run("/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN);
    assertEquals(IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus());
    is = this.getInputStreamFromOutput(testName, CO_TEST_EXTN);
    // Did the test execute properly...
    assertNotNull(is);
    wasRead = FileHelper.getStringFromInputStream(is);
    FileHelper.getStringFromFile(new File(PentahoSystem.getApplicationContext().getSolutionPath(// $NON-NLS-1$
    "test/datasource/books.xml")));
    try {
        FileHelper.getBytesFromFile(new File(PentahoSystem.getApplicationContext().getSolutionPath(// $NON-NLS-1$
        "test/datasource/books.xml")));
    } catch (IOException io) {
    // do nothing
    }
    File f = null;
    FileHelper.getStringFromFile(f);
    assertTrue(wasRead.startsWith(lookingFor));
    // Test different path - InputStream
    // $NON-NLS-1$
    testName = CO_TEST_NAME + "ByteArrayInputStream_" + System.currentTimeMillis();
    // $NON-NLS-1$
    lookingFor = "This is as a simple bytearray input stream";
    ByteArrayInputStream bais = new ByteArrayInputStream(lookingFor.getBytes());
    // $NON-NLS-1$
    parameterProvider.setParameter("CONTENTOUTPUT", bais);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    context = run("/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN);
    assertEquals(IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus());
    is = this.getInputStreamFromOutput(testName, CO_TEST_EXTN);
    // Did the test execute properly...
    assertNotNull(is);
    String newText = FileHelper.getStringFromInputStream(is);
    // $NON-NLS-1$
    System.out.println("Read Text from the input stream" + newText);
    String newTextFromIS = FileHelper.getStringFromInputStream(is);
    // $NON-NLS-1$
    System.out.println("Read Text from the input stream" + newTextFromIS);
    assertTrue(newText.startsWith(lookingFor));
    finishTest();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) File(java.io.File) IOException(java.io.IOException) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 32 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class SolutionEngineAgent method execute.

public int execute() {
    PentahoSystem.systemEntryPoint();
    try {
        // create a generic session object
        StandaloneSession session = new StandaloneSession(userId);
        solutionEngine = PentahoSystem.get(SolutionEngine.class, session);
        solutionEngine.init(session);
        SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parameters);
        HashMap<String, IParameterProvider> parameterProviderMap = new HashMap<String, IParameterProvider>();
        parameterProviderMap.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
        IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
        // $NON-NLS-1$
        IPentahoUrlFactory urlFactory = new SimpleUrlFactory(requestContext.getContextPath());
        String processName = description;
        boolean persisted = false;
        List messages = new ArrayList();
        outputStream = new ByteArrayOutputStream(0);
        SimpleOutputHandler outputHandler = null;
        if (outputStream != null) {
            outputHandler = new SimpleOutputHandler(outputStream, false);
            outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
        }
        solutionEngine.execute(actionSequence, processName, false, true, null, persisted, parameterProviderMap, outputHandler, null, urlFactory, messages);
    } finally {
        PentahoSystem.systemExitPoint();
    }
    return solutionEngine.getStatus();
}
Also used : IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) ArrayList(java.util.ArrayList) List(java.util.List) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 33 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class SolutionHelper method execute.

/**
 * Runs an action sequence. This method uses the base URL set by the Application Context
 *
 * @param description
 *          An identifier for this process. This is used for auditing and logging purposes only.
 * @param session
 *          The user session that is requesting this execution. This is used for auditing and logging and also
 *          can be used in action sequences (for example to filter data)
 * @param actionSequence
 *          Path to the action sequence file
 * @param parameters
 *          Parameters to be passed to the action sequence
 * @param outputStream
 *          The output stream for content generated by the action sequence. Can be null.
 * @param execListener
 *          An execution listener for feedback during execution. Can be null.
 * @return
 */
public static ISolutionEngine execute(final String description, final IPentahoSession session, final String actionSequence, final Map parameters, OutputStream outputStream, final IExecutionListener execListener, final boolean collateMessages, final boolean manageHibernate) {
    if (manageHibernate) {
        PentahoSystem.systemEntryPoint();
    }
    ISolutionEngine solutionEngine = null;
    try {
        solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
        solutionEngine.init(session);
        solutionEngine.setlistener(execListener);
        SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parameters);
        IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
        String url = requestContext.getContextPath();
        // Modifications by Ezequiel Cuellar
        // Old code.
        // String baseUrl = PentahoSystem.getApplicationContext().getBaseUrl();
        // New code. Since the SubActionComponent is being instantiated below to return feedback
        // it is necesary to configure the baseUrl to include the ViewAction.
        Object actionUrlComponent = parameters.get(StandardSettings.ACTION_URL_COMPONENT);
        if ((actionUrlComponent != null) && (actionUrlComponent.toString().length() > 0)) {
            url += actionUrlComponent.toString();
        } else {
            // $NON-NLS-1$
            url += "ViewAction?";
        }
        HashMap<String, IParameterProvider> parameterProviderMap = new HashMap<String, IParameterProvider>();
        parameterProviderMap.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
        IPentahoUrlFactory urlFactory = new SimpleUrlFactory(url);
        String processName = description;
        boolean persisted = false;
        // for now, the messages list needs to be untyped since we may put exceptions as well as strings in it
        List<?> messages = null;
        if (collateMessages) {
            messages = new ArrayList();
        }
        if (outputStream == null) {
            outputStream = new ByteArrayOutputStream(0);
        }
        SimpleOutputHandler outputHandler = null;
        if (outputStream != null) {
            // Modifications by Ezequiel Cuellar
            // Old code.
            // outputHandler = new SimpleOutputHandler(outputStream, false);
            // New code. Without setting the allowFeedback parameter to true it is assumed that SubActionComponent
            // instances
            // are never capable of returning feedback which may not always be the case.
            outputHandler = new SimpleOutputHandler(outputStream, true);
            outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
        }
        solutionEngine.execute(actionSequence, processName, false, true, null, persisted, parameterProviderMap, outputHandler, null, urlFactory, messages);
    } finally {
        if (manageHibernate) {
            PentahoSystem.systemExitPoint();
        }
    }
    return solutionEngine;
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 34 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class AxisServiceExecutorTest method testRunGetWithParameter.

@Test
public void testRunGetWithParameter() throws Exception {
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider pathParams = new SimpleParameterProvider();
    pathParams.setParameter("path", "/StubService/setString?str=testinput");
    parameterProviders.put("path", pathParams);
    contentGenerator.setParameterProviders(parameterProviders);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setMethod("GET");
    request.setRequestURI("/pentaho/content/ws-run/StubService/setString");
    request.setRequestURL("http://localhost:8080/pentaho/content/ws-run/StubService/getString");
    request.setRemoteAddr(REMOTE_ADDRESS);
    request.setQueryString("str=testinput");
    pathParams.setParameter("httprequest", request);
    pathParams.setParameter("httpresponse", response);
    try {
        StubService.setStringCalled = false;
        StubTransportSender.transportOutStr = null;
        contentGenerator.createContent();
        assertTrue(StubService.setStringCalled);
        assertEquals("testinput", StubService.str);
    } catch (Exception e) {
        assertTrue("Exception occurred", false);
    }
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HashMap(java.util.HashMap) MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Test(org.junit.Test)

Example 35 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class AxisServiceExecutorTest method testRunGetAxisServletHooks.

@Test
public void testRunGetAxisServletHooks() throws Exception {
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider pathParams = new SimpleParameterProvider();
    pathParams.setParameter("path", "/StubService/bogus");
    parameterProviders.put("path", pathParams);
    contentGenerator.setParameterProviders(parameterProviders);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setMethod("GET");
    request.setRequestURI("/pentaho/content/ws-run/StubService/bogus");
    request.setRequestURL("http://localhost:8080/pentaho/content/ws-run/StubService/bogus");
    request.setRemoteAddr(REMOTE_ADDRESS);
    pathParams.setParameter("httprequest", request);
    pathParams.setParameter("httpresponse", response);
    try {
        StubTransportSender.transportOutStr = null;
        contentGenerator.createContent();
        String content = StubTransportSender.transportOutStr;
        assertTrue("results are wrong", content.contains("soapenv:Fault"));
        assertTrue("results are wrong", content.contains("AxisServletHooks"));
    } catch (Exception e) {
        assertTrue("Exception occurred", false);
    }
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HashMap(java.util.HashMap) MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Test(org.junit.Test)

Aggregations

SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)72 HashMap (java.util.HashMap)32 ArrayList (java.util.ArrayList)23 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)23 OutputStream (java.io.OutputStream)21 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)21 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)21 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)21 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)16 Test (org.junit.Test)13 IOException (java.io.IOException)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 MockHttpServletRequest (com.mockrunner.mock.web.MockHttpServletRequest)7 MockHttpServletResponse (com.mockrunner.mock.web.MockHttpServletResponse)7 Map (java.util.Map)5 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)5 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)5 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)5 BaseRequestHandler (org.pentaho.platform.engine.services.BaseRequestHandler)5 Iterator (java.util.Iterator)4