use of org.springframework.web.multipart.MultipartHttpServletRequest in project Activiti by Activiti.
the class DeploymentCollectionResource method uploadDeployment.
@RequestMapping(value = "/repository/deployments", method = RequestMethod.POST, produces = "application/json")
public DeploymentResponse uploadDeployment(@RequestParam(value = "tenantId", required = false) String tenantId, HttpServletRequest request, HttpServletResponse response) {
if (request instanceof MultipartHttpServletRequest == false) {
throw new ActivitiIllegalArgumentException("Multipart request is required");
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
if (multipartRequest.getFileMap().size() == 0) {
throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
}
MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
try {
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
String fileName = file.getOriginalFilename();
if (StringUtils.isEmpty(fileName) || !(fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn") || fileName.toLowerCase().endsWith(".bar") || fileName.toLowerCase().endsWith(".zip"))) {
fileName = file.getName();
}
if (fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn")) {
deploymentBuilder.addInputStream(fileName, file.getInputStream());
} else if (fileName.toLowerCase().endsWith(".bar") || fileName.toLowerCase().endsWith(".zip")) {
deploymentBuilder.addZipInputStream(new ZipInputStream(file.getInputStream()));
} else {
throw new ActivitiIllegalArgumentException("File must be of type .bpmn20.xml, .bpmn, .bar or .zip");
}
deploymentBuilder.name(fileName);
if (tenantId != null) {
deploymentBuilder.tenantId(tenantId);
}
Deployment deployment = deploymentBuilder.deploy();
response.setStatus(HttpStatus.CREATED.value());
return restResponseFactory.createDeploymentResponse(deployment);
} catch (Exception e) {
if (e instanceof ActivitiException) {
throw (ActivitiException) e;
}
throw new ActivitiException(e.getMessage(), e);
}
}
use of org.springframework.web.multipart.MultipartHttpServletRequest in project Activiti by Activiti.
the class ModelSourceExtraResource method setModelSource.
@RequestMapping(value = "/repository/models/{modelId}/source-extra", method = RequestMethod.PUT)
protected void setModelSource(@PathVariable String modelId, HttpServletRequest request, HttpServletResponse response) {
Model model = getModelFromRequest(modelId);
if (model != null) {
try {
if (request instanceof MultipartHttpServletRequest == false) {
throw new ActivitiIllegalArgumentException("Multipart request is required");
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
if (multipartRequest.getFileMap().size() == 0) {
throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
}
MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
repositoryService.addModelEditorSourceExtra(model.getId(), file.getBytes());
response.setStatus(HttpStatus.NO_CONTENT.value());
} catch (Exception e) {
throw new ActivitiException("Error adding model editor source extra", e);
}
}
}
use of org.springframework.web.multipart.MultipartHttpServletRequest in project Activiti by Activiti.
the class ModelSourceResource method setModelSource.
@RequestMapping(value = "/repository/models/{modelId}/source", method = RequestMethod.PUT)
protected void setModelSource(@PathVariable String modelId, HttpServletRequest request, HttpServletResponse response) {
Model model = getModelFromRequest(modelId);
if (model != null) {
if (request instanceof MultipartHttpServletRequest == false) {
throw new ActivitiIllegalArgumentException("Multipart request is required");
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
if (multipartRequest.getFileMap().size() == 0) {
throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
}
MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
try {
repositoryService.addModelEditorSource(modelId, file.getBytes());
response.setStatus(HttpStatus.NO_CONTENT.value());
} catch (Exception e) {
throw new ActivitiException("Error adding model editor source extra", e);
}
}
}
use of org.springframework.web.multipart.MultipartHttpServletRequest in project Activiti by Activiti.
the class TaskAttachmentCollectionResource method createAttachment.
@RequestMapping(value = "/runtime/tasks/{taskId}/attachments", method = RequestMethod.POST, produces = "application/json")
public AttachmentResponse createAttachment(@PathVariable String taskId, HttpServletRequest request, HttpServletResponse response) {
AttachmentResponse result = null;
Task task = getTaskFromRequest(taskId);
if (request instanceof MultipartHttpServletRequest) {
result = createBinaryAttachment((MultipartHttpServletRequest) request, task, response);
} else {
AttachmentRequest attachmentRequest = null;
try {
attachmentRequest = objectMapper.readValue(request.getInputStream(), AttachmentRequest.class);
} catch (Exception e) {
throw new ActivitiIllegalArgumentException("Failed to serialize to a AttachmentRequest instance", e);
}
if (attachmentRequest == null) {
throw new ActivitiIllegalArgumentException("AttachmentRequest properties not found in request");
}
result = createSimpleAttachment(attachmentRequest, task);
}
response.setStatus(HttpStatus.CREATED.value());
return result;
}
use of org.springframework.web.multipart.MultipartHttpServletRequest in project bigbluebutton by bigbluebutton.
the class HttpTunnelStreamController method handleCaptureUpdateRequest.
private void handleCaptureUpdateRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
String room = request.getParameterValues("room")[0];
// This data is never a keyframe
String keyframe = "false";
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Get the list of multipart files that are in this POST request.
// Get the block info from each embedded file and send it to the
// session manager to update the viewers.
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Iterator uploadedFilenames = multipartRequest.getFileNames();
while (uploadedFilenames.hasNext()) {
// process each embedded upload-file (block)
String uploadedFilename = (String) uploadedFilenames.next();
MultipartFile multipartFile = multipartRequest.getFile(uploadedFilename);
// Parse the block info out of the upload file name
// The file name is of format "blockgroup_<seqnum>_<position>".
String[] uploadedFileInfo = uploadedFilename.split("[_]");
String seqNum = uploadedFileInfo[1];
String position = uploadedFileInfo[2];
// Update the viewers with the uploaded block data.
sessionManager.updateBlock(room, Integer.valueOf(position), multipartFile.getBytes(), // This data is never a keyframe
false, Integer.parseInt(seqNum));
}
// process each embedded upload-file (block)
/*
// MultipartFile is a copy of file in memory, not in file system
MultipartFile multipartFile = multipartRequest.getFile("blockdata");
long startRx = System.currentTimeMillis();
byte[] blockData = multipartFile.getBytes();
String room = request.getParameterValues("room")[0];
String seqNum = request.getParameterValues("sequenceNumber")[0];
String keyframe = request.getParameterValues("keyframe")[0];
String position = request.getParameterValues("position")[0];
if (! hasSessionManager) {
sessionManager = getSessionManager();
hasSessionManager = true;
}
sessionManager.updateBlock(room, Integer.valueOf(position), blockData, Boolean.parseBoolean(keyframe), Integer.parseInt(seqNum));
*/
}
Aggregations