diff --git a/org.springframework.web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java b/org.springframework.web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java index 144f98e738..00971f2715 100644 --- a/org.springframework.web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java +++ b/org.springframework.web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java @@ -45,35 +45,26 @@ import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; /** - * Implementation of {@link HttpMessageConverter} that can handle form data, including multipart form data - * (i.e. file uploads). + * Implementation of {@link HttpMessageConverter} that can handle form data, including multipart form data (i.e. file + * uploads). * *
This converter can write the {@code application/x-www-form-urlencoded} and {@code multipart/form-data} media * types, and read the {@code application/x-www-form-urlencoded}) media type (but not {@code multipart/form-data}). * - *
In other words, this converter can read and write 'normal' HTML forms (as - * {@link MultiValueMap MultiValueMap<String, String>}), and it can write multipart form (as - * {@link MultiValueMap MultiValueMap<String, Object>}. When writing multipart, this converter uses other - * {@link HttpMessageConverter HttpMessageConverters} to write the respective MIME parts. By default, basic converters - * are registered (supporting {@code Strings} and {@code Resources}, for instance); these can be overridden by setting - * the {@link #setPartConverters(java.util.List) partConverters} property. + *
In other words, this converter can read and write 'normal' HTML forms (as {@link MultiValueMap + * MultiValueMap<String, String>}), and it can write multipart form (as {@link MultiValueMap + * MultiValueMap<String, Object>}. When writing multipart, this converter uses other {@link HttpMessageConverter + * HttpMessageConverters} to write the respective MIME parts. By default, basic converters are registered (supporting + * {@code Strings} and {@code Resources}, for instance); these can be overridden by setting the {@link + * #setPartConverters(java.util.List) partConverters} property. * - *
For example, the following snippet shows how to submit an HTML form: - *
- * RestTemplate template = new RestTemplate(); // FormHttpMessageConverter is configured by default - * MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); - * form.add("field 1", "value 1"); - * form.add("field 2", "value 2"); - * form.add("field 2", "value 3"); - * template.postForLocation("http://example.com/myForm", form); - *- *
The following snippet shows how to do a file upload: - *
- * MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>(); - * parts.add("field 1", "value 1"); - * parts.add("file", new ClassPathResource("myFile.jpg")); - * template.postForLocation("http://example.com/myFileUpload", parts); - *+ *
For example, the following snippet shows how to submit an HTML form:
RestTemplate template = + * new RestTemplate(); // FormHttpMessageConverter is configured by default MultiValueMap<String, String> form = + * new LinkedMultiValueMap<String, String>(); form.add("field 1", "value 1"); form.add("field 2", "value 2"); + * form.add("field 2", "value 3"); template.postForLocation("http://example.com/myForm", form);
The following + * snippet shows how to do a file upload:
MultiValueMap<String, Object> parts = new + * LinkedMultiValueMap<String, Object>(); parts.add("field 1", "value 1"); parts.add("file", new + * ClassPathResource("myFile.jpg")); template.postForLocation("http://example.com/myFileUpload", parts);* *
Some methods in this class were inspired by {@link org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity}.
*
@@ -87,7 +78,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter Default implementation returns a random boundary. Can be overridden in
+ * subclasses.
*/
protected byte[] generateMultipartBoundary() {
byte[] boundary = new byte[rnd.nextInt(11) + 30];
@@ -321,8 +312,9 @@ public class FormHttpMessageConverter implements HttpMessageConverter Default implementation returns {@link Resource#getFilename()} if the part is a {@code Resource}, and {@code null}
+ * in other cases. Can be overridden in subclasses.
+ *
* @param part the part to determine the file name for
* @return the filename, or {@code null} if not known
*/
@@ -336,10 +328,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter