Skip to content

Commit

Permalink
Consistent ordering of WebClient.Builder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Jul 31, 2019
1 parent 59064f0 commit 438b40f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,11 +66,11 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
@Nullable
private ClientHttpConnector connector;

private ExchangeStrategies exchangeStrategies;

@Nullable
private ExchangeFunction exchangeFunction;

private ExchangeStrategies exchangeStrategies;


public DefaultWebClientBuilder() {
this.exchangeStrategies = ExchangeStrategies.withDefaults();
Expand All @@ -80,8 +80,8 @@ public DefaultWebClientBuilder(DefaultWebClientBuilder other) {
Assert.notNull(other, "DefaultWebClientBuilder must not be null");

this.baseUrl = other.baseUrl;
this.defaultUriVariables =
other.defaultUriVariables != null ? new LinkedHashMap<>(other.defaultUriVariables) : null;
this.defaultUriVariables = (other.defaultUriVariables != null ?
new LinkedHashMap<>(other.defaultUriVariables) : null);
this.uriBuilderFactory = other.uriBuilderFactory;
if (other.defaultHeaders != null) {
this.defaultHeaders = new HttpHeaders();
Expand All @@ -90,13 +90,13 @@ public DefaultWebClientBuilder(DefaultWebClientBuilder other) {
else {
this.defaultHeaders = null;
}
this.defaultCookies =
other.defaultCookies != null ? new LinkedMultiValueMap<>(other.defaultCookies) : null;
this.defaultCookies = (other.defaultCookies != null ?
new LinkedMultiValueMap<>(other.defaultCookies) : null);
this.defaultRequest = other.defaultRequest;
this.filters = other.filters != null ? new ArrayList<>(other.filters) : null;
this.connector = other.connector;
this.exchangeFunction = other.exchangeFunction;
this.exchangeStrategies = other.exchangeStrategies;
this.exchangeFunction = other.exchangeFunction;
}


Expand Down Expand Up @@ -163,12 +163,6 @@ public WebClient.Builder defaultRequest(Consumer<WebClient.RequestHeadersSpec<?>
return this;
}

@Override
public WebClient.Builder clientConnector(ClientHttpConnector connector) {
this.connector = connector;
return this;
}

@Override
public WebClient.Builder filter(ExchangeFilterFunction filter) {
Assert.notNull(filter, "ExchangeFilterFunction must not be null");
Expand All @@ -190,8 +184,8 @@ private List<ExchangeFilterFunction> initFilters() {
}

@Override
public WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction) {
this.exchangeFunction = exchangeFunction;
public WebClient.Builder clientConnector(ClientHttpConnector connector) {
this.connector = connector;
return this;
}

Expand All @@ -202,6 +196,23 @@ public WebClient.Builder exchangeStrategies(ExchangeStrategies strategies) {
return this;
}

@Override
public WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction) {
this.exchangeFunction = exchangeFunction;
return this;
}

@Override
public WebClient.Builder apply(Consumer<WebClient.Builder> builderConsumer) {
builderConsumer.accept(this);
return this;
}

@Override
public WebClient.Builder clone() {
return new DefaultWebClientBuilder(this);
}

@Override
public WebClient build() {
ExchangeFunction exchange = initExchangeFunction();
Expand Down Expand Up @@ -245,15 +256,4 @@ private static <K, V> MultiValueMap<K, V> unmodifiableCopy(MultiValueMap<K, V> m
return CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>(map));
}

@Override
public WebClient.Builder clone() {
return new DefaultWebClientBuilder(this);
}

@Override
public WebClient.Builder apply(Consumer<WebClient.Builder> builderConsumer) {
builderConsumer.accept(this);
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -303,29 +303,27 @@ interface Builder {
*/
Builder exchangeFunction(ExchangeFunction exchangeFunction);

/**
* Clone this {@code WebClient.Builder}.
*/
Builder clone();

/**
* Apply the given {@code Consumer} to this builder instance.
* <p>This can be useful for applying pre-packaged customizations.
* @param builderConsumer the consumer to apply
*/
Builder apply(Consumer<Builder> builderConsumer);

/**
* Clone this {@code WebClient.Builder}.
*/
Builder clone();

/**
* Builder the {@link WebClient} instance.
*/
WebClient build();

}


/**
* Contract for specifying the URI for a request.
*
* @param <S> a self reference to the spec type
*/
interface UriSpec<S extends RequestHeadersSpec<?>> {
Expand Down Expand Up @@ -359,7 +357,6 @@ interface UriSpec<S extends RequestHeadersSpec<?>> {

/**
* Contract for specifying request headers leading up to the exchange.
*
* @param <S> a self reference to the spec type
*/
interface RequestHeadersSpec<S extends RequestHeadersSpec<S>> {
Expand Down Expand Up @@ -525,9 +522,9 @@ interface RequestBodySpec extends RequestHeadersSpec<RequestBodySpec> {
* {@linkplain BodyInserters#fromPublisher Publisher inserter}.
* For example:
* <p><pre>
* Mono<Person> personMono = ... ;
* Mono&lt;Person&gt; personMono = ... ;
*
* Mono<Void> result = client.post()
* Mono&lt;Void&gt; result = client.post()
* .uri("/persons/{id}", id)
* .contentType(MediaType.APPLICATION_JSON)
* .body(personMono, Person.class)
Expand Down

0 comments on commit 438b40f

Please sign in to comment.