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();
}
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();
}
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;
}
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);
}
}
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);
}
}
Aggregations