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());
}
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'"));
}
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;
}
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));
*/
}
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);
}
Aggregations