Skip to content

Commit

Permalink
Apply resources after application HttpClient mapper
Browse files Browse the repository at this point in the history
Closes gh-27749
  • Loading branch information
rstoyanchev committed Dec 2, 2021
1 parent 8b89128 commit 6582787
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -73,18 +73,21 @@ public ReactorClientHttpConnector() {
* @since 5.1
*/
public ReactorClientHttpConnector(ReactorResourceFactory factory, Function<HttpClient, HttpClient> 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<HttpClient, HttpClient> 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
Expand Down

0 comments on commit 6582787

Please sign in to comment.