private class DefaultWebClient.DefaultRequestBodyUriSpec extends java.lang.Object implements WebClient.RequestBodyUriSpec
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,java.lang.Object> |
attributes |
private MultiValueMap<java.lang.String,java.lang.String> |
cookies |
private HttpHeaders |
headers |
private HttpMethod |
httpMethod |
private BodyInserter<?,? super ClientHttpRequest> |
inserter |
private java.net.URI |
uri |
Constructor and Description |
---|
DefaultRequestBodyUriSpec(HttpMethod httpMethod) |
Modifier and Type | Method and Description |
---|---|
DefaultWebClient.DefaultRequestBodyUriSpec |
accept(MediaType... acceptableMediaTypes)
Set the list of acceptable media types, as
specified by the
Accept header. |
DefaultWebClient.DefaultRequestBodyUriSpec |
acceptCharset(java.nio.charset.Charset... acceptableCharsets)
Set the list of acceptable charsets, as specified
by the
Accept-Charset header. |
WebClient.RequestBodySpec |
attribute(java.lang.String name,
java.lang.Object value)
Set the attribute with the given name to the given value.
|
WebClient.RequestBodySpec |
attributes(java.util.function.Consumer<java.util.Map<java.lang.String,java.lang.Object>> attributesConsumer)
Provides access to every attribute declared so far with the
possibility to add, replace, or remove values.
|
WebClient.RequestHeadersSpec<?> |
body(BodyInserter<?,? super ClientHttpRequest> inserter)
Set the body of the request using the given body inserter.
|
<T,P extends <any>> |
body(P publisher,
java.lang.Class<T> elementClass)
A shortcut for
WebClient.RequestBodySpec.body(BodyInserter) with a
Publisher inserter. |
<T,P extends <any>> |
body(P publisher,
ParameterizedTypeReference<T> typeReference)
A variant of
#body(Publisher, Class) that allows providing
element type information that includes generics via a
ParameterizedTypeReference . |
DefaultWebClient.DefaultRequestBodyUriSpec |
contentLength(long contentLength)
Set the length of the body in bytes, as specified by the
Content-Length header. |
DefaultWebClient.DefaultRequestBodyUriSpec |
contentType(MediaType contentType)
Set the media type of the body, as specified
by the
Content-Type header. |
DefaultWebClient.DefaultRequestBodyUriSpec |
cookie(java.lang.String name,
java.lang.String value)
Add a cookie with the given name and value.
|
DefaultWebClient.DefaultRequestBodyUriSpec |
cookies(java.util.function.Consumer<MultiValueMap<java.lang.String,java.lang.String>> cookiesConsumer)
Provides access to every cookie declared so far with the possibility
to add, replace, or remove values.
|
private HttpRequest |
createRequest() |
<any> |
exchange()
Perform the HTTP request and return a
ClientResponse with the
response status and headers. |
private MultiValueMap<java.lang.String,java.lang.String> |
getCookies() |
private HttpHeaders |
getHeaders() |
DefaultWebClient.DefaultRequestBodyUriSpec |
header(java.lang.String headerName,
java.lang.String... headerValues)
Add the given, single header value under the given name.
|
DefaultWebClient.DefaultRequestBodyUriSpec |
headers(java.util.function.Consumer<HttpHeaders> headersConsumer)
Provides access to every header declared so far with the possibility
to add, replace, or remove values.
|
DefaultWebClient.DefaultRequestBodyUriSpec |
ifModifiedSince(java.time.ZonedDateTime ifModifiedSince)
Set the value of the
If-Modified-Since header. |
DefaultWebClient.DefaultRequestBodyUriSpec |
ifNoneMatch(java.lang.String... ifNoneMatches)
Set the values of the
If-None-Match header. |
private MultiValueMap<java.lang.String,java.lang.String> |
initCookies() |
private HttpHeaders |
initHeaders() |
private ClientRequest.Builder |
initRequestBuilder() |
private java.net.URI |
initUri() |
WebClient.ResponseSpec |
retrieve()
Perform the HTTP request and retrieve the response body:
|
WebClient.RequestHeadersSpec<?> |
syncBody(java.lang.Object body)
A shortcut for
WebClient.RequestBodySpec.body(BodyInserter) with an
Object inserter. |
WebClient.RequestBodySpec |
uri(java.util.function.Function<UriBuilder,java.net.URI> uriFunction)
Specify the URI by through a
UriBuilder . |
WebClient.RequestBodySpec |
uri(java.lang.String uriTemplate,
java.util.function.Function<UriBuilder,java.net.URI> uriFunction)
Specify the URI starting with a URI template and finishing off with a
UriBuilder created from the template. |
WebClient.RequestBodySpec |
uri(java.lang.String uriTemplate,
java.util.Map<java.lang.String,?> uriVariables)
Specify the URI for the request using a URI template and URI variables.
|
WebClient.RequestBodySpec |
uri(java.lang.String uriTemplate,
java.lang.Object... uriVariables)
Specify the URI for the request using a URI template and URI variables.
|
WebClient.RequestBodySpec |
uri(java.net.URI uri)
Specify the URI using an absolute, fully constructed
URI . |
private final HttpMethod httpMethod
@Nullable private java.net.URI uri
@Nullable private HttpHeaders headers
@Nullable private MultiValueMap<java.lang.String,java.lang.String> cookies
@Nullable private BodyInserter<?,? super ClientHttpRequest> inserter
private final java.util.Map<java.lang.String,java.lang.Object> attributes
DefaultRequestBodyUriSpec(HttpMethod httpMethod)
public WebClient.RequestBodySpec uri(java.lang.String uriTemplate, java.lang.Object... uriVariables)
WebClient.UriSpec
UriBuilderFactory
was configured for the client (e.g.
with a base URI) it will be used to expand the URI template.uri
in interface WebClient.UriSpec<WebClient.RequestBodySpec>
public WebClient.RequestBodySpec uri(java.lang.String uriTemplate, java.util.Map<java.lang.String,?> uriVariables)
WebClient.UriSpec
UriBuilderFactory
was configured for the client (e.g.
with a base URI) it will be used to expand the URI template.uri
in interface WebClient.UriSpec<WebClient.RequestBodySpec>
public WebClient.RequestBodySpec uri(java.lang.String uriTemplate, java.util.function.Function<UriBuilder,java.net.URI> uriFunction)
WebClient.UriSpec
UriBuilder
created from the template.uri
in interface WebClient.UriSpec<WebClient.RequestBodySpec>
public WebClient.RequestBodySpec uri(java.util.function.Function<UriBuilder,java.net.URI> uriFunction)
WebClient.UriSpec
UriBuilder
.uri
in interface WebClient.UriSpec<WebClient.RequestBodySpec>
WebClient.UriSpec.uri(String, Function)
public WebClient.RequestBodySpec uri(java.net.URI uri)
WebClient.UriSpec
URI
.uri
in interface WebClient.UriSpec<WebClient.RequestBodySpec>
private HttpHeaders getHeaders()
private MultiValueMap<java.lang.String,java.lang.String> getCookies()
public DefaultWebClient.DefaultRequestBodyUriSpec header(java.lang.String headerName, java.lang.String... headerValues)
WebClient.RequestHeadersSpec
header
in interface WebClient.RequestHeadersSpec<WebClient.RequestBodySpec>
headerName
- the header nameheaderValues
- the header value(s)public DefaultWebClient.DefaultRequestBodyUriSpec headers(java.util.function.Consumer<HttpHeaders> headersConsumer)
WebClient.RequestHeadersSpec
headers
in interface WebClient.RequestHeadersSpec<WebClient.RequestBodySpec>
headersConsumer
- the consumer to provide access topublic WebClient.RequestBodySpec attribute(java.lang.String name, java.lang.Object value)
WebClient.RequestHeadersSpec
attribute
in interface WebClient.RequestHeadersSpec<WebClient.RequestBodySpec>
name
- the name of the attribute to addvalue
- the value of the attribute to addpublic WebClient.RequestBodySpec attributes(java.util.function.Consumer<java.util.Map<java.lang.String,java.lang.Object>> attributesConsumer)
WebClient.RequestHeadersSpec
attributes
in interface WebClient.RequestHeadersSpec<WebClient.RequestBodySpec>
attributesConsumer
- the consumer to provide access topublic DefaultWebClient.DefaultRequestBodyUriSpec accept(MediaType... acceptableMediaTypes)
WebClient.RequestHeadersSpec
Accept
header.accept
in interface WebClient.RequestHeadersSpec<WebClient.RequestBodySpec>
acceptableMediaTypes
- the acceptable media typespublic DefaultWebClient.DefaultRequestBodyUriSpec acceptCharset(java.nio.charset.Charset... acceptableCharsets)
WebClient.RequestHeadersSpec
Accept-Charset
header.acceptCharset
in interface WebClient.RequestHeadersSpec<WebClient.RequestBodySpec>
acceptableCharsets
- the acceptable charsetspublic DefaultWebClient.DefaultRequestBodyUriSpec contentType(MediaType contentType)
WebClient.RequestBodySpec
Content-Type
header.contentType
in interface WebClient.RequestBodySpec
contentType
- the content typeHttpHeaders.setContentType(MediaType)
public DefaultWebClient.DefaultRequestBodyUriSpec contentLength(long contentLength)
WebClient.RequestBodySpec
Content-Length
header.contentLength
in interface WebClient.RequestBodySpec
contentLength
- the content lengthHttpHeaders.setContentLength(long)
public DefaultWebClient.DefaultRequestBodyUriSpec cookie(java.lang.String name, java.lang.String value)
WebClient.RequestHeadersSpec
cookie
in interface WebClient.RequestHeadersSpec<WebClient.RequestBodySpec>
name
- the cookie namevalue
- the cookie valuepublic DefaultWebClient.DefaultRequestBodyUriSpec cookies(java.util.function.Consumer<MultiValueMap<java.lang.String,java.lang.String>> cookiesConsumer)
WebClient.RequestHeadersSpec
cookies
in interface WebClient.RequestHeadersSpec<WebClient.RequestBodySpec>
cookiesConsumer
- the consumer to provide access topublic DefaultWebClient.DefaultRequestBodyUriSpec ifModifiedSince(java.time.ZonedDateTime ifModifiedSince)
WebClient.RequestHeadersSpec
If-Modified-Since
header.
The date should be specified as the number of milliseconds since January 1, 1970 GMT.
ifModifiedSince
in interface WebClient.RequestHeadersSpec<WebClient.RequestBodySpec>
ifModifiedSince
- the new value of the headerpublic DefaultWebClient.DefaultRequestBodyUriSpec ifNoneMatch(java.lang.String... ifNoneMatches)
WebClient.RequestHeadersSpec
If-None-Match
header.ifNoneMatch
in interface WebClient.RequestHeadersSpec<WebClient.RequestBodySpec>
ifNoneMatches
- the new value of the headerpublic WebClient.RequestHeadersSpec<?> body(BodyInserter<?,? super ClientHttpRequest> inserter)
WebClient.RequestBodySpec
BodyInserters
provides access to built-in implementations of
BodyInserter
.body
in interface WebClient.RequestBodySpec
inserter
- the body inserter to use for the request bodyBodyInserters
public <T,P extends <any>> WebClient.RequestHeadersSpec<?> body(P publisher, ParameterizedTypeReference<T> typeReference)
WebClient.RequestBodySpec
#body(Publisher, Class)
that allows providing
element type information that includes generics via a
ParameterizedTypeReference
.body
in interface WebClient.RequestBodySpec
T
- the type of the elements contained in the publisherP
- the type of the Publisher
publisher
- the Publisher
to write to the requesttypeReference
- the type reference of elements contained in the publisherpublic <T,P extends <any>> WebClient.RequestHeadersSpec<?> body(P publisher, java.lang.Class<T> elementClass)
WebClient.RequestBodySpec
WebClient.RequestBodySpec.body(BodyInserter)
with a
Publisher inserter.
For example:
MonopersonMono = ... ; Mono result = client.post() .uri("/persons/{id}", id) .contentType(MediaType.APPLICATION_JSON) .body(personMono, Person.class) .retrieve() .bodyToMono(Void.class);
body
in interface WebClient.RequestBodySpec
T
- the type of the elements contained in the publisherP
- the type of the Publisher
publisher
- the Publisher
to write to the requestelementClass
- the class of elements contained in the publisherpublic WebClient.RequestHeadersSpec<?> syncBody(java.lang.Object body)
WebClient.RequestBodySpec
WebClient.RequestBodySpec.body(BodyInserter)
with an
Object inserter.
For example:
Person person = ... ; Mono<Void> result = client.post() .uri("/persons/{id}", id) .contentType(MediaType.APPLICATION_JSON) .syncBody(person) .retrieve() .bodyToMono(Void.class);
For multipart requests, provide a
MultiValueMap
. The
values in the MultiValueMap
can be any Object representing
the body of the part, or an
HttpEntity
representing
a part with body and headers. The MultiValueMap
can be built
with MultipartBodyBuilder
.
syncBody
in interface WebClient.RequestBodySpec
body
- the Object
to write to the requestpublic <any> exchange()
WebClient.RequestHeadersSpec
ClientResponse
with the
response status and headers. You can then use methods of the response
to consume the body:
Mono<Person> mono = client.get() .uri("/persons/1") .accept(MediaType.APPLICATION_JSON) .exchange() .flatMap(response -> response.bodyToMono(Person.class)); Flux<Person> flux = client.get() .uri("/persons") .accept(MediaType.APPLICATION_STREAM_JSON) .exchange() .flatMapMany(response -> response.bodyToFlux(Person.class));
NOTE: You must always use one of the body or
entity methods of the response to ensure resources are released.
See ClientResponse
for more details.
exchange
in interface WebClient.RequestHeadersSpec<WebClient.RequestBodySpec>
Mono
for the responseWebClient.RequestHeadersSpec.retrieve()
private ClientRequest.Builder initRequestBuilder()
private java.net.URI initUri()
private HttpHeaders initHeaders()
private MultiValueMap<java.lang.String,java.lang.String> initCookies()
public WebClient.ResponseSpec retrieve()
WebClient.RequestHeadersSpec
Mono<Person> bodyMono = client.get() .uri("/persons/1") .accept(MediaType.APPLICATION_JSON) .retrieve() .bodyToMono(Person.class);
This method is a shortcut to using WebClient.RequestHeadersSpec.exchange()
and
decoding the response body through ClientResponse
.
retrieve
in interface WebClient.RequestHeadersSpec<WebClient.RequestBodySpec>
ResponseSpec
to specify how to decode the bodyWebClient.RequestHeadersSpec.exchange()
private HttpRequest createRequest()