revised Servlet 3.0 based StandardServletMultipartResolver for correct param/file distinction; added multipart content type and headers access to MultipartRequest (dropping the previous header access solution on MultipartFile); MultipartFilter uses a Servlet 3.0 based StandardServletMultipartResolver by default

This commit is contained in:
Juergen Hoeller
2011-07-20 20:46:53 +00:00
parent 21f3f59cb7
commit 571535352b
30 changed files with 619 additions and 412 deletions

View File

@@ -41,8 +41,6 @@ import org.springframework.web.multipart.MultipartFile;
*/
public class MockMultipartFile implements MultipartFile {
private static final String CONTENT_TYPE = "Content-Type";
private final String name;
private String originalFilename;
@@ -133,26 +131,4 @@ public class MockMultipartFile implements MultipartFile {
FileCopyUtils.copy(this.content, dest);
}
public String getHeader(String name) {
if (CONTENT_TYPE.equalsIgnoreCase(name)) {
return this.contentType;
}
else {
return null;
}
}
public String[] getHeaders(String name) {
if (CONTENT_TYPE.equalsIgnoreCase(name)) {
return new String[] {this.contentType};
}
else {
return null;
}
}
public Iterator<String> getHeaderNames() {
return Collections.singleton(CONTENT_TYPE).iterator();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,4 +82,14 @@ public class MockMultipartActionRequest extends MockActionRequest implements Mul
return new LinkedMultiValueMap<String, MultipartFile>(this.multipartFiles);
}
public String getMultipartContentType(String paramOrFileName) {
MultipartFile file = getFile(paramOrFileName);
if (file != null) {
return file.getContentType();
}
else {
return null;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.springframework.web.portlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -481,7 +482,7 @@ public class ComplexPortletApplicationContext extends StaticPortletApplicationCo
files.set("someFile", new MockMultipartFile("someFile", "someContent".getBytes()));
Map<String, String[]> params = new HashMap<String, String[]>();
params.put("someParam", new String[] {"someParam"});
return new DefaultMultipartActionRequest(request, files, params);
return new DefaultMultipartActionRequest(request, files, params, Collections.<String, String>emptyMap());
}
public void cleanupMultipart(MultipartActionRequest request) {