Package com.linecorp.armeria.client
Class BlockingWebClientRequestPreparation
java.lang.Object
com.linecorp.armeria.client.BlockingWebClientRequestPreparation
- All Implemented Interfaces:
HttpRequestSetters
Prepares and executes a new
HttpRequest
for BlockingWebClient
.-
Method Summary
Modifier and TypeMethodDescriptionas
(ResponseAs<AggregatedHttpResponse, U> responseAs) Sets the specifiedResponseAs
that converts theAggregatedHttpResponse
into another.asBytes()
Converts the response content into bytes.asJson
(TypeReference<? extends T> typeRef) Deserializes the JSON response content into the specified Java type using the defaultObjectMapper
.asJson
(TypeReference<? extends T> typeRef, ObjectMapper mapper) Deserializes the JSON response content into the specified Java type using the specifiedObjectMapper
.Deserializes the JSON response content into the specified non-container type using the defaultObjectMapper
.asJson
(Class<? extends T> clazz, ObjectMapper mapper) Deserializes the JSON response content into the specified non-container type using the specifiedObjectMapper
.asString()
Converts the response content intoString
.attr
(AttributeKey<V> key, V value) Sets the content for this request.Sets the content for this request.content
(MediaType contentType, CharSequence content) Sets the content for this request.Sets the content for this request.Sets the content for this request.Sets thePublisher
for this request.Sets the content as UTF_8 for this request.Sets the content as UTF_8 for this request.contentJson
(Object content) Sets the content for this request.Sets a cookie for this request.Sets multiple cookies for this request.Shortcut to set DELETE method and path.Disables path parameters substitution.execute()
Builds and executes the blocking request.Shortcut to set GET method and path.Shortcut to set HEAD method and path.header
(CharSequence name, Object value) Adds a header for this request.headers
(Iterable<? extends Map.Entry<? extends CharSequence, String>> headers) Adds multiple headers for this request.maxResponseLength
(long maxResponseLength) method
(HttpMethod method) Sets the method for this request.Shortcut to set OPTIONS method and path.Shortcut to set PATCH method and path.Sets the path for this request.Sets a path param for this request.pathParams
(Map<String, ?> pathParams) Sets multiple path params for this request.Shortcut to set POST method and path.Shortcut to set PUT method and path.queryParam
(String name, Object value) Sets a query param for this request.queryParams
(Iterable<? extends Map.Entry<? extends String, String>> queryParams) Sets multiple query params for this request.requestOptions
(RequestOptions requestOptions) responseTimeout
(Duration responseTimeout) responseTimeoutMillis
(long responseTimeoutMillis) Shortcut to set TRACE method and path.trailers
(Iterable<? extends Map.Entry<? extends CharSequence, String>> trailers) Sets HTTP trailers for this request.writeTimeout
(Duration writeTimeout) writeTimeoutMillis
(long writeTimeoutMillis)
-
Method Details
-
execute
Builds and executes the blocking request. -
as
@UnstableApi public <U> TransformingRequestPreparation<AggregatedHttpResponse,U> as(ResponseAs<AggregatedHttpResponse, U> responseAs) Sets the specifiedResponseAs
that converts theAggregatedHttpResponse
into another. -
asBytes
@UnstableApi public TransformingRequestPreparation<AggregatedHttpResponse,ResponseEntity<byte[]>> asBytes()Converts the response content into bytes. For example:BlockingWebClient client = BlockingWebClient.of("https://api.example.com"); ResponseEntity<byte[]> response = client.prepare() .get("/v1/items/1") .asBytes() .execute();
-
asString
@UnstableApi public TransformingRequestPreparation<AggregatedHttpResponse,ResponseEntity<String>> asString()Converts the response content intoString
. For example:BlockingWebClient client = BlockingWebClient.of("https://api.example.com"); ResponseEntity<String> response = client.prepare() .get("/v1/items/1") .asString() .execute();
-
asJson
@UnstableApi public <T> TransformingRequestPreparation<AggregatedHttpResponse,ResponseEntity<T>> asJson(Class<? extends T> clazz) Deserializes the JSON response content into the specified non-container type using the defaultObjectMapper
. For example:BlockingWebClient client = BlockingWebClient.of("https://api.example.com"); ResponseEntity<MyObject> response = client.prepare() .get("/v1/items/1") .asJson(MyObject.class) .execute();
Note that this method should NOT be used if the result type is a container such as
Collection
orMap
. UseasJson(TypeReference)
for the container type.- Throws:
InvalidHttpResponseException
- if theHttpStatus
of the response is not success or fails to decode the response body into the result type.- See Also:
-
asJson
@UnstableApi public <T> TransformingRequestPreparation<AggregatedHttpResponse,ResponseEntity<T>> asJson(Class<? extends T> clazz, ObjectMapper mapper) Deserializes the JSON response content into the specified non-container type using the specifiedObjectMapper
. For example:ObjectMapper mapper = ...; BlockingWebClient client = BlockingWebClient.of("https://api.example.com"); ResponseEntity<MyObject> response = client.prepare() .get("/v1/items/1") .asJson(MyObject.class, mapper) .execute();
Note that this method should NOT be used if the result type is a container such as
Collection
orMap
. UseasJson(TypeReference, ObjectMapper)
for the container type.- Throws:
InvalidHttpResponseException
- if theHttpStatus
of the response is not success or fails to decode the response body into the result type.
-
asJson
@UnstableApi public <T> TransformingRequestPreparation<AggregatedHttpResponse,ResponseEntity<T>> asJson(TypeReference<? extends T> typeRef) Deserializes the JSON response content into the specified Java type using the defaultObjectMapper
. This method is useful when you want to deserialize the content into a container type such asList
andMap
. For example:BlockingWebClient client = BlockingWebClient.of("https://api.example.com"); ResponseEntity<List<MyObject>> response = client.prepare() .get("/v1/items/1") .asJson(new TypeReference<List<MyObject>>() {}) .execute();
- Throws:
InvalidHttpResponseException
- if theHttpStatus
of the response is not success or fails to decode the response body into the result type.- See Also:
-
asJson
@UnstableApi public <T> TransformingRequestPreparation<AggregatedHttpResponse,ResponseEntity<T>> asJson(TypeReference<? extends T> typeRef, ObjectMapper mapper) Deserializes the JSON response content into the specified Java type using the specifiedObjectMapper
. For example:ObjectMapper mapper = ...; BlockingWebClient client = BlockingWebClient.of("https://api.example.com"); ResponseEntity<List<MyObject>> response = client.prepare() .get("/v1/items/1") .asJson(new TypeReference<List<MyObject>>() {}, mapper) .execute();
- Throws:
InvalidHttpResponseException
- if theHttpStatus
of the response is not success or fails to decode the response body into the result type.
-
requestOptions
-
get
Description copied from interface:HttpRequestSetters
Shortcut to set GET method and path.- Specified by:
get
in interfaceHttpRequestSetters
-
post
Description copied from interface:HttpRequestSetters
Shortcut to set POST method and path.- Specified by:
post
in interfaceHttpRequestSetters
-
put
Description copied from interface:HttpRequestSetters
Shortcut to set PUT method and path.- Specified by:
put
in interfaceHttpRequestSetters
-
delete
Description copied from interface:HttpRequestSetters
Shortcut to set DELETE method and path.- Specified by:
delete
in interfaceHttpRequestSetters
-
patch
Description copied from interface:HttpRequestSetters
Shortcut to set PATCH method and path.- Specified by:
patch
in interfaceHttpRequestSetters
-
options
Description copied from interface:HttpRequestSetters
Shortcut to set OPTIONS method and path.- Specified by:
options
in interfaceHttpRequestSetters
-
head
Description copied from interface:HttpRequestSetters
Shortcut to set HEAD method and path.- Specified by:
head
in interfaceHttpRequestSetters
-
trace
Description copied from interface:HttpRequestSetters
Shortcut to set TRACE method and path.- Specified by:
trace
in interfaceHttpRequestSetters
-
method
Description copied from interface:HttpRequestSetters
Sets the method for this request.- Specified by:
method
in interfaceHttpRequestSetters
- See Also:
-
path
Description copied from interface:HttpRequestSetters
Sets the path for this request.- Specified by:
path
in interfaceHttpRequestSetters
-
content
Description copied from interface:HttpRequestSetters
Sets the content as UTF_8 for this request.- Specified by:
content
in interfaceHttpRequestSetters
-
content
Description copied from interface:HttpRequestSetters
Sets the content for this request.- Specified by:
content
in interfaceHttpRequestSetters
-
content
Description copied from interface:HttpRequestSetters
Sets the content for this request.- Specified by:
content
in interfaceHttpRequestSetters
-
content
@FormatMethod public BlockingWebClientRequestPreparation content(@FormatString String format, Object... content) Description copied from interface:HttpRequestSetters
Sets the content as UTF_8 for this request. Thecontent
is formatted byString.format(Locale, String, Object...)
with English locale.- Specified by:
content
in interfaceHttpRequestSetters
-
content
@FormatMethod public BlockingWebClientRequestPreparation content(MediaType contentType, @FormatString String format, Object... content) Description copied from interface:HttpRequestSetters
Sets the content for this request. Thecontent
is formatted byString.format(Locale, String, Object...)
with English locale.- Specified by:
content
in interfaceHttpRequestSetters
-
content
Description copied from interface:HttpRequestSetters
Sets the content for this request. Thecontent
will be wrapped usingHttpData.wrap(byte[])
, so any changes made tocontent
will be reflected in the request.- Specified by:
content
in interfaceHttpRequestSetters
-
content
Description copied from interface:HttpRequestSetters
Sets the content for this request.- Specified by:
content
in interfaceHttpRequestSetters
-
content
public BlockingWebClientRequestPreparation content(MediaType contentType, org.reactivestreams.Publisher<? extends HttpData> content) Description copied from interface:HttpRequestSetters
Sets thePublisher
for this request.- Specified by:
content
in interfaceHttpRequestSetters
-
contentJson
Description copied from interface:HttpRequestSetters
Sets the content for this request. Thecontent
is converted into JSON format using the defaultObjectMapper
.- Specified by:
contentJson
in interfaceHttpRequestSetters
-
header
Description copied from interface:HttpRequestSetters
Adds a header for this request. For example:HttpRequest.builder() .get("/") .header("authorization", "foo") .build();
- Specified by:
header
in interfaceHttpRequestSetters
-
headers
public BlockingWebClientRequestPreparation headers(Iterable<? extends Map.Entry<? extends CharSequence, String>> headers) Description copied from interface:HttpRequestSetters
Adds multiple headers for this request. For example:HttpRequest.builder() .get("/") .headers(HttpHeaders.of("authorization", "foo", "bar", "baz")) .build();
- Specified by:
headers
in interfaceHttpRequestSetters
- See Also:
-
trailers
public BlockingWebClientRequestPreparation trailers(Iterable<? extends Map.Entry<? extends CharSequence, String>> trailers) Description copied from interface:HttpRequestSetters
Sets HTTP trailers for this request.- Specified by:
trailers
in interfaceHttpRequestSetters
-
pathParam
Description copied from interface:HttpRequestSetters
Sets a path param for this request. For example:HttpRequest.builder() .get("/{foo}") .pathParam("foo", "bar") .build(); // GET `/bar`
- Specified by:
pathParam
in interfaceHttpRequestSetters
-
pathParams
Description copied from interface:HttpRequestSetters
Sets multiple path params for this request. For example:HttpRequest.builder() .get("/{foo}/:bar") .pathParams(Map.of("foo", 1, "bar", 2)) .build(); // GET `/1/2`
- Specified by:
pathParams
in interfaceHttpRequestSetters
-
disablePathParams
Description copied from interface:HttpRequestSetters
Disables path parameters substitution. If path parameter is not disabled and a parameter's, specified using{}
or:
, value is not found, anIllegalStateException
is thrown.- Specified by:
disablePathParams
in interfaceHttpRequestSetters
-
queryParam
Description copied from interface:HttpRequestSetters
Sets a query param for this request. For example:HttpRequest.builder() .get("/endpoint") .queryParam("foo", "bar") .build(); // GET `/endpoint?foo=bar`
- Specified by:
queryParam
in interfaceHttpRequestSetters
-
queryParams
public BlockingWebClientRequestPreparation queryParams(Iterable<? extends Map.Entry<? extends String, String>> queryParams) Description copied from interface:HttpRequestSetters
Sets multiple query params for this request. For example:HttpRequest.builder() .get("/endpoint") .queryParams(QueryParams.of("from", "foo", "limit", 10)) .build(); // GET `/endpoint?from=foo&limit=10`
- Specified by:
queryParams
in interfaceHttpRequestSetters
- See Also:
-
cookie
Description copied from interface:HttpRequestSetters
Sets a cookie for this request. For example:HttpRequest.builder() .get("/") .cookie(Cookie.ofSecure("cookie", "foo")) .build();
- Specified by:
cookie
in interfaceHttpRequestSetters
- See Also:
-
cookies
Description copied from interface:HttpRequestSetters
Sets multiple cookies for this request. For example:HttpRequest.builder() .get("/") .cookies(Cookies.ofSecure(Cookie.ofSecure("cookie1", "foo"), Cookie.ofSecure("cookie2", "bar"))) .build();
- Specified by:
cookies
in interfaceHttpRequestSetters
- See Also:
-
responseTimeout
-
responseTimeoutMillis
-
writeTimeout
-
writeTimeoutMillis
-
maxResponseLength
-
attr
-