Drop server-specific RequestUpgradeStrategy implementations
StandardWebSocketUpgradeStrategy is the common replacement on Tomcat, Undertow and all EE servers. JettyRequestUpgradeStrategy remains the preferred choice on Jetty. Closes gh-33744
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
@@ -20,7 +20,6 @@ import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -34,16 +33,12 @@ import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.socket.client.WebSocketClient;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.server.RequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.jetty.JettyRequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.standard.UndertowRequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.standard.StandardWebSocketUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
@@ -57,11 +52,6 @@ import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
*/
|
||||
public abstract class AbstractWebSocketIntegrationTests {
|
||||
|
||||
private static final Map<Class<?>, Class<?>> upgradeStrategyConfigTypes = Map.of(
|
||||
JettyWebSocketTestServer.class, JettyUpgradeStrategyConfig.class,
|
||||
TomcatWebSocketTestServer.class, TomcatUpgradeStrategyConfig.class,
|
||||
UndertowTestServer.class, UndertowUpgradeStrategyConfig.class);
|
||||
|
||||
static Stream<Arguments> argumentsFactory() {
|
||||
return Stream.of(
|
||||
arguments(named("Jetty", new JettyWebSocketTestServer()), named("Standard", new StandardWebSocketClient())),
|
||||
@@ -104,7 +94,8 @@ public abstract class AbstractWebSocketIntegrationTests {
|
||||
|
||||
this.wac = new AnnotationConfigWebApplicationContext();
|
||||
this.wac.register(getAnnotatedConfigClasses());
|
||||
this.wac.register(upgradeStrategyConfigTypes.get(this.server.getClass()));
|
||||
this.wac.register(this.server instanceof JettyWebSocketTestServer ? JettyHandshakeHandler.class :
|
||||
StandardHandshakeHandler.class);
|
||||
|
||||
if (this.webSocketClient instanceof Lifecycle) {
|
||||
((Lifecycle) this.webSocketClient).start();
|
||||
@@ -164,46 +155,18 @@ public abstract class AbstractWebSocketIntegrationTests {
|
||||
}
|
||||
|
||||
|
||||
abstract static class AbstractRequestUpgradeStrategyConfig {
|
||||
private static class JettyHandshakeHandler extends DefaultHandshakeHandler {
|
||||
|
||||
@Bean
|
||||
public DefaultHandshakeHandler handshakeHandler() {
|
||||
return new DefaultHandshakeHandler(requestUpgradeStrategy());
|
||||
}
|
||||
|
||||
public abstract RequestUpgradeStrategy requestUpgradeStrategy();
|
||||
}
|
||||
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class JettyUpgradeStrategyConfig extends AbstractRequestUpgradeStrategyConfig {
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
public RequestUpgradeStrategy requestUpgradeStrategy() {
|
||||
return new JettyRequestUpgradeStrategy();
|
||||
public JettyHandshakeHandler() {
|
||||
super(new JettyRequestUpgradeStrategy());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class TomcatUpgradeStrategyConfig extends AbstractRequestUpgradeStrategyConfig {
|
||||
private static class StandardHandshakeHandler extends DefaultHandshakeHandler {
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
public RequestUpgradeStrategy requestUpgradeStrategy() {
|
||||
return new TomcatRequestUpgradeStrategy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class UndertowUpgradeStrategyConfig extends AbstractRequestUpgradeStrategyConfig {
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
public RequestUpgradeStrategy requestUpgradeStrategy() {
|
||||
return new UndertowRequestUpgradeStrategy();
|
||||
public StandardHandshakeHandler() {
|
||||
super(new StandardWebSocketUpgradeStrategy());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,15 +18,13 @@ package org.springframework.web.socket;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.glassfish.tyrus.core.TyrusExtension;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.web.socket.adapter.standard.StandardToWebSocketExtensionAdapter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link WebSocketExtension}
|
||||
* Test fixture for {@link WebSocketExtension}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
class WebSocketExtensionTests {
|
||||
@@ -54,11 +52,4 @@ class WebSocketExtensionTests {
|
||||
.containsExactly("x-foo-extension", "x-bar-extension");
|
||||
}
|
||||
|
||||
@Test // gh-26449
|
||||
public void equality() {
|
||||
WebSocketExtension ext1 = new WebSocketExtension("myExtension");
|
||||
WebSocketExtension ext2 = new StandardToWebSocketExtensionAdapter(new TyrusExtension("myExtension"));
|
||||
|
||||
assertThat(ext1).isEqualTo(ext2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,9 +104,9 @@ class WebSocketHandshakeTests extends AbstractWebSocketIntegrationTests {
|
||||
TestWebSocketHandler handler() {
|
||||
return new TestWebSocketHandler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static class TestWebSocketHandler extends AbstractWebSocketHandler {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurationSupport;
|
||||
import org.springframework.web.socket.server.RequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.standard.StandardWebSocketUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -144,7 +144,7 @@ class WebSocketStompClientIntegrationTests {
|
||||
@Override
|
||||
protected void registerStompEndpoints(StompEndpointRegistry registry) {
|
||||
// Can't rely on classpath detection
|
||||
RequestUpgradeStrategy upgradeStrategy = new TomcatRequestUpgradeStrategy();
|
||||
RequestUpgradeStrategy upgradeStrategy = new StandardWebSocketUpgradeStrategy();
|
||||
registry.addEndpoint("/stomp")
|
||||
.setHandshakeHandler(new DefaultHandshakeHandler(upgradeStrategy))
|
||||
.setAllowedOrigins("*");
|
||||
|
||||
@@ -62,6 +62,7 @@ import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import org.springframework.web.socket.server.HandshakeHandler;
|
||||
import org.springframework.web.socket.server.RequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.standard.StandardWebSocketUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -143,7 +144,9 @@ abstract class AbstractSockJsIntegrationTests {
|
||||
}
|
||||
|
||||
|
||||
protected abstract Class<?> upgradeStrategyConfigClass();
|
||||
protected Class<?> upgradeStrategyConfigClass() {
|
||||
return StandardWebSocketUpgradeStrategy.class;
|
||||
}
|
||||
|
||||
protected abstract WebSocketTestServer createWebSocketTestServer();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
@@ -18,24 +18,15 @@ package org.springframework.web.socket.sockjs.client;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.UndertowTestServer;
|
||||
import org.springframework.web.socket.WebSocketTestServer;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.server.RequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.standard.UndertowRequestUpgradeStrategy;
|
||||
|
||||
/**
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
class UndertowSockJsIntegrationTests extends AbstractSockJsIntegrationTests {
|
||||
|
||||
@Override
|
||||
protected Class<?> upgradeStrategyConfigClass() {
|
||||
return UndertowTestConfig.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WebSocketTestServer createWebSocketTestServer() {
|
||||
return new UndertowTestServer();
|
||||
@@ -56,13 +47,4 @@ class UndertowSockJsIntegrationTests extends AbstractSockJsIntegrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class UndertowTestConfig {
|
||||
@Bean
|
||||
RequestUpgradeStrategy upgradeStrategy() {
|
||||
return new UndertowRequestUpgradeStrategy();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user