diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java index 8112ecf644..0fdfaab691 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 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. @@ -73,18 +73,21 @@ public class ReactorClientHttpConnector implements ClientHttpConnector { * @since 5.1 */ public ReactorClientHttpConnector(ReactorResourceFactory factory, Function mapper) { - this.httpClient = defaultInitializer.andThen(mapper).apply(initHttpClient(factory)); + ConnectionProvider provider = factory.getConnectionProvider(); + Assert.notNull(provider, "No ConnectionProvider: is ReactorResourceFactory not initialized yet?"); + this.httpClient = defaultInitializer.andThen(mapper).andThen(applyLoopResources(factory)) + .apply(HttpClient.create(provider)); } - @SuppressWarnings("deprecation") - private static HttpClient initHttpClient(ReactorResourceFactory resourceFactory) { - ConnectionProvider provider = resourceFactory.getConnectionProvider(); - LoopResources resources = resourceFactory.getLoopResources(); - Assert.notNull(provider, "No ConnectionProvider: is ReactorResourceFactory not initialized yet?"); - Assert.notNull(resources, "No LoopResources: is ReactorResourceFactory not initialized yet?"); - return HttpClient.create(provider).tcpConfiguration(tcpClient -> tcpClient.runOn(resources)); + private static Function applyLoopResources(ReactorResourceFactory factory) { + return httpClient -> { + LoopResources resources = factory.getLoopResources(); + Assert.notNull(resources, "No LoopResources: is ReactorResourceFactory not initialized yet?"); + return httpClient.runOn(resources); + }; } + /** * Constructor with a pre-configured {@code HttpClient} instance. * @param httpClient the client to use diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java index 7e8219c167..9097000ccc 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java @@ -530,7 +530,7 @@ public interface WebClient { * return response.bodyToMono(ErrorContainer.class); * } * else { - * return Mono.error(response.createException()); + * return response.createException(); * } * }); * @@ -562,7 +562,7 @@ public interface WebClient { * return response.bodyToMono(ErrorContainer.class).flux(); * } * else { - * return Flux.error(response.createException()); + * return response.createException().flux(); * } * }); * diff --git a/src/docs/asciidoc/web/webflux-webclient.adoc b/src/docs/asciidoc/web/webflux-webclient.adoc index b0b8e4a951..f1c94a5875 100644 --- a/src/docs/asciidoc/web/webflux-webclient.adoc +++ b/src/docs/asciidoc/web/webflux-webclient.adoc @@ -595,7 +595,7 @@ depending on the response status: } else { // Turn to error - return response.createException().flatMap(Mono::error); + return response.createException(); } }); ----