Search in sources :

Example 51 with IParameterProvider

use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.

the class AbstractAxisServiceContentGenerator method processAxisFault.

/**
 * Handles processing of Axis exceptions.
 *
 * @param msgContext
 *          The message context that experienced an error
 * @param out
 *          The output stream to write to
 * @param e
 *          The error that occurred
 */
protected void processAxisFault(MessageContext msgContext, OutputStream out, Throwable e) {
    // $NON-NLS-1$
    IParameterProvider pathParams = parameterProviders.get("path");
    // is this HTTP?
    boolean http = msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE) != null;
    if (http) {
        // $NON-NLS-1$
        HttpServletResponse res = (HttpServletResponse) pathParams.getParameter("httpresponse");
        // If the fault is not going along the back channel we should be 202ing
        if (AddressingHelper.isFaultRedirected(msgContext)) {
            res.setStatus(HttpServletResponse.SC_ACCEPTED);
        } else {
            // set the status of the HTTP response
            String status = (String) msgContext.getProperty(Constants.HTTP_RESPONSE_STATE);
            try {
                if (status == null) {
                    res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                } else {
                    int sc = Integer.parseInt(status);
                    if (sc >= 400) {
                        res.sendError(sc);
                    } else {
                        res.setStatus(sc);
                    }
                }
            } catch (IOException e1) {
                if (status == null) {
                    res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                } else {
                    int sc = Integer.parseInt(status);
                    res.setStatus(sc);
                }
            }
            AxisBindingOperation axisBindingOperation = (AxisBindingOperation) msgContext.getProperty(Constants.AXIS_BINDING_OPERATION);
            if (axisBindingOperation != null) {
                AxisBindingMessage fault = axisBindingOperation.getFault((String) msgContext.getProperty(Constants.FAULT_NAME));
                if (fault != null) {
                    Integer code = (Integer) fault.getProperty(WSDL2Constants.ATTR_WHTTP_CODE);
                    if (code != null) {
                        res.setStatus(code.intValue());
                    }
                }
            }
        }
    }
    try {
        // now process the fault
        handleFault(msgContext, out, http, e);
    } catch (IOException axisFault) {
        // $NON-NLS-1$
        String message = Messages.getInstance().getErrorString("WebServiceContentGenerator.ERROR_0003_PROCESSING_FAULT");
        getLogger().error(message, axisFault);
    }
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpServletResponse(javax.servlet.http.HttpServletResponse) AxisBindingOperation(org.apache.axis2.description.AxisBindingOperation) AxisBindingMessage(org.apache.axis2.description.AxisBindingMessage) IOException(java.io.IOException)

Example 52 with IParameterProvider

use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.

the class AxisWebServiceRequestDispatcher method createContent.

/**
 * Parses the path parameter to find the web service name, makes sure it is valid, and the calls the current subclass
 * to create the required content for the specified web service
 */
@Override
public void createContent(AxisConfiguration axisConfiguration, ConfigurationContext context, OutputStream out) throws Exception {
    // make sure we have a 'path' parameters provider
    // $NON-NLS-1$
    IParameterProvider pathParams = parameterProviders.get("path");
    if (pathParams == null) {
        // return an error
        String message = // $NON-NLS-1$
        Messages.getInstance().getErrorString("WebServiceContentGenerator.ERROR_0004_PATH_PARAMS_IS_MISSING");
        getLogger().error(message);
        out.write(message.getBytes());
        return;
    }
    // make sure we have a service name on the URL
    // $NON-NLS-1$
    String serviceName = pathParams.getStringParameter("path", null);
    if (serviceName == null) {
        // return an error
        String message = // $NON-NLS-1$
        Messages.getInstance().getErrorString("WebServiceContentGenerator.ERROR_0005_SERVICE_NAME_IS_MISSING");
        getLogger().error(message);
        out.write(message.getBytes());
        return;
    }
    // remove the leading '/'
    serviceName = serviceName.substring(1);
    // pull the service name off the URL
    String query = serviceName;
    String operationName = null;
    // $NON-NLS-1$
    int idx = serviceName.indexOf("/");
    if (idx != -1) {
        serviceName = serviceName.substring(0, idx);
        query = query.substring(idx + 1);
        // $NON-NLS-1$
        idx = query.indexOf("?");
        if (idx != -1) {
            operationName = query.substring(0, idx);
        } else {
            operationName = query;
        }
    }
    // try to get the service using the name
    AxisService axisService = axisConfiguration.getService(serviceName);
    if (axisService == null) {
        // return an error
        String message = Messages.getInstance().getErrorString("WebServiceContentGenerator.ERROR_0006_SERVICE_IS_INVALID", // $NON-NLS-1$
        serviceName);
        getLogger().error(message);
        out.write(message.getBytes());
        return;
    }
    // hand over to the subclass
    createServiceContent(axisService, operationName, axisConfiguration, context, out);
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) AxisService(org.apache.axis2.description.AxisService)

Example 53 with IParameterProvider

use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.

the class ActionSequenceContentGenerator method getPathParameters.

@SuppressWarnings("unchecked")
public IParameterProvider getPathParameters() {
    if (this.pathParameters != null) {
        return this.pathParameters;
    }
    // $NON-NLS-1$
    IParameterProvider pathParams = this.parameterProviders.get("path");
    SimpleParameterSetter parameters = new SimpleParameterSetter();
    Iterator pathParamIterator = pathParams.getParameterNames();
    while (pathParamIterator.hasNext()) {
        String param = (String) pathParamIterator.next();
        parameters.setParameter(param, pathParams.getParameter(param));
    }
    this.pathParameters = parameters;
    return parameters;
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) SimpleParameterSetter(org.pentaho.platform.engine.services.solution.SimpleParameterSetter) Iterator(java.util.Iterator)

Example 54 with IParameterProvider

use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.

the class ActionSequenceContentGenerator method createContent.

public void createContent(OutputStream outputStream) throws Exception {
    IParameterProvider requestParams = getRequestParameters();
    IParameterProvider pathParams = getPathParameters();
    if (// $NON-NLS-1$
    (requestParams != null) && (requestParams.getStringParameter("path", null) != null)) {
        // So far the decode that used to be here is not necessary and breaks files with special characters.
        // Leaving commented code here in case it shows up later
        // path = URLDecoder.decode( requestParams.getStringParameter( "path", "" ), "UTF-8" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        path = requestParams.getStringParameter("path", "");
    } else if ((pathParams != null) && (pathParams.getStringParameter("path", null) != null)) {
        // $NON-NLS-1$
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        path = URLDecoder.decode(pathParams.getStringParameter("path", ""), "UTF-8");
    }
    if ((requestParams != null) && (requestParams.getStringParameter("contentType", null) != null)) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        contentType = requestParams.getStringParameter("contentType", TEXT_HTML);
    } else if ((pathParams != null) && (pathParams.getStringParameter("contentType", null) != null)) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        contentType = pathParams.getStringParameter("contentType", TEXT_HTML);
    }
    if (path != null && path.length() > 0) {
        IUnifiedRepository unifiedRepository = PentahoSystem.get(IUnifiedRepository.class, null);
        RepositoryFile file = unifiedRepository.getFile(path);
        // $NON-NLS-1$
        HttpServletRequest httpRequest = (HttpServletRequest) pathParams.getParameter("httprequest");
        // $NON-NLS-1$
        HttpServletResponse httpResponse = (HttpServletResponse) pathParams.getParameter("httpresponse");
        String buffer = XactionUtil.execute(contentType, file, httpRequest, httpResponse, PentahoSessionHolder.getSession(), outputHandler.getMimeTypeListener());
        if (buffer != null && buffer.trim().length() > 0) {
            outputStream.write(buffer.getBytes(LocaleHelper.getSystemEncoding()));
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpServletResponse(javax.servlet.http.HttpServletResponse) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 55 with IParameterProvider

use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.

the class ActionSequenceContentGenerator method getRequestParameters.

@SuppressWarnings("unchecked")
private IParameterProvider getRequestParameters() {
    if (this.requestParameters != null) {
        return this.requestParameters;
    }
    if (this.parameterProviders == null) {
        return new SimpleParameterProvider();
    }
    // $NON-NLS-1$
    IParameterProvider requestParams = this.parameterProviders.get("request");
    SimpleParameterSetter parameters = new SimpleParameterSetter();
    Iterator requestParamIterator = requestParams.getParameterNames();
    while (requestParamIterator.hasNext()) {
        String param = (String) requestParamIterator.next();
        parameters.setParameter(param, requestParams.getParameter(param));
    }
    this.requestParameters = parameters;
    return parameters;
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) SimpleParameterSetter(org.pentaho.platform.engine.services.solution.SimpleParameterSetter) Iterator(java.util.Iterator) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Aggregations

IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)57 HashMap (java.util.HashMap)27 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)21 ArrayList (java.util.ArrayList)14 List (java.util.List)11 Test (org.junit.Test)11 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 IOException (java.io.IOException)9 Iterator (java.util.Iterator)8 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)8 HttpRequestParameterProvider (org.pentaho.platform.web.http.request.HttpRequestParameterProvider)8 MockHttpServletRequest (com.mockrunner.mock.web.MockHttpServletRequest)7 MockHttpServletResponse (com.mockrunner.mock.web.MockHttpServletResponse)7 IOutputHandler (org.pentaho.platform.api.engine.IOutputHandler)6 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)6 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)6 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)6 SimpleParameterSetter (org.pentaho.platform.engine.services.solution.SimpleParameterSetter)6 OutputStream (java.io.OutputStream)5