Search in sources :

Example 1 with SimpleOutputHandler

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

the class PentahoSystem method globalStartup.

public static void globalStartup(final IPentahoSession session) {
    // getGlobalStartupActions doesn't pay any attention to session class
    List<ISessionStartupAction> globalStartupActions = PentahoSystem.getGlobalStartupActions();
    if (globalStartupActions == null) {
        // nothing to do...
        return;
    }
    boolean doGlobals = PentahoSystem.globalAttributes.size() == 0;
    // see if this has been done already
    if (!doGlobals) {
        return;
    }
    if (globalStartupActions != null) {
        for (ISessionStartupAction globalStartupAction : globalStartupActions) {
            // 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();
            IPentahoUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
            ArrayList messages = new ArrayList();
            IRuntimeContext context = null;
            try {
                context = solutionEngine.execute(globalStartupAction.getActionPath(), "Global 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) {
                            PentahoSystem.globalAttributes.remove(attributeName);
                            PentahoSystem.globalAttributes.put(attributeName, data);
                        }
                    }
                }
            } catch (Throwable th) {
                Logger.warn(PentahoSystem.class.getName(), Messages.getInstance().getString("PentahoSystem.WARN_UNABLE_TO_EXECUTE_GLOBAL_ACTION", th.getLocalizedMessage()), // $NON-NLS-1$
                th);
            } finally {
                if (context != null) {
                    context.dispose();
                }
            }
        }
    }
}
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) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) ISessionStartupAction(org.pentaho.platform.api.engine.ISessionStartupAction) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 2 with SimpleOutputHandler

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

the class AxisServiceExecutorTest method setUp.

@Before
public void setUp() throws Exception {
    StandaloneSession session = new StandaloneSession("test");
    StubServiceSetup serviceSetup = new StubServiceSetup();
    serviceSetup.setSession(session);
    AxisConfiguration axisCfg = serviceSetup.getAxisConfiguration();
    ConfigurationContext configContext = new ConfigurationContext(axisCfg);
    serviceSetup.loadServices();
    TransportInDescription tIn = new TransportInDescription(DEAFULT_TRANSPOT_PROTOCOL);
    StubTransportListener receiver = new StubTransportListener();
    tIn.setReceiver(receiver);
    axisCfg.addTransportIn(tIn);
    TransportOutDescription tOut = new TransportOutDescription(DEAFULT_TRANSPOT_PROTOCOL);
    StubTransportSender sender = new StubTransportSender();
    tOut.setSender(sender);
    axisCfg.addTransportOut(tOut);
    AxisWebServiceManager.currentAxisConfiguration = axisCfg;
    AxisWebServiceManager.currentAxisConfigContext = configContext;
    out = new ByteArrayOutputStream();
    IOutputHandler outputHandler = new SimpleOutputHandler(out, false);
    outputHandler.setMimeTypeListener(new MimeTypeListener());
    contentGenerator = new AxisServiceExecutor();
    contentGenerator.setOutputHandler(outputHandler);
    contentGenerator.setMessagesList(new ArrayList<String>());
    contentGenerator.setSession(session);
    contentGenerator.setUrlFactory(new SimpleUrlFactory(BASE_URL + "?"));
    assertNotNull("contentGenerator is null", contentGenerator);
    assertNotNull("Logger is null", contentGenerator.getLogger());
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StubTransportSender(org.pentaho.test.platform.plugin.services.webservices.StubTransportSender) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) TransportInDescription(org.apache.axis2.description.TransportInDescription) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) StubServiceSetup(org.pentaho.test.platform.plugin.services.webservices.StubServiceSetup) MimeTypeListener(org.pentaho.test.platform.plugin.services.webservices.MimeTypeListener) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) StubTransportListener(org.pentaho.test.platform.plugin.services.webservices.StubTransportListener) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) Before(org.junit.Before)

Example 3 with SimpleOutputHandler

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

the class ActionSequenceAction method execute.

public void execute() throws Exception {
    IOutputHandler outputHandler = null;
    if (xactionResultsOutputStream instanceof RepositoryFileOutputStream) {
        outputHandler = new RepositoryFileOutputHandler(((RepositoryFileOutputStream) xactionResultsOutputStream));
    } else {
        outputHandler = new SimpleOutputHandler(xactionResultsOutputStream, false);
    }
    IRuntimeContext rt = null;
    try {
        ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, null);
        solutionEngine.setCreateFeedbackParameterCallback(null);
        solutionEngine.setLoggingLevel(ILogger.DEBUG);
        solutionEngine.setForcePrompt(false);
        ArrayList messages = new ArrayList();
        HashMap<String, Object> parameterProviders = new HashMap<String, Object>();
        parameterProviders.put(IParameterProvider.SCOPE_REQUEST, new SimpleParameterProvider(xActionInputParams));
        parameterProviders.put(IParameterProvider.SCOPE_SESSION, new PentahoSessionParameterProvider(PentahoSessionHolder.getSession()));
        String xactionPath = null;
        if (xactionDefInputStream instanceof RepositoryFileInputStream) {
            xactionPath = ((RepositoryFileInputStream) xactionDefInputStream).getFile().getPath();
        }
        rt = solutionEngine.execute(xactionPath, this.getClass().getName(), false, true, null, true, parameterProviders, outputHandler, null, null, messages);
        if (!outputHandler.contentDone()) {
            if ((rt != null) && (rt.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS)) {
                // set content which generated by sequence for pass it to caller
                List<IContentItem> components = new ArrayList<IContentItem>(rt.getOutputContentItems());
                setActionOutputContents(components);
                boolean isFlushed = false;
                boolean isEmpty;
                if (xactionResultsOutputStream instanceof RepositoryFileOutputStream) {
                    RepositoryFileOutputStream repositoryFileOutputStream = (RepositoryFileOutputStream) xactionResultsOutputStream;
                    isFlushed = repositoryFileOutputStream.isFlushed();
                    isEmpty = repositoryFileOutputStream.size() > 0 ? false : true;
                    String extension = RepositoryFilenameUtils.getExtension(repositoryFileOutputStream.getFilePath());
                    String mimeTypeFromExtension = MimeHelper.getMimeTypeFromExtension("." + extension);
                    if (mimeTypeFromExtension == null) {
                        // unknown type, treat it not as an extension but part of the name
                        extension = "";
                    }
                    if (extension.isEmpty() && xactionResultsOutputStream.toString().isEmpty()) {
                        repositoryFileOutputStream.setFilePath(repositoryFileOutputStream.getFilePath() + ".html");
                    }
                } else {
                    isEmpty = xactionResultsOutputStream.toString().isEmpty();
                }
                if (!isFlushed) {
                    if (isEmpty) {
                        StringBuffer buffer = new StringBuffer();
                        // $NON-NLS-1$
                        MessageFormatUtils.formatSuccessMessage("text/html", rt, buffer, false);
                        xactionResultsOutputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
                    }
                    xactionResultsOutputStream.close();
                }
            } else {
                // we need an error message...
                StringBuffer buffer = new StringBuffer();
                // $NON-NLS-1$
                MessageFormatUtils.formatFailureMessage("text/html", rt, buffer, messages);
                xactionResultsOutputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
                xactionResultsOutputStream.close();
            }
        }
    } finally {
        if (rt != null) {
            rt.dispose();
        }
    }
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) RepositoryFileOutputHandler(org.pentaho.platform.repository2.unified.fileio.RepositoryFileOutputHandler) HashMap(java.util.HashMap) PentahoSessionParameterProvider(org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream) RepositoryFileOutputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileOutputStream) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) IContentItem(org.pentaho.platform.api.repository.IContentItem) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 4 with SimpleOutputHandler

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

the class HTMLComponentIT method testComponent2.

public void testComponent2() {
    startTest();
    // $NON-NLS-1$
    info(Messages.getInstance().getString("HTMLComponentTest.USER_ERRORS_EXPECTED_CONTENT_TYPE_INVALID"));
    // this should fail because the requested content type is not supported
    // $NON-NLS-1$
    String url = "http://www.pentaho.org/demo/news.html";
    // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory("/testurl?");
    ArrayList messages = new ArrayList();
    // $NON-NLS-1$
    HtmlComponent component = new HtmlComponent(HtmlComponent.TYPE_URL, url, "", urlFactory, messages);
    component.setLoggingLevel(getLoggingLevel());
    // $NON-NLS-1$//$NON-NLS-2$
    OutputStream outputStream = getOutputStream("HTMLComponentTest.testComponent2", ".html");
    // $NON-NLS-1$
    String contentType = "text/xml";
    SimpleParameterProvider requestParameters = new SimpleParameterProvider();
    SimpleParameterProvider sessionParameters = new SimpleParameterProvider();
    HashMap parameterProviders = new HashMap();
    parameterProviders.put(IParameterProvider.SCOPE_REQUEST, requestParameters);
    parameterProviders.put(IParameterProvider.SCOPE_SESSION, sessionParameters);
    StandaloneSession session = // $NON-NLS-1$
    new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, false);
    BaseRequestHandler requestHandler = new BaseRequestHandler(session, null, outputHandler, null, urlFactory);
    try {
        component.validate(session, requestHandler);
        component.handleRequest(outputStream, requestHandler, contentType, parameterProviders);
    } catch (IOException e) {
        e.printStackTrace();
    }
    finishTest();
}
Also used : HashMap(java.util.HashMap) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HtmlComponent(org.pentaho.platform.uifoundation.component.HtmlComponent) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IOException(java.io.IOException) BaseRequestHandler(org.pentaho.platform.engine.services.BaseRequestHandler) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 5 with SimpleOutputHandler

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

the class HTMLComponentIT method testComponent3.

public void testComponent3() {
    startTest();
    // $NON-NLS-1$
    info(Messages.getInstance().getString("HTMLComponentTest.USER_ERRORS_EXPECTED_URL_INVALID"));
    // this should fail because the url is bad
    // $NON-NLS-1$
    String url = "xttp://a";
    // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory("/testurl?");
    ArrayList messages = new ArrayList();
    HtmlComponent component = new HtmlComponent(HtmlComponent.TYPE_URL, url, Messages.getInstance().getString("HTML.ERROR_0001_NOT_AVAILABLE"), urlFactory, // $NON-NLS-1$
    messages);
    component.setLoggingLevel(getLoggingLevel());
    // $NON-NLS-1$//$NON-NLS-2$
    OutputStream outputStream = getOutputStream("HTMLComponentTest.testComponent3", ".html");
    // $NON-NLS-1$
    String contentType = "text/html";
    SimpleParameterProvider requestParameters = new SimpleParameterProvider();
    SimpleParameterProvider sessionParameters = new SimpleParameterProvider();
    HashMap parameterProviders = new HashMap();
    parameterProviders.put(IParameterProvider.SCOPE_REQUEST, requestParameters);
    parameterProviders.put(IParameterProvider.SCOPE_SESSION, sessionParameters);
    StandaloneSession session = // $NON-NLS-1$
    new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, false);
    BaseRequestHandler requestHandler = new BaseRequestHandler(session, null, outputHandler, null, urlFactory);
    try {
        component.validate(session, requestHandler);
        component.handleRequest(outputStream, requestHandler, contentType, parameterProviders);
    } catch (IOException e) {
        e.printStackTrace();
    }
    finishTest();
}
Also used : HashMap(java.util.HashMap) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HtmlComponent(org.pentaho.platform.uifoundation.component.HtmlComponent) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IOException(java.io.IOException) BaseRequestHandler(org.pentaho.platform.engine.services.BaseRequestHandler) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

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