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;
}
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());
}
}
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.");
}
}
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);
}
}
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());
}
}
Aggregations