public class RequestEntity<T> extends HttpEntity<T>
HttpEntity that adds a method and
uri.
Used in RestTemplate and @Controller methods.
In RestTemplate, this class is used as parameter in
exchange():
MyRequest body = ...
RequestEntity<MyRequest> request = RequestEntity.post("http://example.com/{foo}", "bar").accept(MediaType.APPLICATION_JSON).body(body);
ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
Can also be used in Spring MVC, as a parameter in a @Controller method:
@RequestMapping("/handle")
public void handle(RequestEntity<String> request) {
HttpMethod method = request.getMethod();
URI url = request.getUrl();
String body = request.getBody();
}
getMethod(),
getUrl()| Modifier and Type | Class and Description |
|---|---|
static interface |
RequestEntity.BodyBuilder
Defines a builder that adds a body to the response entity.
|
static interface |
RequestEntity.HeadersBuilder<B extends RequestEntity.HeadersBuilder<B>>
Defines a builder that adds headers to the request entity.
|
EMPTY| Constructor and Description |
|---|
RequestEntity(HttpMethod method,
URI url)
Constructor with method and URL but without body nor headers.
|
RequestEntity(MultiValueMap<String,String> headers,
HttpMethod method,
URI url)
Constructor with method, URL and headers but without body.
|
RequestEntity(T body,
HttpMethod method,
URI url)
Constructor with method, URL and body but without headers.
|
RequestEntity(T body,
MultiValueMap<String,String> headers,
HttpMethod method,
URI url)
Constructor with method, URL, headers and body.
|
| Modifier and Type | Method and Description |
|---|---|
static RequestEntity.HeadersBuilder<?> |
delete(String url,
Map<String,?> uriVariables)
Create an HTTP DELETE builder with the given url and uri variables.
|
static RequestEntity.HeadersBuilder<?> |
delete(String url,
Object... uriVariables)
Create an HTTP DELETE builder with the given url and uri variables.
|
static RequestEntity.HeadersBuilder<?> |
delete(URI url)
Create an HTTP DELETE builder with the given url.
|
boolean |
equals(Object other) |
static RequestEntity.HeadersBuilder<?> |
get(String url,
Map<String,?> uriVariables)
Create an HTTP GET builder with the given url and uri variables.
|
static RequestEntity.HeadersBuilder<?> |
get(String url,
Object... uriVariables)
Create a GET builder with the given url and uri variables.
|
static RequestEntity.HeadersBuilder<?> |
get(URI url)
Create an HTTP GET builder with the given url.
|
HttpMethod |
getMethod()
Return the HTTP method of the request.
|
URI |
getUrl()
Return the URL of the request.
|
int |
hashCode() |
static RequestEntity.HeadersBuilder<?> |
head(String url,
Map<String,?> uriVariables)
Create an HTTP HEAD builder with the given url and uri variables.
|
static RequestEntity.HeadersBuilder<?> |
head(String url,
Object... uriVariables)
Create an HTTP HEAD builder with the given url and uri variables.
|
static RequestEntity.HeadersBuilder<?> |
head(URI url)
Create an HTTP HEAD builder with the given url.
|
static RequestEntity.BodyBuilder |
method(HttpMethod method,
String url,
Map<String,?> uriVariables)
Create a builder with the given method, url, and uri variables.
|
static RequestEntity.BodyBuilder |
method(HttpMethod method,
String url,
Object... uriVariables)
Create a builder with the given method, url, and uri variables.
|
static RequestEntity.BodyBuilder |
method(HttpMethod method,
URI url)
Create a builder with the given method and url.
|
static RequestEntity.HeadersBuilder<?> |
options(String url,
Map<String,?> uriVariables)
Creates an HTTP OPTIONS builder with the given url and uri variables.
|
static RequestEntity.HeadersBuilder<?> |
options(String url,
Object... uriVariables)
Create an HTTP OPTIONS builder with the given url and uri variables.
|
static RequestEntity.HeadersBuilder<?> |
options(URI url)
Creates an HTTP OPTIONS builder with the given url.
|
static RequestEntity.BodyBuilder |
patch(String url,
Map<String,?> uriVariables)
Create an HTTP PATCH builder with the given url and uri variables.
|
static RequestEntity.BodyBuilder |
patch(String url,
Object... uriVariables)
Create an HTTP PATCH builder with the given url and uri variables.
|
static RequestEntity.BodyBuilder |
patch(URI url)
Create an HTTP PATCH builder with the given url.
|
static RequestEntity.BodyBuilder |
post(String url,
Map<String,?> uriVariables)
Create an HTTP POST builder with the given url and uri variables.
|
static RequestEntity.BodyBuilder |
post(String url,
Object... uriVariables)
Create an HTTP POST builder with the given url and uri variables.
|
static RequestEntity.BodyBuilder |
post(URI url)
Create an HTTP POST builder with the given url.
|
static RequestEntity.BodyBuilder |
put(String url,
Map<String,?> uriVariables)
Create an HTTP PUT builder with the given url and uri variables.
|
static RequestEntity.BodyBuilder |
put(String url,
Object... uriVariables)
Create an HTTP PUT builder with the given url and uri variables.
|
static RequestEntity.BodyBuilder |
put(URI url)
Create an HTTP PUT builder with the given url.
|
String |
toString() |
getBody, getHeaders, hasBodypublic RequestEntity(HttpMethod method, URI url)
method - the methodurl - the URLpublic RequestEntity(T body, HttpMethod method, URI url)
body - the bodymethod - the methodurl - the URLpublic RequestEntity(MultiValueMap<String,String> headers, HttpMethod method, URI url)
headers - the headersmethod - the methodurl - the URLpublic RequestEntity(T body, MultiValueMap<String,String> headers, HttpMethod method, URI url)
body - the bodyheaders - the headersmethod - the methodurl - the URLpublic HttpMethod getMethod()
HttpMethod enum valuepublic URI getUrl()
URIpublic boolean equals(Object other)
equals in class HttpEntity<T>public int hashCode()
hashCode in class HttpEntity<T>public String toString()
toString in class HttpEntity<T>public static RequestEntity.BodyBuilder method(HttpMethod method, String url, Object... uriVariables)
URI Template variables are expanded using the given URI variables, if any.
method - the HTTP method (GET, POST, etc)url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.BodyBuilder method(HttpMethod method, String url, Map<String,?> uriVariables)
URI Template variables are expanded using the given URI variables, if any.
method - the HTTP method (GET, POST, etc)url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.BodyBuilder method(HttpMethod method, URI url)
method - the HTTP method (GET, POST, etc)url - the URLpublic static RequestEntity.HeadersBuilder<?> get(String url, Object... uriVariables)
URI Template variables are expanded using the given URI variables, if any.
url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.HeadersBuilder<?> get(String url, Map<String,?> uriVariables)
URI Template variables are expanded using the given URI variables, if any.
url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.HeadersBuilder<?> get(URI url)
URI Template variables are expanded using the given URI variables, if any.
url - the URLpublic static RequestEntity.HeadersBuilder<?> head(String url, Object... uriVariables)
URI Template variables are expanded using the given URI variables, if any.
url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.HeadersBuilder<?> head(String url, Map<String,?> uriVariables)
URI Template variables are expanded using the given URI variables, if any.
url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.HeadersBuilder<?> head(URI url)
url - the URLpublic static RequestEntity.BodyBuilder post(String url, Object... uriVariables)
URI Template variables are expanded using the given URI variables, if any.
url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.BodyBuilder post(String url, Map<String,?> uriVariables)
URI Template variables are expanded using the given URI variables, if any.
url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.BodyBuilder post(URI url)
url - the URLpublic static RequestEntity.BodyBuilder put(String url, Object... uriVariables)
URI Template variables are expanded using the given URI variables, if any.
url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.BodyBuilder put(String url, Map<String,?> uriVariables)
URI Template variables are expanded using the given URI variables, if any.
url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.BodyBuilder put(URI url)
url - the URLpublic static RequestEntity.BodyBuilder patch(String url, Object... uriVariables)
URI Template variables are expanded using the given URI variables, if any.
url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.BodyBuilder patch(String url, Map<String,?> uriVariables)
URI Template variables are expanded using the given URI variables, if any.
url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.BodyBuilder patch(URI url)
url - the URLpublic static RequestEntity.HeadersBuilder<?> delete(String url, Object... uriVariables)
URI Template variables are expanded using the given URI variables, if any.
url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.HeadersBuilder<?> delete(String url, Map<String,?> uriVariables)
URI Template variables are expanded using the given URI variables, if any.
url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.HeadersBuilder<?> delete(URI url)
url - the URLpublic static RequestEntity.HeadersBuilder<?> options(String url, Object... uriVariables)
URI Template variables are expanded using the given URI variables, if any.
url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.HeadersBuilder<?> options(String url, Map<String,?> uriVariables)
URI Template variables are expanded using the given URI variables, if any.
url - the URLuriVariables - the variables to expand in the templatepublic static RequestEntity.HeadersBuilder<?> options(URI url)
url - the URL