Search in sources :

Example 31 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.

the class BaseTest method getOutputHandler.

public IOutputHandler getOutputHandler(OutputStream stream) {
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(stream, false);
    outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
    return outputHandler;
}
Also used : SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler)

Example 32 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.

the class BaseTest method getOutputHandler.

public IOutputHandler getOutputHandler(IContentItem contentItem) {
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(contentItem, false);
    outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
    return outputHandler;
}
Also used : SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler)

Example 33 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.

the class SimpleOutputHandlerTest method test2.

public void test2() throws Exception {
    StandaloneSession session = new StandaloneSession();
    OutputStream out = new MockExceptionOutputStream();
    IContentItem content = new SimpleContentItem(out);
    SimpleOutputHandler handler = new SimpleOutputHandler(content, true);
    assertTrue(handler.allowFeedback());
    assertFalse(handler.contentDone());
    assertNotNull(handler.getFeedbackContentItem());
    assertTrue(handler.contentDone());
    IContentItem content2 = handler.getFeedbackContentItem();
    assertEquals(content.getOutputStream(null), content2.getOutputStream(null));
    IContentItem content3 = new BufferedContentItem(null);
    content3.getOutputStream(null).write("test data".getBytes());
    content3.closeOutputStream();
    try {
        handler.setOutput(IOutputHandler.CONTENT, content3);
        fail("Exception not detected.");
    } catch (Exception ex) {
    // Test passed.
    }
}
Also used : SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IContentItem(org.pentaho.platform.api.repository.IContentItem) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) BufferedContentItem(org.pentaho.platform.engine.core.output.BufferedContentItem)

Example 34 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.

the class SimpleOutputHandlerTest method test4.

public void test4() throws Exception {
    StandaloneSession session = new StandaloneSession();
    OutputStream out = new ByteArrayOutputStream();
    SimpleOutputHandler handler = new SimpleOutputHandler(out, true);
    assertTrue(handler.allowFeedback());
    assertNotNull(handler.getFeedbackContentItem());
    IContentItem content2 = handler.getFeedbackContentItem();
    assertEquals(out, content2.getOutputStream(null));
    OutputStream out3 = new ByteArrayOutputStream();
    handler.setOutputStream(out3, IOutputHandler.RESPONSE, IOutputHandler.CONTENT);
    IContentItem content3 = handler.getOutputContentItem(IOutputHandler.RESPONSE, IOutputHandler.CONTENT, null, null);
    assertEquals(out3, content3.getOutputStream(null));
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IContentItem(org.pentaho.platform.api.repository.IContentItem) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 35 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.

the class SimpleOutputHandlerTest method test1.

public void test1() throws Exception {
    StandaloneObjectFactory factory = new StandaloneObjectFactory();
    TestOutputHandler.contentItem = new SimpleContentItem();
    factory.defineObject("testoutut", TestOutputHandler.class.getName(), StandaloneObjectFactory.Scope.LOCAL);
    PentahoSystem.registerObjectFactory(factory);
    StandaloneSession session = new StandaloneSession();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SimpleOutputHandler handler = new SimpleOutputHandler(out, false);
    MimeTypeListener listener = new MimeTypeListener();
    handler.setMimeTypeListener(listener);
    assertEquals(listener, handler.getMimeTypeListener());
    assertFalse(handler.allowFeedback());
    handler.setSession(session);
    assertEquals(session, handler.getSession());
    handler.setContentItem(new SimpleContentItem(), null, null);
    IContentItem content2 = handler.getOutputContentItem("bogus", "testoutut:bogus", null, null);
    assertEquals(TestOutputHandler.contentItem, content2);
    content2 = handler.getOutputContentItem("bogus", "bogus", null, null);
    assertNull(content2);
    content2 = handler.getOutputContentItem(IOutputHandler.RESPONSE, IOutputHandler.CONTENT, null, null);
    assertEquals(out, content2.getOutputStream(null));
    assertFalse(handler.contentDone());
    assertNull(handler.getFeedbackContentItem());
    assertFalse(handler.contentDone());
    handler.setOutputPreference(-1);
    assertEquals(-1, handler.getOutputPreference());
    handler.setMimeType("test/test");
    assertEquals("test/test", handler.getMimeType());
    handler.setOutput("bogus", null);
    handler.setOutput("file:bogus", null);
    IContentItem content3 = new BufferedContentItem(null);
    OutputStream os = content3.getOutputStream(null);
    os.write("test data".getBytes());
    content3.closeOutputStream();
    handler.setOutput(IOutputHandler.CONTENT, content3);
    assertEquals("test data", new String(out.toByteArray()));
    handler.setOutput(IOutputHandler.CONTENT, "+test data2");
    assertEquals("test data+test data2", new String(out.toByteArray()));
}
Also used : SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IContentItem(org.pentaho.platform.api.repository.IContentItem) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) BufferedContentItem(org.pentaho.platform.engine.core.output.BufferedContentItem) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)43 OutputStream (java.io.OutputStream)25 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)24 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)22 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)20 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)17 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)15 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)12 IOException (java.io.IOException)8 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)8 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)6 IContentItem (org.pentaho.platform.api.repository.IContentItem)6 BaseRequestHandler (org.pentaho.platform.engine.services.BaseRequestHandler)6 IOutputHandler (org.pentaho.platform.api.engine.IOutputHandler)5 Iterator (java.util.Iterator)4 List (java.util.List)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)4