[JAVA][Webclient] Add constructor to allow custom WebClient to be passed into ApiClient (#882)

* add constructor to allow custom webclient to be passed into ApiClient
This commit is contained in:
Hugo Barrigas 2018-08-25 14:22:36 +01:00 committed by Jérémie Bresson
parent 39e9206976
commit 37fd4264ac
2 changed files with 26 additions and 20 deletions

View File

@ -33,6 +33,7 @@ import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.ExchangeStrategies;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import java.util.Optional;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
@ -87,20 +88,22 @@ public class ApiClient {
public ApiClient() { public ApiClient() {
this.dateFormat = createDefaultDateFormat(); this.dateFormat = createDefaultDateFormat();
this.webClient = buildWebClient(new ObjectMapper(), this.dateFormat); this.webClient = buildWebClient(new ObjectMapper(), dateFormat);
this.init();
init();
} }
public ApiClient(ObjectMapper mapper, DateFormat format) { public ApiClient(ObjectMapper mapper, DateFormat format) {
this(buildWebClient(mapper.copy(), format), format); this(buildWebClient(mapper.copy(), format), format);
} }
public ApiClient(WebClient webClient, ObjectMapper mapper, DateFormat format) {
this(Optional.ofNullable(webClient).orElseGet(() ->buildWebClient(mapper.copy(), format)), format);
}
private ApiClient(WebClient webClient, DateFormat format) { private ApiClient(WebClient webClient, DateFormat format) {
this.webClient = webClient; this.webClient = webClient;
this.dateFormat = format; this.dateFormat = format;
this.init();
init();
} }
public DateFormat createDefaultDateFormat() { public DateFormat createDefaultDateFormat() {

View File

@ -33,6 +33,7 @@ import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.ExchangeStrategies;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import java.util.Optional;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
@ -87,20 +88,22 @@ public class ApiClient {
public ApiClient() { public ApiClient() {
this.dateFormat = createDefaultDateFormat(); this.dateFormat = createDefaultDateFormat();
this.webClient = buildWebClient(new ObjectMapper(), this.dateFormat); this.webClient = buildWebClient(new ObjectMapper(), dateFormat);
this.init();
init();
} }
public ApiClient(ObjectMapper mapper, DateFormat format) { public ApiClient(ObjectMapper mapper, DateFormat format) {
this(buildWebClient(mapper.copy(), format), format); this(buildWebClient(mapper.copy(), format), format);
} }
public ApiClient(WebClient webClient, ObjectMapper mapper, DateFormat format) {
this(Optional.ofNullable(webClient).orElseGet(() ->buildWebClient(mapper.copy(), format)), format);
}
private ApiClient(WebClient webClient, DateFormat format) { private ApiClient(WebClient webClient, DateFormat format) {
this.webClient = webClient; this.webClient = webClient;
this.dateFormat = format; this.dateFormat = format;
this.init();
init();
} }
public DateFormat createDefaultDateFormat() { public DateFormat createDefaultDateFormat() {