@ -40,6 +40,7 @@ import org.springframework.web.util.UriBuilderFactory;
* Default implementation of { @link WebClient . Builder } .
* Default implementation of { @link WebClient . Builder } .
*
*
* @author Rossen Stoyanchev
* @author Rossen Stoyanchev
* @author Brian Clozel
* @since 5 . 0
* @since 5 . 0
* /
* /
final class DefaultWebClientBuilder implements WebClient . Builder {
final class DefaultWebClientBuilder implements WebClient . Builder {
@ -79,14 +80,16 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
@Nullable
@Nullable
private ClientHttpConnector connector ;
private ClientHttpConnector connector ;
private ExchangeStrategies exchangeStrategies ;
@Nullable
private ExchangeStrategies . Builder strategies ;
private List < Consumer < ExchangeStrategies . Builder > > strategiesConfigurers ;
@Nullable
@Nullable
private ExchangeFunction exchangeFunction ;
private ExchangeFunction exchangeFunction ;
public DefaultWebClientBuilder ( ) {
public DefaultWebClientBuilder ( ) {
this . exchangeStrategies = ExchangeStrategies . withDefaults ( ) ;
}
}
public DefaultWebClientBuilder ( DefaultWebClientBuilder other ) {
public DefaultWebClientBuilder ( DefaultWebClientBuilder other ) {
@ -108,7 +111,7 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
this . defaultRequest = other . defaultRequest ;
this . defaultRequest = other . defaultRequest ;
this . filters = other . filters ! = null ? new ArrayList < > ( other . filters ) : null ;
this . filters = other . filters ! = null ? new ArrayList < > ( other . filters ) : null ;
this . connector = other . connector ;
this . connector = other . connector ;
this . exchangeS trategies = other . exchangeS trategies;
this . s trategies = other . s trategies;
this . exchangeFunction = other . exchangeFunction ;
this . exchangeFunction = other . exchangeFunction ;
}
}
@ -203,9 +206,23 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
}
}
@Override
@Override
@Deprecated
public WebClient . Builder exchangeStrategies ( ExchangeStrategies strategies ) {
public WebClient . Builder exchangeStrategies ( ExchangeStrategies strategies ) {
Assert . notNull ( strategies , "ExchangeStrategies must not be null" ) ;
Assert . notNull ( strategies , "ExchangeStrategies must not be null" ) ;
this . exchangeStrategies = strategies ;
this . strategies = strategies . mutate ( ) ;
return this ;
}
@Override
public WebClient . Builder exchangeStrategies ( ExchangeStrategies . Builder strategies ) {
Assert . notNull ( strategies , "ExchangeStrategies must not be null" ) ;
this . strategies = strategies ;
return this ;
}
@Override
public WebClient . Builder exchangeStrategies ( Consumer < ExchangeStrategies . Builder > configurer ) {
this . strategiesConfigurers . add ( configurer ) ;
return this ;
return this ;
}
}
@ -229,7 +246,7 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
@Override
@Override
public WebClient build ( ) {
public WebClient build ( ) {
ExchangeFunction exchange = ( this . exchangeFunction = = null ?
ExchangeFunction exchange = ( this . exchangeFunction = = null ?
ExchangeFunctions . create ( getOrInitConnector ( ) , this . exchangeStrategies ) :
ExchangeFunctions . create ( getOrInitConnector ( ) , initExchangeStrategies ( ) ) :
this . exchangeFunction ) ;
this . exchangeFunction ) ;
ExchangeFunction filteredExchange = ( this . filters ! = null ? this . filters . stream ( )
ExchangeFunction filteredExchange = ( this . filters ! = null ? this . filters . stream ( )
. reduce ( ExchangeFilterFunction : : andThen )
. reduce ( ExchangeFilterFunction : : andThen )
@ -254,6 +271,19 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
throw new IllegalStateException ( "No suitable default ClientHttpConnector found" ) ;
throw new IllegalStateException ( "No suitable default ClientHttpConnector found" ) ;
}
}
@SuppressWarnings ( "deprecation" )
private ExchangeStrategies initExchangeStrategies ( ) {
if ( CollectionUtils . isEmpty ( this . strategiesConfigurers ) ) {
return this . strategies ! = null ? this . strategies . build ( ) : ExchangeStrategies . withDefaults ( ) ;
}
ExchangeStrategies . Builder builder =
this . strategies ! = null ? this . strategies : ExchangeStrategies . builder ( ) ;
this . strategiesConfigurers . forEach ( configurer - > configurer . accept ( builder ) ) ;
return builder . build ( ) ;
}
private UriBuilderFactory initUriBuilderFactory ( ) {
private UriBuilderFactory initUriBuilderFactory ( ) {
if ( this . uriBuilderFactory ! = null ) {
if ( this . uriBuilderFactory ! = null ) {
return this . uriBuilderFactory ;
return this . uriBuilderFactory ;