Skip to content

Commit 0ea5b5e

Browse files
committed
opened up RestTemplate method signatures to Map<String, ?> and Object array instead of enforcing String values
1 parent ad3fa50 commit 0ea5b5e

File tree

3 files changed

+121
-150
lines changed

3 files changed

+121
-150
lines changed

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

Lines changed: 66 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,44 @@
2424
import org.springframework.http.HttpMethod;
2525

2626
/**
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.
27+
* Interface specifying a basic set of RESTful operations. Implemented by {@link RestTemplate}.
28+
* Not often used directly, but a useful option to enhance testability, as it can easily
29+
* be mocked or stubbed.
2930
*
3031
* @author Arjen Poutsma
31-
* @see RestTemplate
32+
* @author Juergen Hoeller
3233
* @since 3.0
34+
* @see RestTemplate
3335
*/
3436
public interface RestOperations {
3537

3638
// GET
3739

3840
/**
39-
* Retrieve a representation by doing a GET on the specified URL. The response (if any) is converted and returned.
41+
* Retrieve a representation by doing a GET on the specified URL.
42+
* The response (if any) is converted and returned.
4043
* <p>URI Template variables are expanded using the given URI variables, if any.
41-
*
4244
* @param url the URL
4345
* @param responseType the type of the return value
4446
* @param uriVariables the variables to expand the template
4547
* @return the converted object
4648
*/
47-
<T> T getForObject(String url, Class<T> responseType, String... uriVariables) throws RestClientException;
49+
<T> T getForObject(String url, Class<T> responseType, Object... uriVariables) throws RestClientException;
4850

4951
/**
50-
* Retrieve a representation by doing a GET on the URI template. The response (if any) is converted and returned.
52+
* Retrieve a representation by doing a GET on the URI template.
53+
* The response (if any) is converted and returned.
5154
* <p>URI Template variables are expanded using the given map.
52-
*
5355
* @param url the URL
5456
* @param responseType the type of the return value
5557
* @param uriVariables the map containing variables for the URI template
5658
* @return the converted object
5759
*/
58-
<T> T getForObject(String url, Class<T> responseType, Map<String, String> uriVariables) throws RestClientException;
60+
<T> T getForObject(String url, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException;
5961

6062
/**
61-
* Retrieve a representation by doing a GET on the URL . The response (if any) is converted and returned.
62-
*
63+
* Retrieve a representation by doing a GET on the URL .
64+
* The response (if any) is converted and returned.
6365
* @param url the URL
6466
* @param responseType the type of the return value
6567
* @return the converted object
@@ -69,28 +71,25 @@ public interface RestOperations {
6971
// HEAD
7072

7173
/**
72-
* Retrieve all headers of the resource specified by the URI template. <p>URI Template variables are expanded using the
73-
* given URI variables, if any.
74-
*
74+
* Retrieve all headers of the resource specified by the URI template.
75+
* <p>URI Template variables are expanded using the given URI variables, if any.
7576
* @param url the URL
7677
* @param uriVariables the variables to expand the template
7778
* @return all HTTP headers of that resource
7879
*/
79-
HttpHeaders headForHeaders(String url, String... uriVariables) throws RestClientException;
80+
HttpHeaders headForHeaders(String url, Object... uriVariables) throws RestClientException;
8081

8182
/**
82-
* Retrieve all headers of the resource specified by the URI template. <p>URI Template variables are expanded using the
83-
* given map.
84-
*
83+
* Retrieve all headers of the resource specified by the URI template.
84+
* <p>URI Template variables are expanded using the given map.
8585
* @param url the URL
8686
* @param uriVariables the map containing variables for the URI template
8787
* @return all HTTP headers of that resource
8888
*/
89-
HttpHeaders headForHeaders(String url, Map<String, String> uriVariables) throws RestClientException;
89+
HttpHeaders headForHeaders(String url, Map<String, ?> uriVariables) throws RestClientException;
9090

9191
/**
9292
* Retrieve all headers of the resource specified by the URL.
93-
*
9493
* @param url the URL
9594
* @return all HTTP headers of that resource
9695
*/
@@ -100,66 +99,62 @@ public interface RestOperations {
10099

101100
/**
102101
* Create a new resource by POSTing the given object to the URI template, and returns the value of the
103-
* <code>Location</code> header. This header typically indicates where the new resource is stored. <p>URI Template
104-
* variables are expanded using the given URI variables, if any.
105-
*
102+
* <code>Location</code> header. This header typically indicates where the new resource is stored.
103+
* <p>URI Template variables are expanded using the given URI variables, if any.
106104
* @param url the URL
107105
* @param request the Object to be POSTed, may be <code>null</code>
108106
* @param uriVariables the variables to expand the template
109107
* @return the value for the <code>Location</code> header
110108
*/
111-
URI postForLocation(String url, Object request, String... uriVariables) throws RestClientException;
109+
URI postForLocation(String url, Object request, Object... uriVariables) throws RestClientException;
112110

113111
/**
114112
* Create a new resource by POSTing the given object to the URI template, and returns the value of the
115-
* <code>Location</code> header. This header typically indicates where the new resource is stored. <p>URI Template
116-
* variables are expanded using the given map.
117-
*
113+
* <code>Location</code> header. This header typically indicates where the new resource is stored.
114+
* <p>URI Template variables are expanded using the given map.
118115
* @param url the URL
119116
* @param request the Object to be POSTed, may be <code>null</code>
120117
* @param uriVariables the variables to expand the template
121118
* @return the value for the <code>Location</code> header
122119
*/
123-
URI postForLocation(String url, Object request, Map<String, String> uriVariables) throws RestClientException;
120+
URI postForLocation(String url, Object request, Map<String, ?> uriVariables) throws RestClientException;
124121

125122
/**
126123
* Create a new resource by POSTing the given object to the URL, and returns the value of the
127124
* <code>Location</code> header. This header typically indicates where the new resource is stored.
128-
*
129125
* @param url the URL
130126
* @param request the Object to be POSTed, may be <code>null</code>
131127
* @return the value for the <code>Location</code> header
132128
*/
133129
URI postForLocation(URI url, Object request) throws RestClientException;
134130

135131
/**
136-
* Create a new resource by POSTing the given object to the URI template, and returns the representation
137-
* found in the response. <p>URI Template variables are expanded using the given URI variables, if any.
138-
*
132+
* Create a new resource by POSTing the given object to the URI template,
133+
* and returns the representation found in the response.
134+
* <p>URI Template variables are expanded using the given URI variables, if any.
139135
* @param url the URL
140136
* @param request the Object to be POSTed, may be <code>null</code>
141137
* @param uriVariables the variables to expand the template
142138
* @return the converted object
143139
*/
144-
<T> T postForObject(String url, Object request, Class<T> responseType, String... uriVariables)
140+
<T> T postForObject(String url, Object request, Class<T> responseType, Object... uriVariables)
145141
throws RestClientException;
146142

147143
/**
148-
* Create a new resource by POSTing the given object to the URI template, and returns the representation
149-
* found in the response. <p>URI Template variables are expanded using the given map.
150-
*
144+
* Create a new resource by POSTing the given object to the URI template,
145+
* and returns the representation found in the response.
146+
* <p>URI Template variables are expanded using the given map.
151147
* @param url the URL
152148
* @param request the Object to be POSTed, may be <code>null</code>
153149
* @param uriVariables the variables to expand the template
154150
* @return the converted object
155151
*/
156-
<T> T postForObject(String url, Object request, Class<T> responseType, Map<String, String> uriVariables)
152+
<T> T postForObject(String url, Object request, Class<T> responseType, Map<String, ?> uriVariables)
157153
throws RestClientException;
158154

159155
/**
160-
* Create a new resource by POSTing the given object to the URL, and returns the representation
161-
* found in the response.
162-
*
156+
* Create a new resource by POSTing the given object to the URL,
157+
* and returns the representation found in the response.
163158
* @param url the URL
164159
* @param request the Object to be POSTed, may be <code>null</code>
165160
* @return the converted object
@@ -169,28 +164,25 @@ <T> T postForObject(String url, Object request, Class<T> responseType, Map<Strin
169164
// PUT
170165

171166
/**
172-
* Create or update a resource by PUTting the given object to the URI. <p>URI Template variables are expanded using the
173-
* given URI variables, if any.
174-
*
167+
* Create or update a resource by PUTting the given object to the URI.
168+
* <p>URI Template variables are expanded using the given URI variables, if any.
175169
* @param url the URL
176170
* @param request the Object to be PUT, may be <code>null</code>
177171
* @param uriVariables the variables to expand the template
178172
*/
179-
void put(String url, Object request, String... uriVariables) throws RestClientException;
173+
void put(String url, Object request, Object... uriVariables) throws RestClientException;
180174

181175
/**
182-
* Creates a new resource by PUTting the given object to URI template. <p>URI Template variables are expanded using the
183-
* given map.
184-
*
176+
* Creates a new resource by PUTting the given object to URI template.
177+
* <p>URI Template variables are expanded using the given map.
185178
* @param url the URL
186179
* @param request the Object to be PUT, may be <code>null</code>
187180
* @param uriVariables the variables to expand the template
188181
*/
189-
void put(String url, Object request, Map<String, String> uriVariables) throws RestClientException;
182+
void put(String url, Object request, Map<String, ?> uriVariables) throws RestClientException;
190183

191184
/**
192185
* Creates a new resource by PUTting the given object to URL.
193-
*
194186
* @param url the URL
195187
* @param request the Object to be PUT, may be <code>null</code>
196188
*/
@@ -199,53 +191,50 @@ <T> T postForObject(String url, Object request, Class<T> responseType, Map<Strin
199191
// DELETE
200192

201193
/**
202-
* Delete the resources at the specified URI. <p>URI Template variables are expanded using the given URI variables, if
203-
* any.
204-
*
194+
* Delete the resources at the specified URI.
195+
* <p>URI Template variables are expanded using the given URI variables, if any.
205196
* @param url the URL
206197
* @param uriVariables the variables to expand in the template
207198
*/
208-
void delete(String url, String... uriVariables) throws RestClientException;
199+
void delete(String url, Object... uriVariables) throws RestClientException;
209200

210201
/**
211-
* Delete the resources at the specified URI. <p>URI Template variables are expanded using the given map.
202+
* Delete the resources at the specified URI.
203+
* <p>URI Template variables are expanded using the given map.
212204
*
213205
* @param url the URL
214206
* @param uriVariables the variables to expand the template
215207
*/
216-
void delete(String url, Map<String, String> uriVariables) throws RestClientException;
208+
void delete(String url, Map<String, ?> uriVariables) throws RestClientException;
217209

218210
/**
219211
* Delete the resources at the specified URL.
220-
*
221212
* @param url the URL
222213
*/
223214
void delete(URI url) throws RestClientException;
224215

225216
// OPTIONS
226217

227218
/**
228-
* Return the value of the Allow header for the given URI. <p>URI Template variables are expanded using the given URI
229-
* variables, if any.
230-
*
219+
* Return the value of the Allow header for the given URI.
220+
* <p>URI Template variables are expanded using the given URI variables, if any.
231221
* @param url the URL
232222
* @param uriVariables the variables to expand in the template
233223
* @return the value of the allow header
234224
*/
235-
Set<HttpMethod> optionsForAllow(String url, String... uriVariables) throws RestClientException;
225+
Set<HttpMethod> optionsForAllow(String url, Object... uriVariables) throws RestClientException;
236226

237227
/**
238-
* Return the value of the Allow header for the given URI. <p>URI Template variables are expanded using the given map.
239-
*
228+
* Return the value of the Allow header for the given URI.
229+
* <p>URI Template variables are expanded using the given map.
240230
* @param url the URL
241231
* @param uriVariables the variables to expand in the template
242232
* @return the value of the allow header
243233
*/
244-
Set<HttpMethod> optionsForAllow(String url, Map<String, String> uriVariables) throws RestClientException;
234+
Set<HttpMethod> optionsForAllow(String url, Map<String, ?> uriVariables) throws RestClientException;
245235

246236
/**
247237
* Return the value of the Allow header for the given URL.
248-
*
249238
* @param url the URL
250239
* @return the value of the allow header
251240
*/
@@ -254,54 +243,43 @@ <T> T postForObject(String url, Object request, Class<T> responseType, Map<Strin
254243
// general execution
255244

256245
/**
257-
* Execute the HTTP methods to the given URI template, preparing the request with the {@link RequestCallback}, and reading the
258-
* response with a {@link ResponseExtractor}. <p>URI Template variables are expanded using the given URI variables, if
259-
* any.
260-
*
246+
* Execute the HTTP methods to the given URI template, preparing the request with the
247+
* {@link RequestCallback}, and reading the response with a{@link ResponseExtractor}.
248+
* <p>URI Template variables are expanded using the given URI variables, if any.
261249
* @param url the URL
262250
* @param method the HTTP method (GET, POST, etc)
263251
* @param requestCallback object that prepares the request
264252
* @param responseExtractor object that extracts the return value from the response
265253
* @param uriVariables the variables to expand in the template
266254
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
267255
*/
268-
<T> T execute(String url,
269-
HttpMethod method,
270-
RequestCallback requestCallback,
271-
ResponseExtractor<T> responseExtractor,
272-
String... uriVariables) throws RestClientException;
256+
<T> T execute(String url, HttpMethod method, RequestCallback requestCallback,
257+
ResponseExtractor<T> responseExtractor, Object... uriVariables) throws RestClientException;
273258

274259
/**
275-
* Execute the HTTP methods to the given URI template, preparing the request with the {@link RequestCallback}, and reading the
276-
* response with a {@link ResponseExtractor}. <p>URI Template variables are expanded using the given URI variables
277-
* map.
278-
*
260+
* Execute the HTTP methods to the given URI template, preparing the request with the
261+
* {@link RequestCallback}, and reading the response with a {@link ResponseExtractor}.
262+
* <p>URI Template variables are expanded using the given URI variables map.
279263
* @param url the URL
280264
* @param method the HTTP method (GET, POST, etc)
281265
* @param requestCallback object that prepares the request
282266
* @param responseExtractor object that extracts the return value from the response
283267
* @param uriVariables the variables to expand in the template
284268
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
285269
*/
286-
<T> T execute(String url,
287-
HttpMethod method,
288-
RequestCallback requestCallback,
289-
ResponseExtractor<T> responseExtractor,
290-
Map<String, String> uriVariables) throws RestClientException;
270+
<T> T execute(String url, HttpMethod method, RequestCallback requestCallback,
271+
ResponseExtractor<T> responseExtractor, Map<String, ?> uriVariables) throws RestClientException;
291272

292273
/**
293-
* Execute the HTTP methods to the given URL, preparing the request with the {@link RequestCallback}, and reading the
294-
* response with a {@link ResponseExtractor}.
295-
*
274+
* Execute the HTTP methods to the given URL, preparing the request with the
275+
* {@link RequestCallback}, and reading the response with a {@link ResponseExtractor}.
296276
* @param url the URL
297277
* @param method the HTTP method (GET, POST, etc)
298278
* @param requestCallback object that prepares the request
299279
* @param responseExtractor object that extracts the return value from the response
300280
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
301281
*/
302-
<T> T execute(URI url,
303-
HttpMethod method,
304-
RequestCallback requestCallback,
282+
<T> T execute(URI url, HttpMethod method, RequestCallback requestCallback,
305283
ResponseExtractor<T> responseExtractor) throws RestClientException;
306284

307285
}

0 commit comments

Comments
 (0)