Search in sources :

Example 11 with MultipartHttpServletRequest

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);
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ZipInputStream(java.util.zip.ZipInputStream) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Deployment(org.activiti.engine.repository.Deployment) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with MultipartHttpServletRequest

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);
        }
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Model(org.activiti.engine.repository.Model) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with MultipartHttpServletRequest

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);
        }
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Model(org.activiti.engine.repository.Model) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with MultipartHttpServletRequest

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;
}
Also used : Task(org.activiti.engine.task.Task) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) AttachmentResponse(org.activiti.rest.service.api.engine.AttachmentResponse) AttachmentRequest(org.activiti.rest.service.api.engine.AttachmentRequest) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with MultipartHttpServletRequest

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));
*/
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest)

Aggregations

MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)23 MultipartFile (org.springframework.web.multipart.MultipartFile)11 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)10 ActivitiException (org.activiti.engine.ActivitiException)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)6 RestVariable (org.activiti.rest.service.api.engine.variable.RestVariable)5 Test (org.junit.Test)5 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)5 ArrayList (java.util.ArrayList)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)4 File (java.io.File)3 MockServletContext (org.springframework.mock.web.test.MockServletContext)3 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)3 HashMap (java.util.HashMap)2 List (java.util.List)2 FilterChain (javax.servlet.FilterChain)2 ServletRequest (javax.servlet.ServletRequest)2 ServletResponse (javax.servlet.ServletResponse)2