From 1f1f222b8bd84616ebbcdeaaaf19a8c438f37b11 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Wed, 13 Sep 2023 12:05:09 +0100 Subject: [PATCH] Partial revert of 1f8913a9 For WebFlux we can't use ServletContextAware. See gh-30344 --- .../support/HandshakeWebSocketService.java | 11 +------- .../support/WebSocketHandlerAdapter.java | 11 +------- .../upgrade/JettyRequestUpgradeStrategy.java | 28 +------------------ 3 files changed, 3 insertions(+), 47 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java index 68b7f3ca75..7392a8c188 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java @@ -25,7 +25,6 @@ import java.util.Map; import java.util.function.Predicate; import java.util.stream.Collectors; -import jakarta.servlet.ServletContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import reactor.core.publisher.Mono; @@ -40,7 +39,6 @@ import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; -import org.springframework.web.context.ServletContextAware; import org.springframework.web.reactive.socket.HandshakeInfo; import org.springframework.web.reactive.socket.WebSocketHandler; import org.springframework.web.reactive.socket.server.RequestUpgradeStrategy; @@ -65,7 +63,7 @@ import org.springframework.web.server.ServerWebInputException; * @author Juergen Hoeller * @since 5.0 */ -public class HandshakeWebSocketService implements WebSocketService, ServletContextAware, Lifecycle { +public class HandshakeWebSocketService implements WebSocketService, Lifecycle { private static final String SEC_WEBSOCKET_KEY = "Sec-WebSocket-Key"; @@ -157,13 +155,6 @@ public class HandshakeWebSocketService implements WebSocketService, ServletConte return this.sessionAttributePredicate; } - @Override - public void setServletContext(ServletContext servletContext) { - if (getUpgradeStrategy() instanceof ServletContextAware servletContextAware) { - servletContextAware.setServletContext(servletContext); - } - } - @Override public void start() { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/WebSocketHandlerAdapter.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/WebSocketHandlerAdapter.java index b79bbd0f47..fad77e3c14 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/WebSocketHandlerAdapter.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/WebSocketHandlerAdapter.java @@ -16,13 +16,11 @@ package org.springframework.web.reactive.socket.server.support; -import jakarta.servlet.ServletContext; import reactor.core.publisher.Mono; import org.springframework.context.annotation.ImportRuntimeHints; import org.springframework.core.Ordered; import org.springframework.util.Assert; -import org.springframework.web.context.ServletContextAware; import org.springframework.web.reactive.HandlerAdapter; import org.springframework.web.reactive.HandlerResult; import org.springframework.web.reactive.socket.WebSocketHandler; @@ -49,7 +47,7 @@ import org.springframework.web.server.ServerWebExchange; * @since 5.0 */ @ImportRuntimeHints(HandshakeWebSocketServiceRuntimeHints.class) -public class WebSocketHandlerAdapter implements HandlerAdapter, ServletContextAware, Ordered { +public class WebSocketHandlerAdapter implements HandlerAdapter, Ordered { private final WebSocketService webSocketService; @@ -99,13 +97,6 @@ public class WebSocketHandlerAdapter implements HandlerAdapter, ServletContextAw return this.webSocketService; } - @Override - public void setServletContext(ServletContext servletContext) { - if (this.webSocketService instanceof ServletContextAware servletContextAware) { - servletContextAware.setServletContext(servletContext); - } - } - @Override public boolean supports(Object handler) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyRequestUpgradeStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyRequestUpgradeStrategy.java index 94a1db672b..dbb14bc52c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyRequestUpgradeStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyRequestUpgradeStrategy.java @@ -16,7 +16,6 @@ package org.springframework.web.reactive.socket.server.upgrade; -import java.util.function.Consumer; import java.util.function.Supplier; import jakarta.servlet.ServletContext; @@ -24,7 +23,6 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.eclipse.jetty.ee10.websocket.server.JettyWebSocketCreator; import org.eclipse.jetty.ee10.websocket.server.JettyWebSocketServerContainer; -import org.eclipse.jetty.websocket.api.Configurable; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBufferFactory; @@ -33,7 +31,6 @@ import org.springframework.http.server.reactive.ServerHttpRequestDecorator; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponseDecorator; import org.springframework.lang.Nullable; -import org.springframework.web.context.ServletContextAware; import org.springframework.web.reactive.socket.HandshakeInfo; import org.springframework.web.reactive.socket.WebSocketHandler; import org.springframework.web.reactive.socket.adapter.ContextWebSocketHandler; @@ -48,30 +45,7 @@ import org.springframework.web.server.ServerWebExchange; * @author Rossen Stoyanchev * @since 5.3.4 */ -public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy, ServletContextAware { - - @Nullable - private Consumer webSocketConfigurer; - - - /** - * Add a callback to configure WebSocket server parameters on - * {@link JettyWebSocketServerContainer}. - * @since 6.1.0 - */ - public void addWebSocketConfigurer(Consumer webSocketConfigurer) { - this.webSocketConfigurer = (this.webSocketConfigurer != null ? - this.webSocketConfigurer.andThen(webSocketConfigurer) : webSocketConfigurer); - } - - @Override - public void setServletContext(ServletContext servletContext) { - JettyWebSocketServerContainer container = JettyWebSocketServerContainer.getContainer(servletContext); - if (container != null && this.webSocketConfigurer != null) { - this.webSocketConfigurer.accept(container); - } - } - +public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy { @Override public Mono upgrade(