T - ボディ型 public class RequestEntity<T> extends HttpEntity<T>
HttpEntity の拡張。RestTemplate および @Controller メソッドで使用されます。RestTemplate では、このクラスは exchange() のパラメーターとして使用されます。
MyRequest body = ...
RequestEntity<MyRequest> request = RequestEntity
.post(new URI("https://example.com/bar"))
.accept(MediaType.APPLICATION_JSON)
.body(body);
ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
URI テンプレートに変数を提供する場合は、DefaultUriBuilderFactory の使用を検討してください。
// Create shared factory
UriBuilderFactory factory = new DefaultUriBuilderFactory();
// Use factory to create URL from template
URI uri = factory.uriString("https://example.com/{foo}").build("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, URISE url) メソッドと URL はあるが、本文もヘッダーもないコンストラクター。 |
RequestEntity(MultiValueMap<StringSE, StringSE> headers, HttpMethod method, URISE url) メソッド、URL、ヘッダーはあるが本文はないコンストラクター。 |
RequestEntity(T body, HttpMethod method, URISE url) メソッド、URL、ボディはあるがヘッダーはないコンストラクター。 |
RequestEntity(T body, HttpMethod method, URISE url, TypeSE type) メソッド、URL、ボディ、型はあるがヘッダーはないコンストラクター。 |
RequestEntity(T body, MultiValueMap<StringSE, StringSE> headers, HttpMethod method, URISE url) メソッド、URL、ヘッダー、本文を含むコンストラクター。 |
RequestEntity(T body, MultiValueMap<StringSE, StringSE> headers, HttpMethod method, URISE url, TypeSE type) メソッド、URL、ヘッダー、ボディ、型を持つコンストラクター。 |
| 修飾子と型 | メソッドと説明 |
|---|---|
static RequestEntity.HeadersBuilder<?> | delete(URISE url) 指定された URL で HTTP DELETE ビルダーを作成します。 |
boolean | equals(ObjectSE other) |
static RequestEntity.HeadersBuilder<?> | get(URISE url) 指定された URL で HTTP GET ビルダーを作成します。 |
HttpMethod | getMethod() リクエストの HTTP メソッドを返します。 |
TypeSE | getType() リクエストのボディの型を返します。 |
URISE | getUrl() リクエストの URL を返します。 |
int | hashCode() |
static RequestEntity.HeadersBuilder<?> | head(URISE url) 指定された URL で HTTP HEAD ビルダーを作成します。 |
static RequestEntity.BodyBuilder | method(HttpMethod method, URISE url) 指定されたメソッドと URL でビルダーを作成します。 |
static RequestEntity.HeadersBuilder<?> | options(URISE url) 指定された URL で HTTP OPTIONS ビルダーを作成します。 |
static RequestEntity.BodyBuilder | patch(URISE url) 指定された URL で HTTP PATCH ビルダーを作成します。 |
static RequestEntity.BodyBuilder | post(URISE url) 指定された URL で HTTP POST ビルダーを作成します。 |
static RequestEntity.BodyBuilder | put(URISE url) 指定された URL で HTTP PUT ビルダーを作成します。 |
StringSE | toString() |
getBody, getHeaders, hasBodycloneSE, finalizeSE, getClassSE, notifySE, notifyAllSE, waitSE, waitSE, waitSEpublic RequestEntity(HttpMethod method, URISE url)
method - メソッド url - URLpublic RequestEntity(@Nullable T body, HttpMethod method, URISE url)
body - 体 method - メソッド url - URLpublic RequestEntity(@Nullable T body, HttpMethod method, URISE url, TypeSE type)
body - 体 method - メソッド url - URLtype - ジェネリクス型解決に使用される型 public RequestEntity(MultiValueMap<StringSE,StringSE> headers, HttpMethod method, URISE url)
headers - ヘッダー method - メソッド url - URLpublic RequestEntity(@Nullable T body, @Nullable MultiValueMap<StringSE,StringSE> headers, @Nullable HttpMethod method, URISE url)
body - 体 headers - ヘッダー method - メソッド url - URL@Nullable public HttpMethod getMethod()
HttpMethod 列挙値としての HTTP メソッド public URISE getUrl()
URI としての URL public boolean equals(@Nullable ObjectSE other)
HttpEntity<T> の equals public int hashCode()
HttpEntity<T> の hashCode public StringSE toString()
HttpEntity<T> の toString public static RequestEntity.BodyBuilder method(HttpMethod method, URISE url)
method - HTTP メソッド (GET、POST など)url - URLpublic static RequestEntity.HeadersBuilder<?> get(URISE url)
url - URLpublic static RequestEntity.HeadersBuilder<?> head(URISE url)
url - URLpublic static RequestEntity.BodyBuilder post(URISE url)
url - URLpublic static RequestEntity.BodyBuilder put(URISE url)
url - URLpublic static RequestEntity.BodyBuilder patch(URISE url)
url - URLpublic static RequestEntity.HeadersBuilder<?> delete(URISE url)
url - URLpublic static RequestEntity.HeadersBuilder<?> options(URISE url)
url - URL