43
43
* @since 5.0
44
44
*/
45
45
final class DefaultWebClientBuilder implements WebClient .Builder {
46
- private static final boolean jettyHttpClientPresent ;
47
46
48
- private static final boolean reactorNettyHttpClientPresent ;
47
+ private static final boolean reactorClientPresent ;
48
+
49
+ private static final boolean jettyClientPresent ;
49
50
50
51
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 );
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 );
56
55
}
57
56
57
+
58
58
@ Nullable
59
59
private String baseUrl ;
60
60
@@ -228,7 +228,9 @@ public WebClient.Builder clone() {
228
228
229
229
@ Override
230
230
public WebClient build () {
231
- ExchangeFunction exchange = initExchangeFunction ();
231
+ ExchangeFunction exchange = (this .exchangeFunction == null ?
232
+ ExchangeFunctions .create (getOrInitConnector (), this .exchangeStrategies ) :
233
+ this .exchangeFunction );
232
234
ExchangeFunction filteredExchange = (this .filters != null ? this .filters .stream ()
233
235
.reduce (ExchangeFilterFunction ::andThen )
234
236
.map (filter -> filter .apply (exchange ))
@@ -239,23 +241,14 @@ public WebClient build() {
239
241
this .defaultRequest , new DefaultWebClientBuilder (this ));
240
242
}
241
243
242
- private ExchangeFunction initExchangeFunction () {
243
- if (this .exchangeFunction != null ) {
244
- return this .exchangeFunction ;
244
+ private ClientHttpConnector getOrInitConnector () {
245
+ if (this .connector != null ) {
246
+ return this .connector ;
245
247
}
246
- else if (this .connector != null ) {
247
- return ExchangeFunctions .create (this .connector , this .exchangeStrategies );
248
- }
249
- else {
250
- return ExchangeFunctions .create (createDefaultClientHttpConnector (), this .exchangeStrategies );
251
- }
252
- }
253
-
254
- private ClientHttpConnector createDefaultClientHttpConnector () {
255
- if (reactorNettyHttpClientPresent ) {
248
+ else if (reactorClientPresent ) {
256
249
return new ReactorClientHttpConnector ();
257
250
}
258
- else if (jettyHttpClientPresent ) {
251
+ else if (jettyClientPresent ) {
259
252
return new JettyClientHttpConnector ();
260
253
}
261
254
throw new IllegalStateException ("No suitable default ClientHttpConnector found" );
0 commit comments