Remove Netty 5 support

Closes gh-34345
This commit is contained in:
rstoyanchev
2025-02-11 12:27:33 +00:00
parent bae12e739d
commit e9d16da633
51 changed files with 48 additions and 4052 deletions

View File

@@ -36,7 +36,6 @@ 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.util.Assert;
import org.springframework.util.ClassUtils;
@@ -57,8 +56,6 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
private static final boolean reactorNettyClientPresent;
private static final boolean reactorNetty2ClientPresent;
private static final boolean jettyClientPresent;
private static final boolean httpComponentsClientPresent;
@@ -66,7 +63,6 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
static {
ClassLoader loader = DefaultWebClientBuilder.class.getClassLoader();
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) &&
@@ -311,9 +307,6 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
if (reactorNettyClientPresent) {
return new ReactorClientHttpConnector();
}
else if (reactorNetty2ClientPresent) {
return new ReactorNetty2ClientHttpConnector();
}
else if (jettyClientPresent) {
return new JettyClientHttpConnector();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@@ -23,9 +23,7 @@ import org.jspecify.annotations.Nullable;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.Netty5DataBufferFactory;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
/**
@@ -39,10 +37,6 @@ import org.springframework.util.ObjectUtils;
*/
public class WebSocketMessage {
private static final boolean reactorNetty2Present = ClassUtils.isPresent(
"io.netty5.handler.codec.http.websocketx.WebSocketFrame", WebSocketMessage.class.getClassLoader());
private final Type type;
private final DataBuffer payload;
@@ -133,9 +127,6 @@ public class WebSocketMessage {
* @see DataBufferUtils#retain(DataBuffer)
*/
public WebSocketMessage retain() {
if (reactorNetty2Present) {
return ReactorNetty2Helper.retain(this);
}
DataBufferUtils.retain(this.payload);
return this;
}
@@ -194,20 +185,4 @@ public class WebSocketMessage {
PONG
}
private static class ReactorNetty2Helper {
static WebSocketMessage retain(WebSocketMessage message) {
if (message.nativeMessage instanceof io.netty5.handler.codec.http.websocketx.WebSocketFrame netty5Frame) {
io.netty5.handler.codec.http.websocketx.WebSocketFrame frame = netty5Frame.send().receive();
DataBuffer payload = ((Netty5DataBufferFactory) message.payload.factory()).wrap(frame.binaryData());
return new WebSocketMessage(message.type, payload, frame);
}
else {
DataBufferUtils.retain(message.payload);
return message;
}
}
}
}

View File

@@ -1,107 +0,0 @@
/*
* 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.socket.adapter;
import java.util.HashMap;
import java.util.Map;
import io.netty5.buffer.Buffer;
import io.netty5.handler.codec.http.websocketx.BinaryWebSocketFrame;
import io.netty5.handler.codec.http.websocketx.PingWebSocketFrame;
import io.netty5.handler.codec.http.websocketx.PongWebSocketFrame;
import io.netty5.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty5.handler.codec.http.websocketx.WebSocketFrame;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.Netty5DataBufferFactory;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.web.reactive.socket.HandshakeInfo;
import org.springframework.web.reactive.socket.WebSocketMessage;
import org.springframework.web.reactive.socket.WebSocketSession;
/**
* Base class for Netty-based {@link WebSocketSession} adapters that provides
* convenience methods to convert Netty {@link WebSocketFrame WebSocketFrames} to and from
* {@link WebSocketMessage WebSocketMessages}.
*
* <p>This class is based on {@link NettyWebSocketSessionSupport}.
*
* @author Violeta Georgieva
* @since 6.0
* @param <T> the native delegate type
*/
public abstract class Netty5WebSocketSessionSupport<T> extends AbstractWebSocketSession<T> {
/**
* The default max size for inbound WebSocket frames.
*/
public static final int DEFAULT_FRAME_MAX_SIZE = 64 * 1024;
private static final Map<Class<?>, WebSocketMessage.Type> messageTypes;
static {
messageTypes = new HashMap<>(8);
messageTypes.put(TextWebSocketFrame.class, WebSocketMessage.Type.TEXT);
messageTypes.put(BinaryWebSocketFrame.class, WebSocketMessage.Type.BINARY);
messageTypes.put(PingWebSocketFrame.class, WebSocketMessage.Type.PING);
messageTypes.put(PongWebSocketFrame.class, WebSocketMessage.Type.PONG);
}
protected Netty5WebSocketSessionSupport(T delegate, HandshakeInfo info, Netty5DataBufferFactory factory) {
super(delegate, ObjectUtils.getIdentityHexString(delegate), info, factory);
}
@Override
public Netty5DataBufferFactory bufferFactory() {
return (Netty5DataBufferFactory) super.bufferFactory();
}
protected WebSocketMessage toMessage(WebSocketFrame frame) {
DataBuffer payload = bufferFactory().wrap(frame.binaryData());
WebSocketMessage.Type messageType = messageTypes.get(frame.getClass());
Assert.state(messageType != null, "Unexpected message type");
return new WebSocketMessage(messageType, payload, frame);
}
protected WebSocketFrame toFrame(WebSocketMessage message) {
if (message.getNativeMessage() != null) {
return message.getNativeMessage();
}
Buffer buffer = Netty5DataBufferFactory.toBuffer(message.getPayload());
if (WebSocketMessage.Type.TEXT.equals(message.getType())) {
return new TextWebSocketFrame(buffer);
}
else if (WebSocketMessage.Type.BINARY.equals(message.getType())) {
return new BinaryWebSocketFrame(buffer);
}
else if (WebSocketMessage.Type.PING.equals(message.getType())) {
return new PingWebSocketFrame(buffer);
}
else if (WebSocketMessage.Type.PONG.equals(message.getType())) {
return new PongWebSocketFrame(buffer);
}
else {
throw new IllegalArgumentException("Unexpected message type: " + message.getType());
}
}
}

View File

@@ -1,173 +0,0 @@
/*
* 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.socket.adapter;
import java.util.function.Consumer;
import io.netty5.channel.ChannelId;
import io.netty5.handler.codec.http.websocketx.WebSocketFrame;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.netty5.Connection;
import reactor.netty5.NettyInbound;
import reactor.netty5.NettyOutbound;
import reactor.netty5.channel.ChannelOperations;
import reactor.netty5.http.websocket.WebsocketInbound;
import reactor.netty5.http.websocket.WebsocketOutbound;
import org.springframework.core.io.buffer.Netty5DataBufferFactory;
import org.springframework.web.reactive.socket.CloseStatus;
import org.springframework.web.reactive.socket.HandshakeInfo;
import org.springframework.web.reactive.socket.WebSocketMessage;
import org.springframework.web.reactive.socket.WebSocketSession;
/**
* {@link WebSocketSession} implementation for use with the Reactor Netty's (Netty 5)
* {@link NettyInbound} and {@link NettyOutbound}.
* This class is based on {@link ReactorNettyWebSocketSession}.
*
* @author Violeta Georgieva
* @since 6.0
*/
public class ReactorNetty2WebSocketSession
extends Netty5WebSocketSessionSupport<ReactorNetty2WebSocketSession.WebSocketConnection> {
private final int maxFramePayloadLength;
private final ChannelId channelId;
/**
* Constructor for the session, using the {@link #DEFAULT_FRAME_MAX_SIZE} value.
*/
public ReactorNetty2WebSocketSession(WebsocketInbound inbound, WebsocketOutbound outbound,
HandshakeInfo info, Netty5DataBufferFactory bufferFactory) {
this(inbound, outbound, info, bufferFactory, DEFAULT_FRAME_MAX_SIZE);
}
/**
* Constructor with an additional maxFramePayloadLength argument.
* @since 5.1
*/
@SuppressWarnings("rawtypes")
public ReactorNetty2WebSocketSession(WebsocketInbound inbound, WebsocketOutbound outbound,
HandshakeInfo info, Netty5DataBufferFactory bufferFactory,
int maxFramePayloadLength) {
super(new WebSocketConnection(inbound, outbound), info, bufferFactory);
this.maxFramePayloadLength = maxFramePayloadLength;
this.channelId = ((ChannelOperations) inbound).channel().id();
}
/**
* Return the id of the underlying Netty channel.
* @since 5.3.4
*/
public ChannelId getChannelId() {
return this.channelId;
}
@Override
public Flux<WebSocketMessage> receive() {
return getDelegate().getInbound()
.aggregateFrames(this.maxFramePayloadLength)
.receiveFrames()
.map(super::toMessage)
.doOnNext(message -> {
if (logger.isTraceEnabled()) {
logger.trace(getLogPrefix() + "Received " + message);
}
});
}
@Override
public Mono<Void> send(Publisher<WebSocketMessage> messages) {
Flux<WebSocketFrame> frames = Flux.from(messages)
.doOnNext(message -> {
if (logger.isTraceEnabled()) {
logger.trace(getLogPrefix() + "Sending " + message);
}
})
.map(this::toFrame);
return getDelegate().getOutbound()
.sendObject(frames)
.then();
}
@Override
public boolean isOpen() {
DisposedCallback callback = new DisposedCallback();
getDelegate().getInbound().withConnection(callback);
return !callback.isDisposed();
}
@Override
public Mono<Void> close(CloseStatus status) {
// this will notify WebSocketInbound.receiveCloseStatus()
return getDelegate().getOutbound().sendClose(status.getCode(), status.getReason());
}
@Override
public Mono<CloseStatus> closeStatus() {
return getDelegate().getInbound().receiveCloseStatus()
.map(status -> CloseStatus.create(status.code(), status.reasonText()));
}
/**
* Simple container for {@link NettyInbound} and {@link NettyOutbound}.
*/
public static class WebSocketConnection {
private final WebsocketInbound inbound;
private final WebsocketOutbound outbound;
public WebSocketConnection(WebsocketInbound inbound, WebsocketOutbound outbound) {
this.inbound = inbound;
this.outbound = outbound;
}
public WebsocketInbound getInbound() {
return this.inbound;
}
public WebsocketOutbound getOutbound() {
return this.outbound;
}
}
private static class DisposedCallback implements Consumer<Connection> {
private boolean disposed;
public boolean isDisposed() {
return this.disposed;
}
@Override
public void accept(Connection connection) {
this.disposed = connection.isDisposed();
}
}
}

View File

@@ -1,159 +0,0 @@
/*
* 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.socket.client;
import java.net.URI;
import java.util.function.Supplier;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import reactor.netty5.http.client.HttpClient;
import reactor.netty5.http.client.WebsocketClientSpec;
import reactor.netty5.http.websocket.WebsocketInbound;
import org.springframework.core.io.buffer.Netty5DataBufferFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.reactive.socket.HandshakeInfo;
import org.springframework.web.reactive.socket.WebSocketHandler;
import org.springframework.web.reactive.socket.WebSocketSession;
import org.springframework.web.reactive.socket.adapter.ReactorNetty2WebSocketSession;
/**
* {@link WebSocketClient} implementation for use with Reactor Netty for Netty 5.
*
* <p>This class is based on {@link ReactorNettyWebSocketClient}.
*
* @author Violeta Georgieva
* @since 6.0
*/
public class ReactorNetty2WebSocketClient implements WebSocketClient {
private static final Log logger = LogFactory.getLog(ReactorNetty2WebSocketClient.class);
private final HttpClient httpClient;
private final Supplier<WebsocketClientSpec.Builder> specBuilderSupplier;
private @Nullable Boolean handlePing;
/**
* Default constructor.
*/
public ReactorNetty2WebSocketClient() {
this(HttpClient.create());
}
/**
* Constructor that accepts an existing {@link HttpClient} builder
* with a default {@link WebsocketClientSpec.Builder}.
* @since 5.1
*/
public ReactorNetty2WebSocketClient(HttpClient httpClient) {
this(httpClient, WebsocketClientSpec.builder());
}
/**
* Constructor that accepts an existing {@link HttpClient} builder
* and a pre-configured {@link WebsocketClientSpec.Builder}.
*/
public ReactorNetty2WebSocketClient(
HttpClient httpClient, Supplier<WebsocketClientSpec.Builder> builderSupplier) {
Assert.notNull(httpClient, "HttpClient is required");
Assert.notNull(builderSupplier, "WebsocketClientSpec.Builder is required");
this.httpClient = httpClient;
this.specBuilderSupplier = builderSupplier;
}
/**
* Return the configured {@link HttpClient}.
*/
public HttpClient getHttpClient() {
return this.httpClient;
}
/**
* Build an instance of {@code WebsocketClientSpec} that reflects the current
* configuration. This can be used to check the configured parameters except
* for sub-protocols which depend on the {@link WebSocketHandler} that is used
* for a given upgrade.
*/
public WebsocketClientSpec getWebsocketClientSpec() {
return buildSpec(null);
}
private WebsocketClientSpec buildSpec(@Nullable String protocols) {
WebsocketClientSpec.Builder builder = this.specBuilderSupplier.get();
if (StringUtils.hasText(protocols)) {
builder.protocols(protocols);
}
return builder.build();
}
@Override
public Mono<Void> execute(URI url, WebSocketHandler handler) {
return execute(url, new HttpHeaders(), handler);
}
@Override
public Mono<Void> execute(URI url, HttpHeaders requestHeaders, WebSocketHandler handler) {
String protocols = StringUtils.collectionToCommaDelimitedString(handler.getSubProtocols());
WebsocketClientSpec clientSpec = buildSpec(protocols);
return getHttpClient()
.headers(nettyHeaders -> setNettyHeaders(requestHeaders, nettyHeaders))
.websocket(clientSpec)
.uri(url.toString())
.handle((inbound, outbound) -> {
HttpHeaders responseHeaders = toHttpHeaders(inbound);
String protocol = responseHeaders.getFirst("Sec-WebSocket-Protocol");
HandshakeInfo info = new HandshakeInfo(url, responseHeaders, Mono.empty(), protocol);
Netty5DataBufferFactory factory = new Netty5DataBufferFactory(outbound.alloc());
WebSocketSession session = new ReactorNetty2WebSocketSession(
inbound, outbound, info, factory, clientSpec.maxFramePayloadLength());
if (logger.isDebugEnabled()) {
logger.debug("Started session '" + session.getId() + "' for " + url);
}
return handler.handle(session).checkpoint(url + " [ReactorNetty2WebSocketClient]");
})
.doOnRequest(n -> {
if (logger.isDebugEnabled()) {
logger.debug("Connecting to " + url);
}
})
.next();
}
private void setNettyHeaders(HttpHeaders httpHeaders, io.netty5.handler.codec.http.headers.HttpHeaders nettyHeaders) {
httpHeaders.forEach(nettyHeaders::set);
}
private HttpHeaders toHttpHeaders(WebsocketInbound inbound) {
HttpHeaders headers = new HttpHeaders();
inbound.headers().iterator().forEachRemaining(entry ->
headers.add(entry.getKey().toString(), entry.getValue().toString()));
return headers;
}
}

View File

@@ -46,7 +46,6 @@ import org.springframework.web.reactive.socket.server.RequestUpgradeStrategy;
import org.springframework.web.reactive.socket.server.WebSocketService;
import org.springframework.web.reactive.socket.server.upgrade.JettyCoreRequestUpgradeStrategy;
import org.springframework.web.reactive.socket.server.upgrade.JettyRequestUpgradeStrategy;
import org.springframework.web.reactive.socket.server.upgrade.ReactorNetty2RequestUpgradeStrategy;
import org.springframework.web.reactive.socket.server.upgrade.ReactorNettyRequestUpgradeStrategy;
import org.springframework.web.reactive.socket.server.upgrade.StandardWebSocketUpgradeStrategy;
import org.springframework.web.reactive.socket.server.upgrade.UndertowRequestUpgradeStrategy;
@@ -84,8 +83,6 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle {
private static final boolean reactorNettyPresent;
private static final boolean reactorNetty2Present;
static {
ClassLoader classLoader = HandshakeWebSocketService.class.getClassLoader();
jettyWsPresent = ClassUtils.isPresent(
@@ -96,8 +93,6 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle {
"io.undertow.websockets.WebSocketProtocolHandshakeHandler", classLoader);
reactorNettyPresent = ClassUtils.isPresent(
"reactor.netty.http.server.HttpServerResponse", classLoader);
reactorNetty2Present = ClassUtils.isPresent(
"reactor.netty5.http.server.HttpServerResponse", classLoader);
}
@@ -285,12 +280,7 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle {
return new UndertowRequestUpgradeStrategy();
}
else if (reactorNettyPresent) {
// As late as possible (Reactor Netty commonly used for WebClient)
return ReactorNettyStrategyDelegate.forReactorNetty1();
}
else if (reactorNetty2Present) {
// As late as possible (Reactor Netty commonly used for WebClient)
return ReactorNettyStrategyDelegate.forReactorNetty2();
return new ReactorNettyRequestUpgradeStrategy();
}
else {
// Let's assume Jakarta WebSocket API 2.1+
@@ -298,19 +288,4 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle {
}
}
/**
* Inner class to avoid a reachable dependency on Reactor Netty API.
*/
private static class ReactorNettyStrategyDelegate {
public static RequestUpgradeStrategy forReactorNetty1() {
return new ReactorNettyRequestUpgradeStrategy();
}
public static RequestUpgradeStrategy forReactorNetty2() {
return new ReactorNetty2RequestUpgradeStrategy();
}
}
}

View File

@@ -1,113 +0,0 @@
/*
* Copyright 2002-2023 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.socket.server.upgrade;
import java.net.URI;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import reactor.netty5.http.server.HttpServerResponse;
import reactor.netty5.http.server.WebsocketServerSpec;
import org.springframework.core.io.buffer.Netty5DataBufferFactory;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.http.server.reactive.ServerHttpResponseDecorator;
import org.springframework.util.Assert;
import org.springframework.web.reactive.socket.HandshakeInfo;
import org.springframework.web.reactive.socket.WebSocketHandler;
import org.springframework.web.reactive.socket.adapter.ReactorNetty2WebSocketSession;
import org.springframework.web.reactive.socket.server.RequestUpgradeStrategy;
import org.springframework.web.server.ServerWebExchange;
/**
* A WebSocket {@code RequestUpgradeStrategy} for Reactor Netty for Netty 5.
*
* <p>This class is based on {@link ReactorNettyRequestUpgradeStrategy}.
*
* @author Violeta Georgieva
* @since 6.0
*/
public class ReactorNetty2RequestUpgradeStrategy implements RequestUpgradeStrategy {
private final Supplier<WebsocketServerSpec.Builder> specBuilderSupplier;
/**
* Create an instances with a default {@link WebsocketServerSpec.Builder}.
* @since 5.2.6
*/
public ReactorNetty2RequestUpgradeStrategy() {
this(WebsocketServerSpec::builder);
}
/**
* Create an instance with a pre-configured {@link WebsocketServerSpec.Builder}
* to use for WebSocket upgrades.
* @since 5.2.6
*/
public ReactorNetty2RequestUpgradeStrategy(Supplier<WebsocketServerSpec.Builder> builderSupplier) {
Assert.notNull(builderSupplier, "WebsocketServerSpec.Builder is required");
this.specBuilderSupplier = builderSupplier;
}
/**
* Build an instance of {@code WebsocketServerSpec} that reflects the current
* configuration. This can be used to check the configured parameters except
* for sub-protocols which depend on the {@link WebSocketHandler} that is used
* for a given upgrade.
* @since 5.2.6
*/
public WebsocketServerSpec getWebsocketServerSpec() {
return buildSpec(null);
}
WebsocketServerSpec buildSpec(@Nullable String subProtocol) {
WebsocketServerSpec.Builder builder = this.specBuilderSupplier.get();
if (subProtocol != null) {
builder.protocols(subProtocol);
}
return builder.build();
}
@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler,
@Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory) {
ServerHttpResponse response = exchange.getResponse();
HttpServerResponse reactorResponse = ServerHttpResponseDecorator.getNativeResponse(response);
HandshakeInfo handshakeInfo = handshakeInfoFactory.get();
Netty5DataBufferFactory bufferFactory = (Netty5DataBufferFactory) response.bufferFactory();
URI uri = exchange.getRequest().getURI();
// Trigger WebFlux preCommit actions and upgrade
return response.setComplete()
.then(Mono.defer(() -> {
WebsocketServerSpec spec = buildSpec(subProtocol);
return reactorResponse.sendWebsocket((in, out) -> {
ReactorNetty2WebSocketSession session =
new ReactorNetty2WebSocketSession(
in, out, handshakeInfo, bufferFactory, spec.maxFramePayloadLength());
return handler.handle(session).checkpoint(uri + " [ReactorNetty2RequestUpgradeStrategy]");
}, spec);
}));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -116,7 +116,7 @@ public class DelegatingWebFluxConfigurationTests {
boolean condition = initializer.getValidator() instanceof LocalValidatorFactoryBean;
assertThat(condition).isTrue();
assertThat(initializer.getConversionService()).isSameAs(formatterRegistry.getValue());
assertThat(codecsConfigurer.getValue().getReaders()).hasSize(17);
assertThat(codecsConfigurer.getValue().getReaders()).hasSize(16);
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -114,7 +114,7 @@ class WebFluxConfigurationSupportTests {
assertThat(adapter).isNotNull();
List<HttpMessageReader<?>> readers = adapter.getMessageReaders();
assertThat(readers).hasSize(17);
assertThat(readers).hasSize(16);
ResolvableType multiValueMapType = forClassWithGenerics(MultiValueMap.class, String.class, String.class);
@@ -169,7 +169,7 @@ class WebFluxConfigurationSupportTests {
assertThat(handler.getOrder()).isEqualTo(0);
List<HttpMessageWriter<?>> writers = handler.getMessageWriters();
assertThat(writers).hasSize(17);
assertThat(writers).hasSize(16);
assertHasMessageWriter(writers, forClass(byte[].class), APPLICATION_OCTET_STREAM);
assertHasMessageWriter(writers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM);
@@ -197,7 +197,7 @@ class WebFluxConfigurationSupportTests {
assertThat(handler.getOrder()).isEqualTo(100);
List<HttpMessageWriter<?>> writers = handler.getMessageWriters();
assertThat(writers).hasSize(17);
assertThat(writers).hasSize(16);
assertHasMessageWriter(writers, forClass(byte[].class), APPLICATION_OCTET_STREAM);
assertHasMessageWriter(writers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM);

View File

@@ -77,7 +77,6 @@ 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.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.client.WebClient.ResponseSpec;
import org.springframework.web.testfixture.xml.Pojo;
@@ -107,7 +106,6 @@ class WebClientIntegrationTests {
static Stream<Arguments> arguments() {
return Stream.of(
argumentSet("Reactor Netty", new ReactorClientHttpConnector()),
argumentSet("Reactor Netty 2", new ReactorNetty2ClientHttpConnector()),
argumentSet("JDK", new JdkClientHttpConnector()),
argumentSet("Jetty", new JettyClientHttpConnector()),
argumentSet("HttpComponents", new HttpComponentsClientHttpConnector())
@@ -204,9 +202,6 @@ class WebClientIntegrationTests {
if (clientHttpRequest instanceof ChannelOperations<?,?> nettyReq) {
nativeRequest.set(nettyReq.channel().attr(ReactorClientHttpConnector.ATTRIBUTES_KEY));
}
else if (clientHttpRequest instanceof reactor.netty5.channel.ChannelOperations<?,?> nettyReq) {
nativeRequest.set(nettyReq.channel().attr(ReactorNetty2ClientHttpConnector.ATTRIBUTES_KEY));
}
else {
nativeRequest.set(clientHttpRequest.getNativeRequest());
}
@@ -222,13 +217,6 @@ class WebClientIntegrationTests {
assertThat(attributes.get()).isNotNull();
assertThat(attributes.get()).containsEntry("foo", "bar");
}
else if (nativeRequest.get() instanceof io.netty5.util.Attribute<?>) {
@SuppressWarnings("unchecked")
io.netty5.util.Attribute<Map<String, Object>> attributes =
(io.netty5.util.Attribute<Map<String, Object>>) nativeRequest.get();
assertThat(attributes.get()).isNotNull();
assertThat(attributes.get()).containsEntry("foo", "bar");
}
else if (nativeRequest.get() instanceof Request nativeReq) {
assertThat(nativeReq.getAttributes()).containsEntry("foo", "bar");
}
@@ -946,11 +934,6 @@ class WebClientIntegrationTests {
@ParameterizedWebClientTest
void statusHandlerSuppressedErrorSignalWithFlux(ClientHttpConnector connector) {
// Temporarily disabled, leads to io.netty5.buffer.BufferClosedException
if (connector instanceof ReactorNetty2ClientHttpConnector) {
return;
}
startServer(connector);
prepareResponse(response -> response.setResponseCode(500)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -58,7 +58,6 @@ import org.springframework.web.reactive.socket.server.support.HandshakeWebSocket
import org.springframework.web.reactive.socket.server.support.WebSocketHandlerAdapter;
import org.springframework.web.reactive.socket.server.upgrade.JettyCoreRequestUpgradeStrategy;
import org.springframework.web.reactive.socket.server.upgrade.JettyRequestUpgradeStrategy;
import org.springframework.web.reactive.socket.server.upgrade.ReactorNetty2RequestUpgradeStrategy;
import org.springframework.web.reactive.socket.server.upgrade.ReactorNettyRequestUpgradeStrategy;
import org.springframework.web.reactive.socket.server.upgrade.StandardWebSocketUpgradeStrategy;
import org.springframework.web.reactive.socket.server.upgrade.UndertowRequestUpgradeStrategy;
@@ -244,16 +243,6 @@ abstract class AbstractReactiveWebSocketIntegrationTests {
}
@Configuration
static class ReactorNetty2Config extends AbstractHandlerAdapterConfig {
@Override
protected RequestUpgradeStrategy getUpgradeStrategy() {
return new ReactorNetty2RequestUpgradeStrategy();
}
}
@Configuration
static class UndertowConfig extends AbstractHandlerAdapterConfig {