Skip to content

Commit 977084a

Browse files
committed
Correct documentation of default HttpMessageConverters in RestTemplate
Issue: SPR-7885 (cherry picked from commit 442ddb0)
1 parent 0e7e49b commit 977084a

File tree

2 files changed

+32
-36
lines changed

2 files changed

+32
-36
lines changed

spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,8 +61,10 @@
6161
*
6262
* <p>For example, the following snippet shows how to submit an HTML form:
6363
* <pre class="code">
64-
* RestTemplate template = new RestTemplate(); // FormHttpMessageConverter is configured by default
65-
* MultiValueMap&lt;String, String&gt; form = new LinkedMultiValueMap&lt;String, String&gt;();
64+
* RestTemplate template = new RestTemplate();
65+
* // AllEncompassingFormHttpMessageConverter is configured by default
66+
*
67+
* MultiValueMap&lt;String, String&gt; form = new LinkedMultiValueMap&lt;&gt;();
6668
* form.add("field 1", "value 1");
6769
* form.add("field 2", "value 2");
6870
* form.add("field 2", "value 3");
@@ -71,7 +73,7 @@
7173
*
7274
* <p>The following snippet shows how to do a file upload:
7375
* <pre class="code">
74-
* MultiValueMap&lt;String, Object&gt; parts = new LinkedMultiValueMap&lt;String, Object&gt;();
76+
* MultiValueMap&lt;String, Object&gt; parts = new LinkedMultiValueMap&lt;&gt;();
7577
* parts.add("field 1", "value 1");
7678
* parts.add("file", new ClassPathResource("myFile.jpg"));
7779
* template.postForLocation("http://example.com/myFileUpload", parts);
@@ -84,7 +86,8 @@
8486
* @author Rossen Stoyanchev
8587
* @author Juergen Hoeller
8688
* @since 3.0
87-
* @see MultiValueMap
89+
* @see org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter
90+
* @see org.springframework.util.MultiValueMap
8891
*/
8992
public class FormHttpMessageConverter implements HttpMessageConverter<MultiValueMap<String, ?>> {
9093

src/asciidoc/integration.adoc

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,23 +1059,23 @@ exception processing the HTTP request, an exception of the type `RestClientExcep
10591059
will be thrown; this behavior can be changed by plugging in another
10601060
`ResponseErrorHandler` implementation into the `RestTemplate`.
10611061

1062-
The `exchange` and `execute` methods are generalized versions of the more
1063-
specific methods listed above them and can support additional combinations and methods,
1064-
like HTTP PATCH. However, note that the underlying HTTP library must also support the
1065-
desired combination. The JDK `HttpURLConnection` does not support the `PATCH` method, but
1066-
Apache HttpComponents HttpClient version 4.2 or later does. They also enable
1067-
`RestTemplate` to read an HTTP response to a generic type (e.g. `List<Account>`), using a
1068-
`ParameterizedTypeReference`, a new class that enables capturing and passing generic
1069-
type info.
1062+
The `exchange` and `execute` methods are generalized versions of the more specific
1063+
methods listed above them and can support additional combinations and methods,
1064+
e.g. HTTP PATCH. However, note that the underlying HTTP library must also support the
1065+
desired combination. The JDK `HttpURLConnection` does not support the `PATCH` method
1066+
but Apache HttpComponents HttpClient version 4.2 or later does. They also enable
1067+
`RestTemplate` to read an HTTP response to a generic type (e.g. `List<Account>`),
1068+
using a `ParameterizedTypeReference`, a new class that enables capturing and passing
1069+
generic type info.
10701070

10711071
Objects passed to and returned from these methods are converted to and from HTTP
1072-
messages by `HttpMessageConverter` instances. Converters for the main mime types are
1073-
registered by default, but you can also write your own converter and register it via the
1074-
`messageConverters()` bean property. The default converter instances registered with the
1075-
template are `ByteArrayHttpMessageConverter`, `StringHttpMessageConverter`,
1076-
`FormHttpMessageConverter` and `SourceHttpMessageConverter`. You can override these
1077-
defaults using the `messageConverters()` bean property as would be required if using the
1078-
`MarshallingHttpMessageConverter` or `MappingJackson2HttpMessageConverter`.
1072+
messages by `HttpMessageConverter` implementations. Converters for the main MIME types
1073+
are registered by default, but you can also override the defaults and register custom
1074+
converters via the `messageConverters()` bean property. The default converters are
1075+
`ByteArrayHttpMessageConverter`, `StringHttpMessageConverter`,
1076+
`ResourceHttpMessageConverter`, `SourceHttpMessageConverter` as well as
1077+
`AllEncompassingFormHttpMessageConverter` and a few provider-specific converters:
1078+
e.g. `MappingJackson2HttpMessageConverter` when Jackson is present on the classpath.
10791079

10801080
Each method takes URI template arguments in two forms, either as a `String`
10811081
variable-length argument or a `Map<String,String>`. For example,
@@ -5778,9 +5778,8 @@ exception hierarchy.
57785778

57795779
The `org.springframework.mail.javamail.JavaMailSender` interface adds specialized
57805780
__JavaMail__ features such as MIME message support to the `MailSender` interface (from
5781-
which it inherits). `JavaMailSender` also provides a callback interface for preparation
5782-
of JavaMail MIME messages, called
5783-
`org.springframework.mail.javamail.MimeMessagePreparator`
5781+
which it inherits). `JavaMailSender` also provides a callback interface for preparing
5782+
a 'MimeMessage', called `org.springframework.mail.javamail.MimeMessagePreparator`.
57845783

57855784

57865785

@@ -5903,23 +5902,17 @@ callback interface. Please note in this case that the `mailSender` property is o
59035902
}
59045903
59055904
public void placeOrder(final Order order) {
5906-
59075905
// Do the business calculations...
5908-
59095906
// Call the collaborators to persist the order...
59105907
59115908
MimeMessagePreparator preparator = new MimeMessagePreparator() {
5912-
59135909
public void prepare(MimeMessage mimeMessage) throws Exception {
5914-
59155910
mimeMessage.setRecipient(Message.RecipientType.TO,
59165911
new InternetAddress(order.getCustomer().getEmailAddress()));
59175912
mimeMessage.setFrom(new InternetAddress("[email protected]"));
5918-
mimeMessage.setText(
5919-
"Dear " + order.getCustomer().getFirstName() + " "
5920-
+ order.getCustomer().getLastName()
5921-
+ ", thank you for placing order. Your order number is "
5922-
+ order.getOrderNumber());
5913+
mimeMessage.setText("Dear " + order.getCustomer().getFirstName() + " " +
5914+
order.getCustomer().getLastName() + ", thanks for your order. " +
5915+
"Your order number is " + order.getOrderNumber() + ".");
59235916
}
59245917
};
59255918
@@ -6035,10 +6028,10 @@ along with an inline image.
60356028

60366029
[WARNING]
60376030
====
6038-
Inline resources are added to the mime message using the specified `Content-ID` (
6039-
`identifier1234` in the above example). The order in which you are adding the text and
6040-
the resource are __very__ important. Be sure to __first add the text__ and after that
6041-
the resources. If you are doing it the other way around, it won't work!
6031+
Inline resources are added to the `MimeMessage` using the specified `Content-ID`
6032+
(`identifier1234` in the above example). The order in which you are adding the text
6033+
and the resource are __very__ important. Be sure to __first add the text__ and after
6034+
that the resources. If you are doing it the other way around, it won't work!
60426035
====
60436036

60446037

0 commit comments

Comments
 (0)