|
25 | 25 |
|
26 | 26 | import org.springframework.http.HttpHeaders;
|
27 | 27 | import org.springframework.http.client.reactive.ClientHttpConnector;
|
| 28 | +import org.springframework.http.client.reactive.JettyClientHttpConnector; |
28 | 29 | import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
29 | 30 | import org.springframework.lang.Nullable;
|
30 | 31 | import org.springframework.util.Assert;
|
| 32 | +import org.springframework.util.ClassUtils; |
31 | 33 | import org.springframework.util.CollectionUtils;
|
32 | 34 | import org.springframework.util.LinkedMultiValueMap;
|
33 | 35 | import org.springframework.util.MultiValueMap;
|
|
41 | 43 | * @since 5.0
|
42 | 44 | */
|
43 | 45 | final class DefaultWebClientBuilder implements WebClient.Builder {
|
| 46 | + private static final boolean jettyHttpClientPresent; |
| 47 | + |
| 48 | + private static final boolean reactorNettyHttpClientPresent; |
| 49 | + |
| 50 | + static { |
| 51 | + ClassLoader classLoader = DefaultWebClientBuilder.class.getClassLoader(); |
| 52 | + jettyHttpClientPresent = ClassUtils.isPresent( |
| 53 | + "org.eclipse.jetty.client.HttpClient", classLoader); |
| 54 | + reactorNettyHttpClientPresent = ClassUtils.isPresent( |
| 55 | + "reactor.netty.http.client.HttpClient", classLoader); |
| 56 | + } |
44 | 57 |
|
45 | 58 | @Nullable
|
46 | 59 | private String baseUrl;
|
@@ -234,8 +247,18 @@ else if (this.connector != null) {
|
234 | 247 | return ExchangeFunctions.create(this.connector, this.exchangeStrategies);
|
235 | 248 | }
|
236 | 249 | else {
|
237 |
| - return ExchangeFunctions.create(new ReactorClientHttpConnector(), this.exchangeStrategies); |
| 250 | + return ExchangeFunctions.create(createDefaultClientHttpConnector(), this.exchangeStrategies); |
| 251 | + } |
| 252 | + } |
| 253 | + |
| 254 | + private ClientHttpConnector createDefaultClientHttpConnector() { |
| 255 | + if (reactorNettyHttpClientPresent) { |
| 256 | + return new ReactorClientHttpConnector(); |
| 257 | + } |
| 258 | + else if (jettyHttpClientPresent) { |
| 259 | + return new JettyClientHttpConnector(); |
238 | 260 | }
|
| 261 | + throw new IllegalStateException("No suitable default ClientHttpConnector found"); |
239 | 262 | }
|
240 | 263 |
|
241 | 264 | private UriBuilderFactory initUriBuilderFactory() {
|
|
0 commit comments