Search in sources :

Example 26 with MultipartHttpServletRequest

use of org.springframework.web.multipart.MultipartHttpServletRequest in project gocd by gocd.

the class FakeArtifactPublisherServlet method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
    MultipartHttpServletRequest httpServletRequest = multipartResolver.resolveMultipart(request);
    Map<String, MultipartFile> map = httpServletRequest.getFileMap();
    MultipartFile multipartFile = map.values().iterator().next();
    receivedFiles.add(multipartFile.getOriginalFilename());
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) CommonsMultipartResolver(org.springframework.web.multipart.commons.CommonsMultipartResolver) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest)

Example 27 with MultipartHttpServletRequest

use of org.springframework.web.multipart.MultipartHttpServletRequest in project gocd by gocd.

the class ArtifactsControllerTest method shouldReturnBadRequestIfRequiredHeadersAreMissingOnACreateArtifactRequest.

@Test
public void shouldReturnBadRequestIfRequiredHeadersAreMissingOnACreateArtifactRequest() throws Exception {
    MultipartHttpServletRequest multipartHttpServletRequest = new MockMultipartHttpServletRequest();
    when(systemEnvironment.isApiSafeModeEnabled()).thenReturn(true);
    ModelAndView modelAndView = artifactsController.postArtifact("pipeline", "invalid-label", "stage", "stage-counter", "job-name", 3L, "file-path", 3, multipartHttpServletRequest);
    ResponseCodeView codeView = (ResponseCodeView) modelAndView.getView();
    assertThat(codeView.getStatusCode(), is(HttpServletResponse.SC_BAD_REQUEST));
    assertThat(codeView.getContent(), is("Missing required header 'Confirm'"));
}
Also used : MockMultipartHttpServletRequest(org.springframework.mock.web.MockMultipartHttpServletRequest) ResponseCodeView(com.thoughtworks.go.server.web.ResponseCodeView) ModelAndView(org.springframework.web.servlet.ModelAndView) MockMultipartHttpServletRequest(org.springframework.mock.web.MockMultipartHttpServletRequest) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 28 with MultipartHttpServletRequest

use of org.springframework.web.multipart.MultipartHttpServletRequest in project grails-core by grails.

the class DefaultUrlMappingInfo method tryMultipartParams.

private Enumeration<String> tryMultipartParams(HttpServletRequest request, Enumeration<String> originalParams) {
    Enumeration<String> paramNames = originalParams;
    boolean disabled = isMultipartDisabled();
    if (!disabled) {
        MultipartResolver resolver = getMultipartResolver();
        if (resolver != null && resolver.isMultipart(request)) {
            MultipartHttpServletRequest resolvedMultipartRequest = getResolvedRequest(request, resolver);
            paramNames = resolvedMultipartRequest.getParameterNames();
        }
    }
    return paramNames;
}
Also used : MultipartResolver(org.springframework.web.multipart.MultipartResolver) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest)

Example 29 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)

Example 30 with MultipartHttpServletRequest

use of org.springframework.web.multipart.MultipartHttpServletRequest in project spring-framework by spring-projects.

the class CommonsMultipartResolverTests method withServletContextAndFilterWithCustomBeanName.

@Test
public void withServletContextAndFilterWithCustomBeanName() throws Exception {
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(new MockServletContext());
    wac.refresh();
    wac.registerSingleton("myMultipartResolver", MockCommonsMultipartResolver.class, new MutablePropertyValues());
    wac.getServletContext().setAttribute(WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE, new File("mytemp"));
    wac.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    CommonsMultipartResolver resolver = new CommonsMultipartResolver(wac.getServletContext());
    assertTrue(resolver.getFileItemFactory().getRepository().getAbsolutePath().endsWith("mytemp"));
    MockFilterConfig filterConfig = new MockFilterConfig(wac.getServletContext(), "filter");
    filterConfig.addInitParameter("multipartResolverBeanName", "myMultipartResolver");
    final List<MultipartFile> files = new ArrayList<>();
    FilterChain filterChain = new FilterChain() {

        @Override
        public void doFilter(ServletRequest originalRequest, ServletResponse response) {
            if (originalRequest instanceof MultipartHttpServletRequest) {
                MultipartHttpServletRequest request = (MultipartHttpServletRequest) originalRequest;
                files.addAll(request.getFileMap().values());
            }
        }
    };
    MultipartFilter filter = new MultipartFilter() {

        private boolean invoked = false;

        @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
            super.doFilterInternal(request, response, filterChain);
            super.doFilterInternal(request, response, filterChain);
            if (invoked) {
                throw new ServletException("Should not have been invoked twice");
            }
            invoked = true;
        }
    };
    filter.init(filterConfig);
    MockHttpServletRequest originalRequest = new MockHttpServletRequest();
    originalRequest.setMethod("POST");
    originalRequest.setContentType("multipart/form-data");
    originalRequest.addHeader("Content-type", "multipart/form-data");
    HttpServletResponse response = new MockHttpServletResponse();
    filter.doFilter(originalRequest, response, filterChain);
    CommonsMultipartFile file1 = (CommonsMultipartFile) files.get(0);
    CommonsMultipartFile file2 = (CommonsMultipartFile) files.get(1);
    assertTrue(((MockFileItem) file1.getFileItem()).deleted);
    assertTrue(((MockFileItem) file2.getFileItem()).deleted);
}
Also used : MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) MultipartFilter(org.springframework.web.multipart.support.MultipartFilter) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) FilterChain(javax.servlet.FilterChain) PassThroughFilterChain(org.springframework.mock.web.test.PassThroughFilterChain) ArrayList(java.util.ArrayList) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) MockServletContext(org.springframework.mock.web.test.MockServletContext) MockFilterConfig(org.springframework.mock.web.test.MockFilterConfig) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ServletException(javax.servlet.ServletException) MultipartFile(org.springframework.web.multipart.MultipartFile) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) Test(org.junit.Test)

Aggregations

MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)44 MultipartFile (org.springframework.web.multipart.MultipartFile)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 File (java.io.File)11 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)10 ActivitiException (org.activiti.engine.ActivitiException)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)6 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)6 HashMap (java.util.HashMap)5 RestVariable (org.activiti.rest.service.api.engine.variable.RestVariable)5 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)2 OptUploadFileRespDto (com.paascloud.provider.model.dto.oss.OptUploadFileRespDto)2 ApiOperation (io.swagger.annotations.ApiOperation)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStreamReader (java.io.InputStreamReader)2 Date (java.util.Date)2 List (java.util.List)2