T - ボディ型 public class RequestEntity<T> extends HttpEntity<T>
HttpEntity の拡張。RestTemplate および @Controller メソッドで使用されます。RestTemplate では、このクラスは exchange() のパラメーターとして使用されます。
MyRequest body = ...
RequestEntity<MyRequest> request = RequestEntity
.post(new URI("http://example.com/bar"))
.accept(MediaType.APPLICATION_JSON)
.body(body);
ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
URI テンプレートに変数を提供する場合は、UriTemplate の使用を検討してください。
URI uri = new UriTemplate("http://example.com/{foo}").expand("bar");
RequestEntity<MyRequest> request = RequestEntity.post(uri).accept(MediaType.APPLICATION_JSON).body(body);
@Controller メソッドのパラメーターとして、Spring MVC でも使用できます。
@RequestMapping("/handle")
public void handle(RequestEntity<String> request) {
HttpMethod method = request.getMethod();
URI url = request.getUrl();
String body = request.getBody();
}
getMethod(), getUrl()| 修飾子と型 | クラスと説明 |
|---|---|
static interface | RequestEntity.BodyBuilder レスポンスエンティティに本文を追加するビルダーを定義します。 |
static interface | RequestEntity.HeadersBuilder<B extends RequestEntity.HeadersBuilder<B>> リクエストエンティティにヘッダーを追加するビルダーを定義します。 |
EMPTY| コンストラクターと説明 |
|---|
RequestEntity(HttpMethod method, java.net.URI url) メソッドと URL はあるが、本文もヘッダーもないコンストラクター。 |
RequestEntity(MultiValueMap<java.lang.String,java.lang.String> headers, HttpMethod method, java.net.URI url) メソッド、URL、ヘッダーはあるが本文はないコンストラクター。 |
RequestEntity(T body, HttpMethod method, java.net.URI url) メソッド、URL、ボディはあるがヘッダーはないコンストラクター。 |
RequestEntity(T body, HttpMethod method, java.net.URI url, java.lang.reflect.Type type) メソッド、URL、ボディ、型はあるがヘッダーはないコンストラクター。 |
RequestEntity(T body, MultiValueMap<java.lang.String,java.lang.String> headers, HttpMethod method, java.net.URI url) メソッド、URL、ヘッダー、本文を含むコンストラクター。 |
RequestEntity(T body, MultiValueMap<java.lang.String,java.lang.String> headers, HttpMethod method, java.net.URI url, java.lang.reflect.Type type) メソッド、URL、ヘッダー、ボディ、型を持つコンストラクター。 |
| 修飾子と型 | メソッドと説明 |
|---|---|
static RequestEntity.HeadersBuilder<?> | delete(java.net.URI url) 指定された URL で HTTP DELETE ビルダーを作成します。 |
boolean | equals(java.lang.Object other) |
static RequestEntity.HeadersBuilder<?> | get(java.net.URI url) 指定された URL で HTTP GET ビルダーを作成します。 |
HttpMethod | getMethod() リクエストの HTTP メソッドを返します。 |
java.lang.reflect.Type | getType() リクエストのボディの型を返します。 |
java.net.URI | getUrl() リクエストの URL を返します。 |
int | hashCode() |
static RequestEntity.HeadersBuilder<?> | head(java.net.URI url) 指定された URL で HTTP HEAD ビルダーを作成します。 |
static RequestEntity.BodyBuilder | method(HttpMethod method, java.net.URI url) 指定されたメソッドと URL でビルダーを作成します。 |
static RequestEntity.HeadersBuilder<?> | options(java.net.URI url) 指定された URL で HTTP OPTIONS ビルダーを作成します。 |
static RequestEntity.BodyBuilder | patch(java.net.URI url) 指定された URL で HTTP PATCH ビルダーを作成します。 |
static RequestEntity.BodyBuilder | post(java.net.URI url) 指定された URL で HTTP POST ビルダーを作成します。 |
static RequestEntity.BodyBuilder | put(java.net.URI url) 指定された URL で HTTP PUT ビルダーを作成します。 |
java.lang.String | toString() |
getBody, getHeaders, hasBodypublic RequestEntity(HttpMethod method, java.net.URI url)
method - メソッド url - URLpublic RequestEntity(@Nullable T body, HttpMethod method, java.net.URI url)
body - 体 method - メソッド url - URLpublic RequestEntity(@Nullable T body, HttpMethod method, java.net.URI url, java.lang.reflect.Type type)
body - 体 method - メソッド url - URLtype - ジェネリクス型解決に使用される型 public RequestEntity(MultiValueMap<java.lang.String,java.lang.String> headers, HttpMethod method, java.net.URI url)
headers - ヘッダー method - メソッド url - URLpublic RequestEntity(@Nullable T body, @Nullable MultiValueMap<java.lang.String,java.lang.String> headers, @Nullable HttpMethod method, java.net.URI url)
body - 体 headers - ヘッダー method - メソッド url - URLpublic RequestEntity(@Nullable T body, @Nullable MultiValueMap<java.lang.String,java.lang.String> headers, @Nullable HttpMethod method, java.net.URI url, @Nullable java.lang.reflect.Type type)
body - 体 headers - ヘッダー method - メソッド url - URLtype - ジェネリクス型解決に使用される型 @Nullable public HttpMethod getMethod()
HttpMethod 列挙値としての HTTP メソッド public java.net.URI getUrl()
URI としての URL @Nullable public java.lang.reflect.Type getType()
null public boolean equals(@Nullable java.lang.Object other)
HttpEntity<T> の equals public int hashCode()
HttpEntity<T> の hashCode public java.lang.String toString()
HttpEntity<T> の toString public static RequestEntity.BodyBuilder method(HttpMethod method, java.net.URI url)
method - HTTP メソッド (GET、POST など)url - URLpublic static RequestEntity.HeadersBuilder<?> get(java.net.URI url)
url - URLpublic static RequestEntity.HeadersBuilder<?> head(java.net.URI url)
url - URLpublic static RequestEntity.BodyBuilder post(java.net.URI url)
url - URLpublic static RequestEntity.BodyBuilder put(java.net.URI url)
url - URLpublic static RequestEntity.BodyBuilder patch(java.net.URI url)
url - URLpublic static RequestEntity.HeadersBuilder<?> delete(java.net.URI url)
url - URLpublic static RequestEntity.HeadersBuilder<?> options(java.net.URI url)
url - URL