From a31a4f8148fa1ea9003e35c3719896ddd5878200 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Fri, 10 Jan 2020 15:59:59 +0100 Subject: [PATCH] Copy strategiesConfigurers when cloning WebClient.Builder This commit fixes the missing `strategiesConfigurers` copy when the `WebClient.Builder` is cloned. Fixes gh-24329 --- .../client/DefaultWebClientBuilder.java | 3 ++- .../client/DefaultWebClientTests.java | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java index c255c439d326..dfd1087598b2 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -114,6 +114,7 @@ public DefaultWebClientBuilder(DefaultWebClientBuilder other) { this.filters = other.filters != null ? new ArrayList<>(other.filters) : null; this.connector = other.connector; this.strategies = other.strategies; + this.strategiesConfigurers = other.strategiesConfigurers != null ? new ArrayList<>(other.strategiesConfigurers) : null; this.exchangeFunction = other.exchangeFunction; } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java index 7b4a06277413..61943fc0b5c7 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.function.Consumer; import java.util.function.Predicate; import org.junit.jupiter.api.BeforeEach; @@ -36,6 +37,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; +import org.springframework.http.codec.ClientCodecConfigurer; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; @@ -231,6 +233,23 @@ public void mutateDoesCopy() { builder1a.defaultCookies(cookies -> assertThat(cookies.size()).isEqualTo(2)); } + @Test + void cloneBuilder() { + Consumer codecsConfig = c -> {}; + ExchangeFunction exchangeFunction = request -> Mono.empty(); + WebClient.Builder builder = WebClient.builder().baseUrl("https://example.org") + .exchangeFunction(exchangeFunction) + .filter((request, next) -> Mono.empty()) + .codecs(codecsConfig); + + WebClient.Builder clonedBuilder = builder.clone(); + + assertThat(clonedBuilder).extracting("baseUrl").isEqualTo("https://example.org"); + assertThat(clonedBuilder).extracting("filters").isNotNull(); + assertThat(clonedBuilder).extracting("strategiesConfigurers").isNotNull(); + assertThat(clonedBuilder).extracting("exchangeFunction").isEqualTo(exchangeFunction); + } + @Test public void withStringAttribute() { Map actual = new HashMap<>();