Interface WebTestClient.Builder
- Enclosing interface:
- WebTestClient
WebClient via WebClient.Builder.- Since:
- 5.0
- Author:
- Rossen Stoyanchev, Brian Clozel, Sam Brannen, MichaĆ Rowicki
- 
Method SummaryModifier and TypeMethodDescriptionapiVersionInserter(@Nullable ApiVersionInserter apiVersionInserter) Configure anApiVersionInserterto abstract how an API version specified viaWebTestClient.RequestHeadersSpec.apiVersion(Object)is inserted into the request.apply(WebTestClientConfigurer configurer) Apply the given configurer to this builder instance.Configure a base URI as described inWebClient.create(String).build()Build theWebTestClientinstance.clientConnector(ClientHttpConnector connector) Set theClientHttpConnectorto use.codecs(Consumer<ClientCodecConfigurer> configurer) defaultApiVersion(Object version) Global option to specify an API version to add to every request, if not already set.defaultCookie(String cookieName, String... cookieValues) Add the given cookie to all requests that haven't already added it.defaultCookies(Consumer<MultiValueMap<String, String>> cookiesConsumer) Manipulate the default cookies with the given consumer.defaultHeader(String headerName, String... headerValues) Add the given header to all requests that haven't added it.defaultHeaders(Consumer<HttpHeaders> headersConsumer) Manipulate the default headers with the given consumer.entityExchangeResultConsumer(Consumer<EntityExchangeResult<?>> consumer) Configure anEntityExchangeResultcallback that is invoked every time after a response is fully decoded to a single entity, to a List of entities, or to a byte[].exchangeStrategies(ExchangeStrategies strategies) Configure theExchangeStrategiesto use.filter(ExchangeFilterFunction filter) Add the given filter to the filter chain.filters(Consumer<List<ExchangeFilterFunction>> filtersConsumer) Manipulate the filters with the given consumer.responseTimeout(Duration timeout) Max amount of time to wait for responses.uriBuilderFactory(UriBuilderFactory uriBuilderFactory) Provide a pre-configuredUriBuilderFactoryinstance as an alternative to and effectively overridingbaseUrl(String).
- 
Method Details- 
baseUrlConfigure a base URI as described inWebClient.create(String).
- 
uriBuilderFactoryProvide a pre-configuredUriBuilderFactoryinstance as an alternative to and effectively overridingbaseUrl(String).
- 
defaultHeaderAdd the given header to all requests that haven't added it.- Parameters:
- headerName- the header name
- headerValues- the header values
 
- 
defaultHeadersManipulate the default headers with the given consumer. The headers provided to the consumer are "live", so that the consumer can be used to overwrite existing header values, remove values, or use any of the otherHttpHeadersmethods.- Parameters:
- headersConsumer- a function that consumes the- HttpHeaders
- Returns:
- this builder
 
- 
defaultCookieAdd the given cookie to all requests that haven't already added it.- Parameters:
- cookieName- the cookie name
- cookieValues- the cookie values
 
- 
defaultCookiesManipulate the default cookies with the given consumer. The map provided to the consumer is "live", so that the consumer can be used to overwrite existing header values, remove values, or use any of the otherMultiValueMapmethods.- Parameters:
- cookiesConsumer- a function that consumes the cookies map
- Returns:
- this builder
 
- 
defaultApiVersionGlobal option to specify an API version to add to every request, if not already set.- Parameters:
- version- the version to use
- Returns:
- this builder
- Since:
- 7.0
 
- 
apiVersionInserterConfigure anApiVersionInserterto abstract how an API version specified viaWebTestClient.RequestHeadersSpec.apiVersion(Object)is inserted into the request.ApiVersionInserterexposes shortcut methods for several built-in inserter implementation types. See the class-level Javadoc ofApiVersionInserterfor a list of choices.- Parameters:
- apiVersionInserter- the inserter to use
- Since:
- 7.0
 
- 
filterAdd the given filter to the filter chain.- Parameters:
- filter- the filter to be added to the chain
 
- 
filtersManipulate the filters with the given consumer. The list provided to the consumer is "live", so that the consumer can be used to remove filters, change ordering, etc.- Parameters:
- filtersConsumer- a function that consumes the filter list
- Returns:
- this builder
 
- 
codecs- Parameters:
- configurer- the configurer to apply
- Since:
- 5.1.13
 
- 
exchangeStrategiesConfigure theExchangeStrategiesto use.For most cases, prefer using codecs(Consumer)which allows customizing the codecs in theExchangeStrategiesrather than replace them. That ensures multiple parties can contribute to codecs configuration.By default this is set to ExchangeStrategies.withDefaults().- Parameters:
- strategies- the strategies to use
 
- 
responseTimeoutMax amount of time to wait for responses.By default 5 seconds. - Parameters:
- timeout- the response timeout value
 
- 
clientConnectorSet theClientHttpConnectorto use.By default, this is initialized and set internally. However, the connector may also be prepared externally and passed via WebTestClient.bindToServer(ClientHttpConnector)such as forMockMvcWebTestClienttests, and in that case you can use this fromWebTestClient.mutateWith(WebTestClientConfigurer)to replace it.- Parameters:
- connector- the connector to use
- Since:
- 6.1
 
- 
entityExchangeResultConsumerConfigure anEntityExchangeResultcallback that is invoked every time after a response is fully decoded to a single entity, to a List of entities, or to a byte[]. In effect, equivalent to each and all of the below but registered once, globally:client.get().uri("/accounts/1") .exchange() .expectBody(Person.class).consumeWith(exchangeResult -> ... )); client.get().uri("/accounts") .exchange() .expectBodyList(Person.class).consumeWith(exchangeResult -> ... )); client.get().uri("/accounts/1") .exchange() .expectBody().consumeWith(exchangeResult -> ... ));Note that the configured consumer does not apply to responses decoded to Flux<T>which can be consumed outside the workflow of the test client, for example viareactor.test.StepVerifier.- Parameters:
- consumer- the consumer to apply to entity responses
- Returns:
- the builder
- Since:
- 5.3.5
 
- 
applyApply the given configurer to this builder instance.This can be useful for applying pre-packaged customizations. - Parameters:
- configurer- the configurer to apply
 
- 
buildWebTestClient build()Build theWebTestClientinstance.
 
-