Skip to content

Commit

Permalink
Auto-detect Reactor Netty client in RestClient
Browse files Browse the repository at this point in the history
Closes gh-33635
  • Loading branch information
rstoyanchev committed Oct 8, 2024
1 parent a84a41f commit 000b8a6
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.springframework.http.client.InterceptingClientHttpRequestFactory;
import org.springframework.http.client.JdkClientHttpRequestFactory;
import org.springframework.http.client.JettyClientHttpRequestFactory;
import org.springframework.http.client.ReactorClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.client.observation.ClientRequestObservationConvention;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
Expand Down Expand Up @@ -75,6 +76,8 @@ final class DefaultRestClientBuilder implements RestClient.Builder {

private static final boolean jettyClientPresent;

private static final boolean reactorNettyClientPresent;

private static final boolean jdkClientPresent;

// message factories
Expand All @@ -99,6 +102,7 @@ final class DefaultRestClientBuilder implements RestClient.Builder {

httpComponentsClientPresent = ClassUtils.isPresent("org.apache.hc.client5.http.classic.HttpClient", loader);
jettyClientPresent = ClassUtils.isPresent("org.eclipse.jetty.client.HttpClient", loader);
reactorNettyClientPresent = ClassUtils.isPresent("reactor.netty.http.client.HttpClient", loader);
jdkClientPresent = ClassUtils.isPresent("java.net.http.HttpClient", loader);

jackson2Present = ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", loader) &&
Expand Down Expand Up @@ -463,6 +467,9 @@ else if (httpComponentsClientPresent) {
else if (jettyClientPresent) {
return new JettyClientHttpRequestFactory();
}
else if (reactorNettyClientPresent) {
return new ReactorClientHttpRequestFactory();
}
else if (jdkClientPresent) {
// java.net.http module might not be loaded, so we can't default to the JDK HttpClient
return new JdkClientHttpRequestFactory();
Expand Down

0 comments on commit 000b8a6

Please sign in to comment.