Add classpath detection for Reactor Netty 2
See gh-28847
This commit is contained in:
@@ -34,6 +34,7 @@ import org.springframework.http.client.reactive.HttpComponentsClientHttpConnecto
|
||||
import org.springframework.http.client.reactive.JdkClientHttpConnector;
|
||||
import org.springframework.http.client.reactive.JettyClientHttpConnector;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.http.client.reactive.ReactorNetty2ClientHttpConnector;
|
||||
import org.springframework.http.codec.ClientCodecConfigurer;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -53,7 +54,9 @@ import org.springframework.web.util.UriBuilderFactory;
|
||||
*/
|
||||
final class DefaultWebClientBuilder implements WebClient.Builder {
|
||||
|
||||
private static final boolean reactorClientPresent;
|
||||
private static final boolean reactorNettyClientPresent;
|
||||
|
||||
private static final boolean reactorNetty2ClientPresent;
|
||||
|
||||
private static final boolean jettyClientPresent;
|
||||
|
||||
@@ -61,7 +64,8 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
|
||||
|
||||
static {
|
||||
ClassLoader loader = DefaultWebClientBuilder.class.getClassLoader();
|
||||
reactorClientPresent = ClassUtils.isPresent("reactor.netty.http.client.HttpClient", loader);
|
||||
reactorNettyClientPresent = ClassUtils.isPresent("reactor.netty.http.client.HttpClient", loader);
|
||||
reactorNetty2ClientPresent = ClassUtils.isPresent("reactor.netty5.http.client.HttpClient", loader);
|
||||
jettyClientPresent = ClassUtils.isPresent("org.eclipse.jetty.client.HttpClient", loader);
|
||||
httpComponentsClientPresent =
|
||||
ClassUtils.isPresent("org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient", loader) &&
|
||||
@@ -306,9 +310,12 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
|
||||
}
|
||||
|
||||
private ClientHttpConnector initConnector() {
|
||||
if (reactorClientPresent) {
|
||||
if (reactorNettyClientPresent) {
|
||||
return new ReactorClientHttpConnector();
|
||||
}
|
||||
else if (reactorNetty2ClientPresent) {
|
||||
return new ReactorNetty2ClientHttpConnector();
|
||||
}
|
||||
else if (jettyClientPresent) {
|
||||
return new JettyClientHttpConnector();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -74,12 +74,15 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle {
|
||||
|
||||
private static final boolean reactorNettyPresent;
|
||||
|
||||
private static final boolean reactorNetty2Present;
|
||||
|
||||
static {
|
||||
ClassLoader loader = HandshakeWebSocketService.class.getClassLoader();
|
||||
tomcatPresent = ClassUtils.isPresent("org.apache.tomcat.websocket.server.WsHttpUpgradeHandler", loader);
|
||||
jettyPresent = ClassUtils.isPresent("org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer", loader);
|
||||
undertowPresent = ClassUtils.isPresent("io.undertow.websockets.WebSocketProtocolHandshakeHandler", loader);
|
||||
reactorNettyPresent = ClassUtils.isPresent("reactor.netty.http.server.HttpServerResponse", loader);
|
||||
reactorNetty2Present = ClassUtils.isPresent("reactor.netty5.http.server.HttpServerResponse", loader);
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +129,10 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle {
|
||||
// As late as possible (Reactor Netty commonly used for WebClient)
|
||||
className = "ReactorNettyRequestUpgradeStrategy";
|
||||
}
|
||||
else if (reactorNetty2Present) {
|
||||
// As late as possible (Reactor Netty commonly used for WebClient)
|
||||
className = "ReactorNetty2RequestUpgradeStrategy";
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("No suitable default RequestUpgradeStrategy found");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user