19
19
import java .net .URI ;
20
20
import java .nio .charset .Charset ;
21
21
import java .util .Arrays ;
22
- import java .util .Map ;
23
22
24
23
import org .springframework .util .Assert ;
25
24
import org .springframework .util .MultiValueMap ;
26
25
import org .springframework .util .ObjectUtils ;
27
- import org .springframework .web .util .UriTemplate ;
28
26
29
27
/**
30
28
* Extension of {@link HttpEntity} that adds a {@linkplain HttpMethod method} and
35
33
* {@link org.springframework.web.client.RestTemplate#exchange(RequestEntity, Class) exchange()}:
36
34
* <pre class="code">
37
35
* MyRequest body = ...
38
- * RequestEntity<MyRequest> request = RequestEntity.post("http://example.com/{foo}", " bar").accept(MediaType.APPLICATION_JSON).body(body);
36
+ * RequestEntity<MyRequest> request = RequestEntity.post(new URI( "http://example.com/bar").accept(MediaType.APPLICATION_JSON).body(body);
39
37
* ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
40
38
* </pre>
41
39
*
40
+ * <p>If you would like to provide a URI template with variables, consider using
41
+ * {@link org.springframework.web.util.UriTemplate}:
42
+ * <pre class="code">
43
+ * URI uri = new UriTemplate("http://example.com/{foo}"").expand("bar");
44
+ * RequestEntity<MyRequest> request = RequestEntity.post(uri).accept(MediaType.APPLICATION_JSON).body(body);
45
+ * </pre>
46
+ *
42
47
* <p>Can also be used in Spring MVC, as a parameter in a @Controller method:
43
48
* <pre class="code">
44
49
* @RequestMapping("/handle")
@@ -169,32 +174,6 @@ public String toString() {
169
174
170
175
// Static builder methods
171
176
172
- /**
173
- * Create a builder with the given method, url, and uri variables.
174
- * <p>URI Template variables are expanded using the given URI variables, if any.
175
- * @param method the HTTP method (GET, POST, etc)
176
- * @param url the URL
177
- * @param uriVariables the variables to expand in the template
178
- * @return the created builder
179
- */
180
- public static BodyBuilder method (HttpMethod method , String url , Object ... uriVariables ) {
181
- URI expanded = new UriTemplate (url ).expand (uriVariables );
182
- return new DefaultBodyBuilder (method , expanded );
183
- }
184
-
185
- /**
186
- * Create a builder with the given method, url, and uri variables.
187
- * <p>URI Template variables are expanded using the given URI variables, if any.
188
- * @param method the HTTP method (GET, POST, etc)
189
- * @param url the URL
190
- * @param uriVariables the variables to expand in the template
191
- * @return the created builder
192
- */
193
- public static BodyBuilder method (HttpMethod method , String url , Map <String , ?> uriVariables ) {
194
- URI expanded = new UriTemplate (url ).expand (uriVariables );
195
- return new DefaultBodyBuilder (method , expanded );
196
- }
197
-
198
177
/**
199
178
* Create a builder with the given method and url.
200
179
* @param method the HTTP method (GET, POST, etc)
@@ -205,60 +184,15 @@ public static BodyBuilder method(HttpMethod method, URI url) {
205
184
return new DefaultBodyBuilder (method , url );
206
185
}
207
186
208
- /**
209
- * Create a GET builder with the given url and uri variables.
210
- * <p>URI Template variables are expanded using the given URI variables, if any.
211
- * @param url the URL
212
- * @param uriVariables the variables to expand in the template
213
- * @return the created builder
214
- */
215
- public static HeadersBuilder <?> get (String url , Object ... uriVariables ) {
216
- return method (HttpMethod .GET , url , uriVariables );
217
- }
218
-
219
- /**
220
- * Create an HTTP GET builder with the given url and uri variables.
221
- * <p>URI Template variables are expanded using the given URI variables, if any.
222
- * @param url the URL
223
- * @param uriVariables the variables to expand in the template
224
- * @return the created builder
225
- */
226
- public static HeadersBuilder <?> get (String url , Map <String , ?> uriVariables ) {
227
- return method (HttpMethod .GET , url , uriVariables );
228
- }
229
-
230
187
/**
231
188
* Create an HTTP GET builder with the given url.
232
- * <p>URI Template variables are expanded using the given URI variables, if any.
233
189
* @param url the URL
234
190
* @return the created builder
235
191
*/
236
192
public static HeadersBuilder <?> get (URI url ) {
237
193
return method (HttpMethod .GET , url );
238
194
}
239
195
240
- /**
241
- * Create an HTTP HEAD builder with the given url and uri variables.
242
- * <p>URI Template variables are expanded using the given URI variables, if any.
243
- * @param url the URL
244
- * @param uriVariables the variables to expand in the template
245
- * @return the created builder
246
- */
247
- public static HeadersBuilder <?> head (String url , Object ... uriVariables ) {
248
- return method (HttpMethod .HEAD , url , uriVariables );
249
- }
250
-
251
- /**
252
- * Create an HTTP HEAD builder with the given url and uri variables.
253
- * <p>URI Template variables are expanded using the given URI variables, if any.
254
- * @param url the URL
255
- * @param uriVariables the variables to expand in the template
256
- * @return the created builder
257
- */
258
- public static HeadersBuilder <?> head (String url , Map <String , ?> uriVariables ) {
259
- return method (HttpMethod .HEAD , url , uriVariables );
260
- }
261
-
262
196
/**
263
197
* Create an HTTP HEAD builder with the given url.
264
198
* @param url the URL
@@ -268,28 +202,6 @@ public static HeadersBuilder<?> head(URI url) {
268
202
return method (HttpMethod .HEAD , url );
269
203
}
270
204
271
- /**
272
- * Create an HTTP POST builder with the given url and uri variables.
273
- * <p>URI Template variables are expanded using the given URI variables, if any.
274
- * @param url the URL
275
- * @param uriVariables the variables to expand in the template
276
- * @return the created builder
277
- */
278
- public static BodyBuilder post (String url , Object ... uriVariables ) {
279
- return method (HttpMethod .POST , url , uriVariables );
280
- }
281
-
282
- /**
283
- * Create an HTTP POST builder with the given url and uri variables.
284
- * <p>URI Template variables are expanded using the given URI variables, if any.
285
- * @param url the URL
286
- * @param uriVariables the variables to expand in the template
287
- * @return the created builder
288
- */
289
- public static BodyBuilder post (String url , Map <String , ?> uriVariables ) {
290
- return method (HttpMethod .POST , url , uriVariables );
291
- }
292
-
293
205
/**
294
206
* Create an HTTP POST builder with the given url.
295
207
* @param url the URL
@@ -299,28 +211,6 @@ public static BodyBuilder post(URI url) {
299
211
return method (HttpMethod .POST , url );
300
212
}
301
213
302
- /**
303
- * Create an HTTP PUT builder with the given url and uri variables.
304
- * <p>URI Template variables are expanded using the given URI variables, if any.
305
- * @param url the URL
306
- * @param uriVariables the variables to expand in the template
307
- * @return the created builder
308
- */
309
- public static BodyBuilder put (String url , Object ... uriVariables ) {
310
- return method (HttpMethod .PUT , url , uriVariables );
311
- }
312
-
313
- /**
314
- * Create an HTTP PUT builder with the given url and uri variables.
315
- * <p>URI Template variables are expanded using the given URI variables, if any.
316
- * @param url the URL
317
- * @param uriVariables the variables to expand in the template
318
- * @return the created builder
319
- */
320
- public static BodyBuilder put (String url , Map <String , ?> uriVariables ) {
321
- return method (HttpMethod .PUT , url , uriVariables );
322
- }
323
-
324
214
/**
325
215
* Create an HTTP PUT builder with the given url.
326
216
* @param url the URL
@@ -330,28 +220,6 @@ public static BodyBuilder put(URI url) {
330
220
return method (HttpMethod .PUT , url );
331
221
}
332
222
333
- /**
334
- * Create an HTTP PATCH builder with the given url and uri variables.
335
- * <p>URI Template variables are expanded using the given URI variables, if any.
336
- * @param url the URL
337
- * @param uriVariables the variables to expand in the template
338
- * @return the created builder
339
- */
340
- public static BodyBuilder patch (String url , Object ... uriVariables ) {
341
- return method (HttpMethod .PATCH , url , uriVariables );
342
- }
343
-
344
- /**
345
- * Create an HTTP PATCH builder with the given url and uri variables.
346
- * <p>URI Template variables are expanded using the given URI variables, if any.
347
- * @param url the URL
348
- * @param uriVariables the variables to expand in the template
349
- * @return the created builder
350
- */
351
- public static BodyBuilder patch (String url , Map <String , ?> uriVariables ) {
352
- return method (HttpMethod .PATCH , url , uriVariables );
353
- }
354
-
355
223
/**
356
224
* Create an HTTP PATCH builder with the given url.
357
225
* @param url the URL
@@ -361,28 +229,6 @@ public static BodyBuilder patch(URI url) {
361
229
return method (HttpMethod .PATCH , url );
362
230
}
363
231
364
- /**
365
- * Create an HTTP DELETE builder with the given url and uri variables.
366
- * <p>URI Template variables are expanded using the given URI variables, if any.
367
- * @param url the URL
368
- * @param uriVariables the variables to expand in the template
369
- * @return the created builder
370
- */
371
- public static HeadersBuilder <?> delete (String url , Object ... uriVariables ) {
372
- return method (HttpMethod .DELETE , url , uriVariables );
373
- }
374
-
375
- /**
376
- * Create an HTTP DELETE builder with the given url and uri variables.
377
- * <p>URI Template variables are expanded using the given URI variables, if any.
378
- * @param url the URL
379
- * @param uriVariables the variables to expand in the template
380
- * @return the created builder
381
- */
382
- public static HeadersBuilder <?> delete (String url , Map <String , ?> uriVariables ) {
383
- return method (HttpMethod .DELETE , url , uriVariables );
384
- }
385
-
386
232
/**
387
233
* Create an HTTP DELETE builder with the given url.
388
234
* @param url the URL
@@ -392,28 +238,6 @@ public static HeadersBuilder<?> delete(URI url) {
392
238
return method (HttpMethod .DELETE , url );
393
239
}
394
240
395
- /**
396
- * Create an HTTP OPTIONS builder with the given url and uri variables.
397
- * <p>URI Template variables are expanded using the given URI variables, if any.
398
- * @param url the URL
399
- * @param uriVariables the variables to expand in the template
400
- * @return the created builder
401
- */
402
- public static HeadersBuilder <?> options (String url , Object ... uriVariables ) {
403
- return method (HttpMethod .OPTIONS , url , uriVariables );
404
- }
405
-
406
- /**
407
- * Creates an HTTP OPTIONS builder with the given url and uri variables.
408
- * <p>URI Template variables are expanded using the given URI variables, if any.
409
- * @param url the URL
410
- * @param uriVariables the variables to expand in the template
411
- * @return the created builder
412
- */
413
- public static HeadersBuilder <?> options (String url , Map <String , ?> uriVariables ) {
414
- return method (HttpMethod .OPTIONS , url , uriVariables );
415
- }
416
-
417
241
/**
418
242
* Creates an HTTP OPTIONS builder with the given url.
419
243
* @param url the URL
0 commit comments