Skip to content

Commit ddcd9f4

Browse files
committed
SPR-5836 - RestTemplate - postForObject() method
1 parent 4ea373b commit ddcd9f4

File tree

4 files changed

+251
-133
lines changed

4 files changed

+251
-133
lines changed

org.springframework.web/src/main/java/org/springframework/web/client/RestOperations.java

Lines changed: 103 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -24,176 +24,203 @@
2424
import org.springframework.http.HttpMethod;
2525

2626
/**
27-
* Interface specifying a basic set of RESTful operations.
28-
* Implemented by {@link RestTemplate}. Not often used directly, but a useful
29-
* option to enhance testability, as it can easily be mocked or stubbed.
27+
* Interface specifying a basic set of RESTful operations. Implemented by {@link RestTemplate}. Not often used directly,
28+
* but a useful option to enhance testability, as it can easily be mocked or stubbed.
3029
*
3130
* @author Arjen Poutsma
32-
* @since 3.0
3331
* @see RestTemplate
32+
* @since 3.0
3433
*/
3534
public interface RestOperations {
3635

3736
// GET
3837

3938
/**
40-
* Retrieve a representation by doing a GET on the specified URL.
39+
* Retrieve a representation by doing a GET on the specified URL. The response (if any) is converted and returned.
4140
* <p>URI Template variables are expanded using the given URI variables, if any.
42-
* @param uri the URI
41+
*
42+
* @param url the URL
4343
* @param responseType the type of the return value
4444
* @param uriVariables the variables to expand the template
4545
* @return the converted object
4646
*/
47-
<T> T getForObject(String uri, Class<T> responseType, String... uriVariables) throws RestClientException;
47+
<T> T getForObject(String url, Class<T> responseType, String... uriVariables) throws RestClientException;
4848

4949
/**
50-
* Retrieve a representation by doing a GET on the URI template.
50+
* Retrieve a representation by doing a GET on the URI template. The response (if any) is converted and returned.
5151
* <p>URI Template variables are expanded using the given map.
52-
* @param uri the URI
52+
*
53+
* @param url the URL
5354
* @param responseType the type of the return value
5455
* @param uriVariables the map containing variables for the URI template
5556
* @return the converted object
5657
*/
57-
<T> T getForObject(String uri, Class<T> responseType, Map<String, String> uriVariables) throws RestClientException;
58-
58+
<T> T getForObject(String url, Class<T> responseType, Map<String, String> uriVariables) throws RestClientException;
5959

6060
// HEAD
6161

6262
/**
63-
* Retrieve all headers of the resource specified by the URI template.
64-
* <p>URI Template variables are expanded using the given URI variables, if any.
65-
* @param uri the URI
63+
* Retrieve all headers of the resource specified by the URI template. <p>URI Template variables are expanded using the
64+
* given URI variables, if any.
65+
*
66+
* @param url the URL
6667
* @param uriVariables the variables to expand the template
6768
* @return all HTTP headers of that resource
6869
*/
69-
HttpHeaders headForHeaders(String uri, String... uriVariables) throws RestClientException;
70+
HttpHeaders headForHeaders(String url, String... uriVariables) throws RestClientException;
7071

7172
/**
72-
* Retrieve all headers of the resource specified by the URI template.
73-
* <p>URI Template variables are expanded using the given map.
74-
* @param uri the URI
73+
* Retrieve all headers of the resource specified by the URI template. <p>URI Template variables are expanded using the
74+
* given map.
75+
*
76+
* @param url the URL
7577
* @param uriVariables the map containing variables for the URI template
7678
* @return all HTTP headers of that resource
7779
*/
78-
HttpHeaders headForHeaders(String uri, Map<String, String> uriVariables) throws RestClientException;
79-
80+
HttpHeaders headForHeaders(String url, Map<String, String> uriVariables) throws RestClientException;
8081

8182
// POST
8283

8384
/**
84-
* Create a new resource by POSTing the given object to the URI template. The value of the <code>Location</code>
85-
* header, indicating where the new resource is stored, is returned.
86-
* <p>URI Template variables are expanded using the given URI variables, if any.
87-
* @param uri the URI
85+
* Create a new resource by POSTing the given object to the URI template, and returns the value of the
86+
* <code>Location</code> header. This header typically indicates where the new resource is stored. <p>URI Template
87+
* variables are expanded using the given URI variables, if any.
88+
*
89+
* @param url the URL
8890
* @param request the Object to be POSTed, may be <code>null</code>
8991
* @return the value for the <code>Location</code> header
9092
*/
91-
URI postForLocation(String uri, Object request, String... uriVariables) throws RestClientException;
93+
URI postForLocation(String url, Object request, String... uriVariables) throws RestClientException;
9294

9395
/**
94-
* Create a new resource by POSTing the given object to URI template. The value of the <code>Location</code> header,
95-
* indicating where the new resource is stored, is returned.
96-
* <p>URI Template variables are expanded using the given map.
97-
* @param uri the URI
98-
* @param request the Object to be POSTed, may be <code>null</code>
96+
* Create a new resource by POSTing the given object to the URI template, and returns the value of the
97+
* <code>Location</code> header. This header typically indicates where the new resource is stored. <p>URI Template
98+
* variables are expanded using the given map.
99+
*
100+
* @param url the URL
101+
* @param request the Object to be POSTed, may be <code>null</code>
99102
* @param uriVariables the variables to expand the template
100103
* @return the value for the <code>Location</code> header
101104
*/
102-
URI postForLocation(String uri, Object request, Map<String, String> uriVariables) throws RestClientException;
105+
URI postForLocation(String url, Object request, Map<String, String> uriVariables) throws RestClientException;
103106

107+
/**
108+
* Create a new resource by POSTing the given object to the URI template, and returns the converted representation
109+
* found in the response. <p>URI Template variables are expanded using the given URI variables, if any.
110+
*
111+
* @param url the URL
112+
* @param request the Object to be POSTed, may be <code>null</code>
113+
* @return the converted object
114+
*/
115+
<T> T postForObject(String url, Object request, Class<T> responseType, String... uriVariables)
116+
throws RestClientException;
117+
118+
/**
119+
* Create a new resource by POSTing the given object to the URI template, and returns the converted representation
120+
* found in the response. <p>URI Template variables are expanded using the given map.
121+
*
122+
* @param url the URL
123+
* @param request the Object to be POSTed, may be <code>null</code>
124+
* @return the converted object
125+
*/
126+
<T> T postForObject(String url, Object request, Class<T> responseType, Map<String, String> uriVariables)
127+
throws RestClientException;
104128

105129
// PUT
106130

107131
/**
108-
* Create or update a resource by PUTting the given object to the URI.
109-
* <p>URI Template variables are expanded using the given URI variables, if any.
110-
* @param uri the URI
111-
* @param request the Object to be PUT, may be <code>null</code>
132+
* Create or update a resource by PUTting the given object to the URI. <p>URI Template variables are expanded using the
133+
* given URI variables, if any.
134+
*
135+
* @param url the URL
136+
* @param request the Object to be PUT, may be <code>null</code>
112137
* @param uriVariables the variables to expand the template
113138
*/
114-
void put(String uri, Object request, String... uriVariables) throws RestClientException;
139+
void put(String url, Object request, String... uriVariables) throws RestClientException;
115140

116141
/**
117-
* Creates a new resource by PUTting the given object to URI template.
118-
* <p>URI Template variables are expanded using the given map.
119-
* @param uri the URI
120-
* @param request the Object to be PUT, may be <code>null</code>
142+
* Creates a new resource by PUTting the given object to URI template. <p>URI Template variables are expanded using the
143+
* given map.
144+
*
145+
* @param url the URL
146+
* @param request the Object to be PUT, may be <code>null</code>
121147
* @param uriVariables the variables to expand the template
122148
*/
123-
void put(String uri, Object request, Map<String, String> uriVariables) throws RestClientException;
124-
149+
void put(String url, Object request, Map<String, String> uriVariables) throws RestClientException;
125150

126151
// DELETE
127152

128153
/**
129-
* Delete the resources at the specified URI.
130-
* <p>URI Template variables are expanded using the given URI variables, if any.
131-
* @param uri the URI
154+
* Delete the resources at the specified URI. <p>URI Template variables are expanded using the given URI variables, if
155+
* any.
156+
*
157+
* @param url the URL
132158
* @param uriVariables the variables to expand in the template
133159
*/
134-
void delete(String uri, String... uriVariables) throws RestClientException;
160+
void delete(String url, String... uriVariables) throws RestClientException;
135161

136162
/**
137-
* Delete the resources at the specified URI.
138-
* <p>URI Template variables are expanded using the given map.
139-
* @param uri the URI
163+
* Delete the resources at the specified URI. <p>URI Template variables are expanded using the given map.
164+
*
165+
* @param url the URL
140166
* @param uriVariables the variables to expand the template
141167
*/
142-
void delete(String uri, Map<String, String> uriVariables) throws RestClientException;
143-
168+
void delete(String url, Map<String, String> uriVariables) throws RestClientException;
144169

145170
// OPTIONS
146171

147172
/**
148-
* Return the value of the Allow header for the given URI.
149-
* <p>URI Template variables are expanded using the given URI variables, if any.
150-
* @param uri the URI
173+
* Return the value of the Allow header for the given URI. <p>URI Template variables are expanded using the given URI
174+
* variables, if any.
175+
*
176+
* @param url the URL
151177
* @param uriVariables the variables to expand in the template
152178
* @return the value of the allow header
153179
*/
154-
Set<HttpMethod> optionsForAllow(String uri, String... uriVariables) throws RestClientException;
180+
Set<HttpMethod> optionsForAllow(String url, String... uriVariables) throws RestClientException;
155181

156182
/**
157-
* Return the value of the Allow header for the given URI.
158-
* <p>URI Template variables are expanded using the given map.
159-
* @param uri the URI
183+
* Return the value of the Allow header for the given URI. <p>URI Template variables are expanded using the given map.
184+
*
185+
* @param url the URL
160186
* @param uriVariables the variables to expand in the template
161187
* @return the value of the allow header
162188
*/
163-
Set<HttpMethod> optionsForAllow(String uri, Map<String, String> uriVariables) throws RestClientException;
164-
189+
Set<HttpMethod> optionsForAllow(String url, Map<String, String> uriVariables) throws RestClientException;
165190

166191
// general execution
167192

168193
/**
169-
* Execute the HTTP methods to the given URI, preparing the request with the {@link RequestCallback},
170-
* and reading the response with a {@link ResponseExtractor}.
171-
* <p>URI Template variables are expanded using the given URI variables, if any.
172-
* @param uri the URI
173-
* @param method the HTTP method (GET, POST, etc)
174-
* @param requestCallback object that prepares the request
194+
* Execute the HTTP methods to the given URI, preparing the request with the {@link RequestCallback}, and reading the
195+
* response with a {@link ResponseExtractor}. <p>URI Template variables are expanded using the given URI variables, if
196+
* any.
197+
*
198+
* @param url the URL
199+
* @param method the HTTP method (GET, POST, etc)
200+
* @param requestCallback object that prepares the request
175201
* @param responseExtractor object that extracts the return value from the response
176-
* @param uriVariables the variables to expand in the template
202+
* @param uriVariables the variables to expand in the template
177203
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
178204
*/
179-
<T> T execute(String uri,
205+
<T> T execute(String url,
180206
HttpMethod method,
181207
RequestCallback requestCallback,
182208
ResponseExtractor<T> responseExtractor,
183209
String... uriVariables) throws RestClientException;
184210

185211
/**
186-
* Execute the HTTP methods to the given URI, preparing the request with the {@link RequestCallback},
187-
* and reading the response with a {@link ResponseExtractor}.
188-
* <p>URI Template variables are expanded using the given URI variables map.
189-
* @param uri the URI
190-
* @param method the HTTP method (GET, POST, etc)
191-
* @param requestCallback object that prepares the request
212+
* Execute the HTTP methods to the given URI, preparing the request with the {@link RequestCallback}, and reading the
213+
* response with a {@link ResponseExtractor}. <p>URI Template variables are expanded using the given URI variables
214+
* map.
215+
*
216+
* @param url the URL
217+
* @param method the HTTP method (GET, POST, etc)
218+
* @param requestCallback object that prepares the request
192219
* @param responseExtractor object that extracts the return value from the response
193-
* @param uriVariables the variables to expand in the template
220+
* @param uriVariables the variables to expand in the template
194221
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
195222
*/
196-
<T> T execute(String uri,
223+
<T> T execute(String url,
197224
HttpMethod method,
198225
RequestCallback requestCallback,
199226
ResponseExtractor<T> responseExtractor,

0 commit comments

Comments
 (0)