use of org.pentaho.platform.engine.core.output.SimpleOutputHandler 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.output.SimpleOutputHandler in project pentaho-platform by pentaho.
the class AbstractChartComponent method getActionData.
/**
* Gets a IPentahoResultSet from the action output
*
* @return IPentahoResultSet
*/
public IPentahoResultSet getActionData() {
// create an instance of the solution engine to execute the specified
// action
ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, getSession());
solutionEngine.setLoggingLevel(ILogger.DEBUG);
solutionEngine.init(getSession());
HashMap parameterProviders = getParameterProviders();
OutputStream outputStream = null;
SimpleOutputHandler outputHandler = null;
outputHandler = new SimpleOutputHandler(outputStream, false);
ArrayList messages = new ArrayList();
String processId = this.getClass().getName();
context = // $NON-NLS-1$ //$NON-NLS-2$
solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
actionPath, // $NON-NLS-1$ //$NON-NLS-2$
processId, // $NON-NLS-1$ //$NON-NLS-2$
false, // $NON-NLS-1$ //$NON-NLS-2$
true, // $NON-NLS-1$ //$NON-NLS-2$
instanceId, // $NON-NLS-1$ //$NON-NLS-2$
false, parameterProviders, outputHandler, null, urlFactory, messages);
if (context == null) {
// this went badly wrong
return null;
}
if (actionOutput != null) {
if (context.getOutputNames().contains(actionOutput)) {
IActionParameter output = context.getOutputParameter(actionOutput);
IPentahoResultSet results = output.getValueAsResultSet();
if (results != null) {
results = results.memoryCopy();
}
return results;
} else {
// this is an error
return null;
}
} else {
for (Object objAp : context.getOutputNames()) {
IActionParameter output = (IActionParameter) objAp;
if (output.getType().equalsIgnoreCase(IActionParameter.TYPE_RESULT_SET)) {
IPentahoResultSet results = output.getValueAsResultSet();
if (results != null) {
results = results.memoryCopy();
}
return results;
}
}
}
return null;
}
use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.
the class AxisServiceWsdlGeneratorTest method testBadInit3.
@Test
public void testBadInit3() throws Exception {
// $NON-NLS-1$
StandaloneSession session = new StandaloneSession("test");
AxisServiceWsdlGenerator contentGenerator = new AxisServiceWsdlGenerator();
// $NON-NLS-1$
assertNotNull("contentGenerator is null", contentGenerator);
// $NON-NLS-1$
assertNotNull("Logger is null", contentGenerator.getLogger());
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOutputHandler outputHandler = new SimpleOutputHandler(out, false);
// $NON-NLS-1$
String baseUrl = "http://testhost:testport/testcontent";
Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
SimpleParameterProvider requestParams = new SimpleParameterProvider();
parameterProviders.put(IParameterProvider.SCOPE_REQUEST, requestParams);
// $NON-NLS-1$
SimpleUrlFactory urlFactory = new SimpleUrlFactory(baseUrl + "?");
List<String> messages = new ArrayList<String>();
contentGenerator.setOutputHandler(outputHandler);
MimeTypeListener mimeTypeListener = new MimeTypeListener();
outputHandler.setMimeTypeListener(mimeTypeListener);
contentGenerator.setMessagesList(messages);
contentGenerator.setParameterProviders(parameterProviders);
contentGenerator.setSession(session);
contentGenerator.setUrlFactory(urlFactory);
contentGenerator.createContent();
String content = new String(out.toByteArray());
System.out.println(content);
assertTrue(content.indexOf(Messages.getInstance().getErrorString("WebServiceContentGenerator.ERROR_0001_AXIS_CONFIG_IS_NULL")) != // $NON-NLS-1$
-1);
}
use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.
the class MultipleComponentIT method getOutputHandler.
public IOutputHandler getOutputHandler(OutputStream stream) {
// Allow feedback for this test
SimpleOutputHandler outputHandler = new SimpleOutputHandler(stream, true);
outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
return outputHandler;
}
use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.
the class RuntimeIT method testHelloWorld.
public void testHelloWorld() {
startTest();
SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
// $NON-NLS-1$ //$NON-NLS-2$
parameterProvider.setParameter("type", "html");
// $NON-NLS-1$ //$NON-NLS-2$
OutputStream outputStream = getOutputStream("RuntimeTest.testHelloWorld", ".html");
SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true);
StandaloneSession session = // $NON-NLS-1$
new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
IRuntimeContext context = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
run("/test/platform/HelloWorld.xaction", null, false, parameterProvider, outputHandler, session);
assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
context.getStatus());
finishTest();
}
Aggregations