From f50acf0d044f8d67426df3947542f9e17158bd66 Mon Sep 17 00:00:00 2001 From: zhaoguhong Date: Fri, 17 Apr 2026 14:06:04 +0800 Subject: [PATCH] Fix websocket client spec builder reuse in plugin config --- .../plugin/websocket/WebSocketPluginConfiguration.java | 2 +- .../websocket/WebSocketPluginConfigurationTest.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/main/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/main/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfiguration.java index 2a7fcf36d26e..90f92bc2d348 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/main/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfiguration.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/main/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfiguration.java @@ -78,7 +78,7 @@ public WebSocketPlugin webSocketPlugin(final WebSocketClient webSocketClient, fi @Bean public ReactorNettyWebSocketClient reactorNettyWebSocketClient(final ShenyuConfig shenyuConfig, final ObjectProvider httpClient) { - Supplier builder = WebsocketClientSpec.builder() + Supplier builder = () -> WebsocketClientSpec.builder() .maxFramePayloadLength(shenyuConfig.getWebsocket().getMaxFramePayloadSize() * Constants.BYTES_PER_MB) .handlePing(shenyuConfig.getWebsocket().getEnableProxyPing()); return new ReactorNettyWebSocketClient(httpClient.getIfAvailable(HttpClient::create), builder); diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/test/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfigurationTest.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/test/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfigurationTest.java index e0068d4e2941..ed6fbea3c8fe 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/test/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfigurationTest.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/test/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfigurationTest.java @@ -28,8 +28,12 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Configuration; +import org.springframework.test.util.ReflectionTestUtils; import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient; import org.springframework.web.reactive.socket.server.WebSocketService; +import reactor.netty.http.client.WebsocketClientSpec; + +import java.util.function.Supplier; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -76,6 +80,11 @@ public void testReactorNettyWebSocketClient() { applicationContextRunner.run(context -> { ReactorNettyWebSocketClient client = context.getBean("reactorNettyWebSocketClient", ReactorNettyWebSocketClient.class); assertNotNull(client); + @SuppressWarnings("unchecked") + Supplier builderSupplier = + (Supplier) ReflectionTestUtils.getField(client, "specBuilderSupplier"); + assertNotNull(builderSupplier); + assertThat(builderSupplier.get()).isNotSameAs(builderSupplier.get()); } ); }