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 ;
42
44
*/
43
45
final class DefaultWebClientBuilder implements WebClient .Builder {
44
46
47
+ private static final boolean reactorClientPresent ;
48
+
49
+ private static final boolean jettyClientPresent ;
50
+
51
+ static {
52
+ ClassLoader loader = DefaultWebClientBuilder .class .getClassLoader ();
53
+ reactorClientPresent = ClassUtils .isPresent ("reactor.netty.http.client.HttpClient" , loader );
54
+ jettyClientPresent = ClassUtils .isPresent ("org.eclipse.jetty.client.HttpClient" , loader );
55
+ }
56
+
57
+
45
58
@ Nullable
46
59
private String baseUrl ;
47
60
@@ -215,7 +228,9 @@ public WebClient.Builder clone() {
215
228
216
229
@ Override
217
230
public WebClient build () {
218
- ExchangeFunction exchange = initExchangeFunction ();
231
+ ExchangeFunction exchange = (this .exchangeFunction == null ?
232
+ ExchangeFunctions .create (getOrInitConnector (), this .exchangeStrategies ) :
233
+ this .exchangeFunction );
219
234
ExchangeFunction filteredExchange = (this .filters != null ? this .filters .stream ()
220
235
.reduce (ExchangeFilterFunction ::andThen )
221
236
.map (filter -> filter .apply (exchange ))
@@ -226,16 +241,17 @@ public WebClient build() {
226
241
this .defaultRequest , new DefaultWebClientBuilder (this ));
227
242
}
228
243
229
- private ExchangeFunction initExchangeFunction () {
230
- if (this .exchangeFunction != null ) {
231
- return this .exchangeFunction ;
244
+ private ClientHttpConnector getOrInitConnector () {
245
+ if (this .connector != null ) {
246
+ return this .connector ;
232
247
}
233
- else if (this . connector != null ) {
234
- return ExchangeFunctions . create ( this . connector , this . exchangeStrategies );
248
+ else if (reactorClientPresent ) {
249
+ return new ReactorClientHttpConnector ( );
235
250
}
236
- else {
237
- return ExchangeFunctions . create ( new ReactorClientHttpConnector (), this . exchangeStrategies );
251
+ else if ( jettyClientPresent ) {
252
+ return new JettyClientHttpConnector ( );
238
253
}
254
+ throw new IllegalStateException ("No suitable default ClientHttpConnector found" );
239
255
}
240
256
241
257
private UriBuilderFactory initUriBuilderFactory () {
0 commit comments