Search in sources :

Example 11 with SimpleOutputHandler

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

the class SimpleOutputHandlerTest method testGetOutputContentItemObjectNameImportant.

public void testGetOutputContentItemObjectNameImportant() throws Exception {
    OutputStream out = new ByteArrayOutputStream();
    TestOutputHandler.contentItem = new SimpleContentItem(out);
    SimpleOutputHandler handler = new SimpleOutputHandler(out, false);
    StandaloneObjectFactory factory = new StandaloneObjectFactory();
    factory.defineObject("contentrepo", TestOutputHandler.class.getName(), StandaloneObjectFactory.Scope.GLOBAL);
    PentahoSystem.registerObjectFactory(factory);
    IContentItem contentItem = handler.getOutputContentItem("contentrepo", "myreport:contentrepo", null, null);
    assertNotNull(contentItem);
    assertEquals(out, contentItem.getOutputStream(null));
    contentItem = handler.getOutputContentItem("", "myreport:contentrepo", null, null);
    assertNull(contentItem);
}
Also used : SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StandaloneObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory) IContentItem(org.pentaho.platform.api.repository.IContentItem) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 12 with SimpleOutputHandler

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

the class SimpleOutputHandlerTest method test3.

public void test3() throws Exception {
    StandaloneSession session = new StandaloneSession();
    OutputStream out = new MockExceptionOutputStream();
    SimpleOutputHandler handler = new SimpleOutputHandler(out, false);
    assertFalse(handler.allowFeedback());
    handler.setSession(session);
    assertEquals(session, handler.getSession());
    IContentItem content2 = handler.getOutputContentItem(IOutputHandler.RESPONSE, IOutputHandler.CONTENT, null, null);
    assertEquals(out, content2.getOutputStream(null));
    assertNull(handler.getFeedbackContentItem());
    try {
        handler.setOutput(IOutputHandler.CONTENT, "test data");
        fail("Exception not detected.");
    } catch (Exception ex) {
    // Test passed.
    }
}
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)

Example 13 with SimpleOutputHandler

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

the class XactionUtil method executeXml.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static String executeXml(RepositoryFile file, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, IPentahoSession userSession) throws Exception {
    try {
        HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider(userSession);
        HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider(httpServletRequest);
        Map parameterProviders = new HashMap();
        // $NON-NLS-1$
        parameterProviders.put("request", requestParameters);
        // $NON-NLS-1$
        parameterProviders.put("session", sessionParameters);
        List messages = new ArrayList();
        IParameterProvider requestParams = new HttpRequestParameterProvider(httpServletRequest);
        // $NON-NLS-1$
        httpServletResponse.setContentType("text/xml");
        httpServletResponse.setCharacterEncoding(LocaleHelper.getSystemEncoding());
        // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
        boolean forcePrompt = "true".equalsIgnoreCase(requestParams.getStringParameter("prompt", "false"));
        OutputStream contentStream = new ByteArrayOutputStream();
        SimpleOutputHandler outputHandler = new SimpleOutputHandler(contentStream, false);
        IRuntimeContext runtime = null;
        try {
            runtime = executeInternal(file, requestParams, httpServletRequest, outputHandler, parameterProviders, userSession, forcePrompt, messages);
            Document responseDoc = SoapHelper.createSoapResponseDocument(runtime, outputHandler, contentStream, messages);
            OutputFormat format = OutputFormat.createCompactFormat();
            format.setSuppressDeclaration(true);
            // $NON-NLS-1$
            format.setEncoding("utf-8");
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            XMLWriter writer = new XMLWriter(outputStream, format);
            writer.write(responseDoc);
            writer.flush();
            // $NON-NLS-1$
            return outputStream.toString("utf-8");
        } finally {
            if (runtime != null) {
                runtime.dispose();
            }
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        logger.warn(Messages.getInstance().getString("XactionUtil.XML_OUTPUT_NOT_SUPPORTED"));
        throw e;
    }
}
Also used : HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) OutputFormat(org.dom4j.io.OutputFormat) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.dom4j.Document) XMLWriter(org.dom4j.io.XMLWriter) ServletException(javax.servlet.ServletException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IOException(java.io.IOException) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpSessionParameterProvider(org.pentaho.platform.web.http.session.HttpSessionParameterProvider) HttpRequestParameterProvider(org.pentaho.platform.web.http.request.HttpRequestParameterProvider) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext)

Example 14 with SimpleOutputHandler

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

the class HttpWebService method doGetFixMe.

public void doGetFixMe(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    try {
        // $NON-NLS-1$
        String actionPath = request.getParameter("path");
        String solutionName = actionPath.substring(0, actionPath.indexOf('/', 1));
        String actionName = actionPath.substring(actionPath.lastIndexOf('/'));
        String actionSeqPath = ActionInfo.buildSolutionPath(solutionName, actionPath, actionName);
        // $NON-NLS-1$
        String component = request.getParameter("component");
        String content = getPayloadAsString(request);
        IParameterProvider parameterProvider = null;
        HashMap parameters = new HashMap();
        if ((content != null) && (content.length() > 0)) {
            Document doc = XmlDom4JHelper.getDocFromString(content, new PentahoEntityResolver());
            // $NON-NLS-1$
            List parameterNodes = doc.selectNodes("//SOAP-ENV:Body/*/*");
            for (int i = 0; i < parameterNodes.size(); i++) {
                Node parameterNode = (Node) parameterNodes.get(i);
                String parameterName = parameterNode.getName();
                String parameterValue = parameterNode.getText();
                // if( "xml-data".equalsIgnoreCase( ) )
                if ("action".equals(parameterName)) {
                    // $NON-NLS-1$
                    ActionInfo info = ActionInfo.parseActionString(parameterValue);
                    solutionName = info.getSolutionName();
                    actionPath = info.getPath();
                    actionName = info.getActionName();
                } else if ("component".equals(parameterName)) {
                    // $NON-NLS-1$
                    component = parameterValue;
                } else {
                    parameters.put(parameterName, parameterValue);
                }
            }
            parameterProvider = new SimpleParameterProvider(parameters);
        } else {
            parameterProvider = new HttpRequestParameterProvider(request);
        }
        // $NON-NLS-1$
        response.setContentType("text/xml");
        response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
        // PentahoHttpSession userSession = new PentahoHttpSession(
        // request.getRemoteUser(), request.getSession(),
        // request.getLocale() );
        IPentahoSession userSession = getPentahoSession(request);
        // $NON-NLS-1$
        String instanceId = request.getParameter("instance-id");
        String processId = this.getClass().getName();
        OutputStream contentStream = new ByteArrayOutputStream();
        SimpleOutputHandler outputHandler = new SimpleOutputHandler(contentStream, false);
        // send the header of the message to prevent time-outs while we are
        // working
        OutputStream outputStream = response.getOutputStream();
        if ((component == null) || "action".equals(component)) {
            // $NON-NLS-1$
            // assume this is an action sequence execute
            HttpWebServiceRequestHandler requestHandler = new HttpWebServiceRequestHandler(userSession, null, outputHandler, parameterProvider, null);
            requestHandler.setParameterProvider(IParameterProvider.SCOPE_SESSION, new HttpSessionParameterProvider(userSession));
            requestHandler.setInstanceId(instanceId);
            requestHandler.setProcessId(processId);
            requestHandler.setActionPath(actionSeqPath);
            if (ServletBase.debug) {
                // $NON-NLS-1$
                debug(Messages.getInstance().getString("HttpWebService.DEBUG_WEB_SERVICE_START"));
            }
            IRuntimeContext runtime = null;
            try {
                runtime = requestHandler.handleActionRequest(0, 0);
                Document responseDoc = SoapHelper.createSoapResponseDocument(runtime, outputHandler, contentStream, requestHandler.getMessages());
                XmlDom4JHelper.saveDom(responseDoc, outputStream, PentahoSystem.getSystemSetting("web-service-encoding", "utf-8"), true);
            } finally {
                if (runtime != null) {
                    runtime.dispose();
                }
            }
        } else if ("dial".equals(component)) {
            // $NON-NLS-1$
            doDial(solutionName, actionPath, actionName, parameterProvider, outputStream, userSession);
        } else if ("chart".equals(component)) {
            // $NON-NLS-1$
            doChart(actionPath, parameterProvider, outputStream, userSession);
        } else if ("xaction-parameter".equals(component)) {
            // $NON-NLS-1$
            doParameter(solutionName, actionPath, actionName, parameterProvider, outputStream, userSession, response);
        }
    } catch (Throwable t) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"), t);
    }
    if (ServletBase.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("HttpWebService.DEBUG_WEB_SERVICE_END"));
    }
}
Also used : HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Node(org.dom4j.Node) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ActionInfo(org.pentaho.platform.engine.core.solution.ActionInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpWebServiceRequestHandler(org.pentaho.platform.web.http.request.HttpWebServiceRequestHandler) Document(org.dom4j.Document) PentahoEntityResolver(org.pentaho.platform.engine.services.solution.PentahoEntityResolver) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpSessionParameterProvider(org.pentaho.platform.web.http.session.HttpSessionParameterProvider) HttpRequestParameterProvider(org.pentaho.platform.web.http.request.HttpRequestParameterProvider) ArrayList(java.util.ArrayList) List(java.util.List) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 15 with SimpleOutputHandler

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

the class WidgetGridComponent method getActionData.

protected 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();
    String actionSeqPath = ActionInfo.buildSolutionPath(solution, actionPath, actionName);
    context = solutionEngine.execute(actionSeqPath, processId, false, true, instanceId, false, parameterProviders, outputHandler, null, urlFactory, messages);
    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 {
        // return the first list that we find...
        Iterator it = context.getOutputNames().iterator();
        while (it.hasNext()) {
            IActionParameter output = (IActionParameter) it.next();
            if (output.getType().equalsIgnoreCase(IActionParameter.TYPE_RESULT_SET)) {
                IPentahoResultSet results = output.getValueAsResultSet();
                if (results != null) {
                    results = results.memoryCopy();
                }
                return results;
            }
        }
    }
    return null;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

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