Search in sources :

Example 66 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-business-process by wso2.

the class AxisServiceUtils method createAxisServiceBuilder.

private static WSDL11ToAxisServiceBuilder createAxisServiceBuilder(BPELProcessProxy processProxy) throws AxisFault {
    Definition wsdlDef = processProxy.getWsdlDefinition();
    QName serviceName = processProxy.getServiceName();
    String portName = processProxy.getPort();
    ProcessConf pConf = processProxy.getProcessConfiguration();
    QName pid = pConf.getProcessId();
    InputStream wsdlInStream = null;
    URI wsdlBaseURI = pConf.getBaseURI().resolve(wsdlDef.getDocumentBaseURI());
    try {
        wsdlInStream = wsdlBaseURI.toURL().openStream();
    } catch (MalformedURLException e) {
        String errMsg = "Malformed WSDL base URI.";
        handleException(pid, errMsg, e);
    } catch (IOException e) {
        String errMsg = "Error opening stream.";
        handleException(pid, errMsg, e);
    }
    WSDL11ToAxisServiceBuilder serviceBuilder = new WSDL11ToAxisPatchedBuilder(wsdlInStream, serviceName, portName);
    serviceBuilder.setBaseUri(wsdlBaseURI.toString());
    serviceBuilder.setCustomResolver(new Axis2UriResolver());
    try {
        serviceBuilder.setCustomWSDLResolver(new Axis2WSDLLocator(wsdlBaseURI));
    } catch (URISyntaxException e) {
        String errorMessage = "URI syntax invalid.";
        handleException(pid, errorMessage, e);
    }
    serviceBuilder.setServerSide(true);
    return serviceBuilder;
}
Also used : Axis2UriResolver(org.wso2.carbon.bpel.core.ode.integration.axis2.Axis2UriResolver) MalformedURLException(java.net.MalformedURLException) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) ProcessConf(org.apache.ode.bpel.iapi.ProcessConf) Definition(javax.wsdl.Definition) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) WSDL11ToAxisServiceBuilder(org.apache.axis2.description.WSDL11ToAxisServiceBuilder) Axis2WSDLLocator(org.wso2.carbon.bpel.core.ode.integration.axis2.Axis2WSDLLocator)

Example 67 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-business-process by wso2.

the class BPSAnalyticsConfiguration method initConfigurationFromFile.

/**
 * Initialize the configuration object from the properties in the BPS Analytics config xml file.
 */
private void initConfigurationFromFile(File BPSAnalyticsConfigurationFile) {
    SecretResolver secretResolver = null;
    try (InputStream in = new FileInputStream(BPSAnalyticsConfigurationFile)) {
        StAXOMBuilder builder = new StAXOMBuilder(in);
        secretResolver = SecretResolverFactory.create(builder.getDocumentElement(), true);
    } catch (Exception e) {
        log.warn("Error occurred while retrieving secured BPS Analytics configuration.", e);
    }
    TBPSAnalytics tBPSAnalytics = bpsAnalyticsDocument.getBPSAnalytics();
    if (tBPSAnalytics == null) {
        return;
    }
    if (tBPSAnalytics.getAnalyticServer() != null) {
        initAnalytics(secretResolver, tBPSAnalytics.getAnalyticServer());
    }
    if (tBPSAnalytics.getBPMN() != null) {
        initBPMNAnalytics(tBPSAnalytics.getBPMN());
    }
}
Also used : SecretResolver(org.wso2.securevault.SecretResolver) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlException(org.apache.xmlbeans.XmlException) TBPSAnalytics(org.wso2.carbon.bps.common.analytics.config.TBPSAnalytics)

Example 68 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-business-process by wso2.

the class ProcessInstanceService method getProcessInstanceDiagram.

@GET
@Path("/{processInstanceId}/diagram")
@Produces(MediaType.APPLICATION_JSON)
public Response getProcessInstanceDiagram(@PathParam("processInstanceId") String processInstanceId) {
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    ProcessDefinition pde = repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
    if (pde != null && pde.hasGraphicalNotation()) {
        RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
        InputStream diagramStream = new DefaultProcessDiagramGenerator().generateDiagram(repositoryService.getBpmnModel(pde.getId()), "png", runtimeService.getActiveActivityIds(processInstanceId));
        try {
            return Response.ok().type("image/png").entity(IOUtils.toByteArray(diagramStream)).build();
        } catch (Exception e) {
            throw new ActivitiIllegalArgumentException("Error exporting diagram", e);
        }
    } else {
        throw new ActivitiIllegalArgumentException("Process instance with id '" + processInstance.getId() + "' has no graphical notation defined.");
    }
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) ActivitiException(org.activiti.engine.ActivitiException) ServletException(javax.servlet.ServletException) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) BPMNContentNotSupportedException(org.wso2.carbon.bpmn.rest.common.exception.BPMNContentNotSupportedException) XMLStreamException(javax.xml.stream.XMLStreamException) BPMNConflictException(org.wso2.carbon.bpmn.rest.common.exception.BPMNConflictException) JAXBException(javax.xml.bind.JAXBException) NotFoundException(javax.ws.rs.NotFoundException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) IOException(java.io.IOException) RestApiBasicAuthenticationException(org.wso2.carbon.bpmn.rest.common.exception.RestApiBasicAuthenticationException) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 69 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-business-process by wso2.

the class AttachmentDownloadServlet method doGet.

/**
 * Logic that will be executed for a get request.
 *
 * @param request  the HTTP Servlet request.
 * @param response the HTTP Servlet response.
 * @throws ServletException if an error occurred.
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String url = request.getRequestURI();
    String attachmentUniqueID = url.substring(url.lastIndexOf("/") + 1);
    InputStream contentStream = null;
    ServletOutputStream servletOutputStream = null;
    try {
        TAttachment fileAttachment = getFileFromUniqueID(url);
        response.setHeader("Content-Disposition", "attachment; filename=" + fileAttachment.getName());
        response.setContentType(fileAttachment.getContentType());
        contentStream = fileAttachment.getContent().getInputStream();
        servletOutputStream = response.getOutputStream();
        IOUtils.copy(contentStream, servletOutputStream);
        servletOutputStream.flush();
    } catch (AttachmentMgtException e) {
        throw new ServletException(e.getLocalizedMessage(), e);
    } finally {
        IOUtils.closeQuietly(contentStream);
        IOUtils.closeQuietly(servletOutputStream);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) ServletException(javax.servlet.ServletException) TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment) ServletOutputStream(javax.servlet.ServletOutputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream)

Example 70 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-business-process by wso2.

the class BaseExecutionService method createBinaryExecutionVariable.

protected RestVariable createBinaryExecutionVariable(Execution execution, int responseVariableType, UriInfo uriInfo, boolean isNew, MultipartBody multipartBody) {
    boolean debugEnabled = log.isDebugEnabled();
    Response.ResponseBuilder responseBuilder = Response.ok();
    List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments = multipartBody.getAllAttachments();
    int attachmentSize = attachments.size();
    if (attachmentSize <= 0) {
        throw new ActivitiIllegalArgumentException("No Attachments found with the request body");
    }
    AttachmentDataHolder attachmentDataHolder = new AttachmentDataHolder();
    for (int i = 0; i < attachmentSize; i++) {
        org.apache.cxf.jaxrs.ext.multipart.Attachment attachment = attachments.get(i);
        String contentDispositionHeaderValue = attachment.getHeader("Content-Disposition");
        String contentType = attachment.getHeader("Content-Type");
        if (debugEnabled) {
            log.debug("Going to iterate:" + i);
            log.debug("contentDisposition:" + contentDispositionHeaderValue);
        }
        if (contentDispositionHeaderValue != null) {
            contentDispositionHeaderValue = contentDispositionHeaderValue.trim();
            Map<String, String> contentDispositionHeaderValueMap = Utils.processContentDispositionHeader(contentDispositionHeaderValue);
            String dispositionName = contentDispositionHeaderValueMap.get("name");
            DataHandler dataHandler = attachment.getDataHandler();
            OutputStream outputStream = null;
            if ("name".equals(dispositionName)) {
                try {
                    outputStream = Utils.getAttachmentStream(dataHandler.getInputStream());
                } catch (IOException e) {
                    throw new ActivitiIllegalArgumentException("Attachment Name Reading error occured", e);
                }
                if (outputStream != null) {
                    String fileName = outputStream.toString();
                    attachmentDataHolder.setName(fileName);
                }
            } else if ("type".equals(dispositionName)) {
                try {
                    outputStream = Utils.getAttachmentStream(dataHandler.getInputStream());
                } catch (IOException e) {
                    throw new ActivitiIllegalArgumentException("Attachment Type Reading error occured", e);
                }
                if (outputStream != null) {
                    String typeName = outputStream.toString();
                    attachmentDataHolder.setType(typeName);
                }
            } else if ("scope".equals(dispositionName)) {
                try {
                    outputStream = Utils.getAttachmentStream(dataHandler.getInputStream());
                } catch (IOException e) {
                    throw new ActivitiIllegalArgumentException("Attachment Description Reading error occured", e);
                }
                if (outputStream != null) {
                    String description = outputStream.toString();
                    attachmentDataHolder.setScope(description);
                }
            }
            if (contentType != null) {
                if ("file".equals(dispositionName)) {
                    InputStream inputStream = null;
                    try {
                        inputStream = dataHandler.getInputStream();
                    } catch (IOException e) {
                        throw new ActivitiIllegalArgumentException("Error Occured During processing empty body.", e);
                    }
                    if (inputStream != null) {
                        attachmentDataHolder.setContentType(contentType);
                        byte[] attachmentArray = new byte[0];
                        try {
                            attachmentArray = IOUtils.toByteArray(inputStream);
                        } catch (IOException e) {
                            throw new ActivitiIllegalArgumentException("Processing Attachment Body Failed.", e);
                        }
                        attachmentDataHolder.setAttachmentArray(attachmentArray);
                    }
                }
            }
        }
    }
    attachmentDataHolder.printDebug();
    if (attachmentDataHolder.getName() == null) {
        throw new ActivitiIllegalArgumentException("Attachment name is required.");
    }
    if (attachmentDataHolder.getAttachmentArray() == null) {
        throw new ActivitiIllegalArgumentException("Empty attachment body was found in request body after " + "decoding the request" + ".");
    }
    String variableScope = attachmentDataHolder.getScope();
    String variableName = attachmentDataHolder.getName();
    String variableType = attachmentDataHolder.getType();
    if (log.isDebugEnabled()) {
        log.debug("variableScope:" + variableScope + " variableName:" + variableName + " variableType:" + variableType);
    }
    try {
        // Validate input and set defaults
        if (variableName == null) {
            throw new ActivitiIllegalArgumentException("No variable name was found in request body.");
        }
        if (variableType != null) {
            if (!RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variableType) && !RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variableType)) {
                throw new ActivitiIllegalArgumentException("Only 'binary' and 'serializable' are supported as variable type.");
            }
        } else {
            variableType = RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE;
        }
        RestVariable.RestVariableScope scope = RestVariable.RestVariableScope.LOCAL;
        if (variableScope != null) {
            scope = RestVariable.getScopeFromString(variableScope);
        }
        if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variableType)) {
            // Use raw bytes as variable value
            setVariable(execution, variableName, attachmentDataHolder.getAttachmentArray(), scope, isNew);
        } else {
            // Try deserializing the object
            try (InputStream inputStream = new ByteArrayInputStream(attachmentDataHolder.getAttachmentArray());
                ObjectInputStream stream = new ObjectInputStream(inputStream)) {
                Object value = stream.readObject();
                setVariable(execution, variableName, value, scope, isNew);
            }
        }
        if (responseVariableType == RestResponseFactory.VARIABLE_PROCESS) {
            return new RestResponseFactory().createBinaryRestVariable(variableName, scope, variableType, null, null, execution.getId(), uriInfo.getBaseUri().toString());
        } else {
            return new RestResponseFactory().createBinaryRestVariable(variableName, scope, variableType, null, execution.getId(), null, uriInfo.getBaseUri().toString());
        }
    } catch (IOException ioe) {
        throw new ActivitiIllegalArgumentException("Could not process multipart content", ioe);
    } catch (ClassNotFoundException ioe) {
        throw new BPMNContentNotSupportedException("The provided body contains a serialized object for which the class is nog found: " + ioe.getMessage());
    }
}
Also used : DataHandler(javax.activation.DataHandler) BPMNContentNotSupportedException(org.wso2.carbon.bpmn.rest.common.exception.BPMNContentNotSupportedException) RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) JAXBContext(javax.xml.bind.JAXBContext) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response)

Aggregations

Test (org.testng.annotations.Test)80 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)67 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)58 InputStream (java.io.InputStream)54 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)54 Event (org.wso2.siddhi.core.event.Event)48 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)47 IOException (java.io.IOException)32 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)24 ByteArrayInputStream (java.io.ByteArrayInputStream)20 API (org.wso2.carbon.apimgt.core.models.API)18 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)17 FileInputStream (java.io.FileInputStream)15 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)13 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)12 Response (javax.ws.rs.core.Response)11 HashMap (java.util.HashMap)9 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)8 File (java.io.File)7 Connection (java.sql.Connection)7