diff --git a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java index a881340cad..02ba3b6fce 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -42,26 +42,37 @@ import org.springframework.util.StreamUtils; 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} to read and write 'normal' HTML + * forms and also to write (but not read) multipart data (e.g. 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 the + * {@code "application/x-www-form-urlencoded"} media type as + * {@link MultiValueMap MultiValueMap<String, String>} and it can also + * write (but not read) the {@code "multipart/form-data"} media type as + * {@link MultiValueMap MultiValueMap<String, Object>}. * - *
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. + *
When writing multipart data this converter uses other + * {@link HttpMessageConverter HttpMessageConverters} to write the respective + * MIME parts. By default basic converters are registered (for {@code Strings} + * and {@code Resources}). These can be overridden through 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 {@code org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity}.
*
@@ -77,7 +88,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter