use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.
the class AuditHelperTest method testAuditFailures.
public void testAuditFailures() {
startTest();
// $NON-NLS-1$ //$NON-NLS-2$
OutputStream outputStream = getOutputStream("testAudit", ".html");
SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true);
outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_PARAMETERS);
StandaloneSession session = // $NON-NLS-1$
new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
AuditHelper.audit(null, session, "Type", "This is a message", "Values", 34, this);
assertTrue(true);
finishTest();
}
use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.
the class PojoComponentTest method testStreamingPojo.
public void testStreamingPojo() {
String instanceId = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
SimpleOutputHandler outputHandler = new SimpleOutputHandler(out, false);
outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
startTest();
IPentahoSession session = new StandaloneSession("system");
ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
if (outputHandler != null) {
outputHandler.setSession(session);
}
try {
String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "test/pojo/pojo2.xaction");
PojoComponentTest.setActionSequenceResourceCalled = false;
IRuntimeContext runtimeContext = // $NON-NLS-1$ //$NON-NLS-2$
solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
xactionStr, // $NON-NLS-1$ //$NON-NLS-2$
"test1.xaction", // $NON-NLS-1$ //$NON-NLS-2$
"empty action sequence test", // $NON-NLS-1$ //$NON-NLS-2$
false, // $NON-NLS-1$ //$NON-NLS-2$
true, // $NON-NLS-1$ //$NON-NLS-2$
null, // $NON-NLS-1$ //$NON-NLS-2$
false, new HashMap(), outputHandler, null, new SimpleUrlFactory(""), new ArrayList());
IActionParameter param = runtimeContext.getOutputParameter("outputstream");
assertNotNull("RuntimeContext is null", runtimeContext);
assertEquals("Action sequence execution failed", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_STATUS_SUCCESS);
assertTrue("setResource was not called", PojoComponentTest.setResourceInputStreamCalled);
assertTrue("setResource was not called", PojoComponentTest.setActionSequenceResourceCalled);
} catch (Exception e) {
// we should not get here
e.printStackTrace();
assertTrue(e.getMessage(), false);
}
String output = new String(out.toByteArray());
assertEquals("outputstream", "abcdeabcde", output);
finishTest();
}
use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.
the class PentahoSystem method sessionStartup.
public static void sessionStartup(final IPentahoSession session, IParameterProvider sessionParameters) {
List<ISessionStartupAction> sessionStartupActions = PentahoSystem.getSessionStartupActionsForType(session.getClass().getName());
if (sessionStartupActions == null) {
// nothing to do...
return;
}
if (!session.isAuthenticated()) {
return;
}
Boolean startupActionsFired = (Boolean) session.getAttribute("StartupActionsFired");
if ((startupActionsFired == null) || (!startupActionsFired)) {
try {
if (debug) {
// $NON-NLS-1$
Logger.debug(PentahoSystem.class, "Process session startup actions");
}
if (sessionStartupActions != null) {
for (ISessionStartupAction sessionStartupAction : sessionStartupActions) {
// parse the actionStr out to identify an action
// now execute the action...
SimpleOutputHandler outputHandler = null;
String instanceId = null;
ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
solutionEngine.setLoggingLevel(PentahoSystem.loggingLevel);
solutionEngine.init(session);
// $NON-NLS-1$
String baseUrl = "";
HashMap parameterProviderMap = new HashMap();
if (sessionParameters == null) {
sessionParameters = new PentahoSessionParameterProvider(session);
}
parameterProviderMap.put(SCOPE_SESSION, sessionParameters);
IPentahoUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
ArrayList messages = new ArrayList();
IRuntimeContext context = null;
try {
context = solutionEngine.execute(sessionStartupAction.getActionPath(), "Session startup actions", false, true, instanceId, false, parameterProviderMap, outputHandler, null, urlFactory, // $NON-NLS-1$
messages);
// if context is null, then we cannot check the status
if (null == context) {
return;
}
if (context.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS) {
// now grab any outputs
Iterator outputNameIterator = context.getOutputNames().iterator();
while (outputNameIterator.hasNext()) {
String attributeName = (String) outputNameIterator.next();
IActionParameter output = context.getOutputParameter(attributeName);
Object data = output.getValue();
if (data != null) {
session.removeAttribute(attributeName);
session.setAttribute(attributeName, data);
}
}
}
} catch (Throwable th) {
Logger.warn(PentahoSystem.class.getName(), Messages.getInstance().getString("PentahoSystem.WARN_UNABLE_TO_EXECUTE_SESSION_ACTION", th.getLocalizedMessage()), // $NON-NLS-1$
th);
} finally {
if (context != null) {
context.dispose();
}
}
}
}
} finally {
session.setAttribute("StartupActionsFired", true);
}
} else {
if (debug) {
Logger.debug(PentahoSystem.class, "Session startup actions already fired");
}
}
}
use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.
the class DefaultChartBeansGenerator method createAndRunActionSequence.
protected void createAndRunActionSequence(final IPentahoSession pentahoSession, final Map<String, Object> params, final Map<String, Object> defaultParameterMap, String contentLinkingTemplate, final OutputStream out) {
SimpleParameterProvider parameterProvider = new SimpleParameterProvider(params);
// add the default parameter values
for (Map.Entry<String, Object> entry : defaultParameterMap.entrySet()) {
parameterProvider.setParameter(entry.getKey(), entry.getValue());
}
Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
parameterProviders.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
SimpleOutputHandler outputHandler = new SimpleOutputHandler(out, true);
outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
ActionSequenceDocument doc = createActionSequenceDocument(defaultParameterMap.keySet(), contentLinkingTemplate);
runActionSequence(pentahoSession, parameterProviders, outputHandler, doc);
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.
the class DashboardWidgetIT method testWidget1.
public void testWidget1() {
startTest();
// $NON-NLS-1$
SimpleUrlFactory urlFactory = new SimpleUrlFactory("/testurl?");
ArrayList messages = new ArrayList();
DashboardWidgetComponent widget = new DashboardWidgetComponent(DashboardWidgetComponent.TYPE_DIAL, getSolutionPath() + "/samples/charts/dashboardwidget1.dial.xml", 300, 300, urlFactory, // $NON-NLS-1$
messages);
widget.setLoggingLevel(getLoggingLevel());
widget.setValue(72.5);
// $NON-NLS-1$
widget.setTitle("test widget 1");
// $NON-NLS-1$
widget.setUnits("$");
// $NON-NLS-1$//$NON-NLS-2$
OutputStream outputStream = getOutputStream("DashboardWidgetTest.testWidget1", ".html");
// $NON-NLS-1$
String contentType = "text/html";
SimpleParameterProvider requestParameters = new SimpleParameterProvider();
SimpleParameterProvider sessionParameters = new SimpleParameterProvider();
HashMap parameterProviders = new HashMap();
parameterProviders.put(HttpRequestParameterProvider.SCOPE_REQUEST, requestParameters);
parameterProviders.put(HttpSessionParameterProvider.SCOPE_SESSION, sessionParameters);
// $NON-NLS-1$
StandaloneSession session = new StandaloneSession("BaseTest.DEBUG_JUNIT_SESSION");
SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, false);
BaseRequestHandler requestHandler = new BaseRequestHandler(session, null, outputHandler, null, urlFactory);
try {
widget.validate(session, requestHandler);
widget.handleRequest(outputStream, requestHandler, contentType, parameterProviders);
} catch (IOException e) {
e.printStackTrace();
}
finishTest();
}
Aggregations