This is an automated email from the ASF dual-hosted git repository.
Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new ce5cc09a49 fix: honor the enabled attribute when registering websocket
client metadata (#6665) (#7171)
ce5cc09a49 is described below
commit ce5cc09a49c4ceaa50742112cac54d75ee5e3c28
Author: wy471x <[email protected]>
AuthorDate: Sat Sep 26 18:15:50 2026 +0800
fix: honor the enabled attribute when registering websocket client metadata
(#6665) (#7171)
Co-authored-by: aias00 <[email protected]>
---
.../init/SpringWebSocketClientEventListener.java | 2 +-
.../SpringWebSocketClientEventListenerTest.java | 23 ++++++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git
a/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListener.java
b/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListener.java
index efe0829244..1461ff7c0b 100644
---
a/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListener.java
+++
b/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListener.java
@@ -237,7 +237,7 @@ public class SpringWebSocketClientEventListener extends
AbstractContextRefreshed
.appName(getAppName())
.path(UriComponentsBuilder.fromUriString(PathUtils.decoratorPathWithSlash(getContextPath())).build().encode().toUriString())
.rpcType(RpcTypeEnum.WEB_SOCKET.getName())
- .enabled(true)
+ .enabled(webSocketClient.enabled())
.ruleName(StringUtils.defaultIfBlank(webSocketClient.ruleName(),
getContextPath()))
.namespaceId(namespaceId)
.build();
diff --git
a/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/test/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListenerTest.java
b/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/test/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListenerTest.java
index f9f52f3f78..9f973b28f5 100644
---
a/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/test/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListenerTest.java
+++
b/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/test/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListenerTest.java
@@ -37,6 +37,7 @@ import org.mockito.MockedStatic;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.util.ReflectionUtils;
import java.lang.annotation.Annotation;
@@ -47,8 +48,10 @@ import java.util.Map;
import java.util.Properties;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
@@ -161,6 +164,17 @@ public class SpringWebSocketClientEventListenerTest {
assertNotNull(metaDataRegisterDTO);
}
+ @Test
+ public void testBuildMetaDataDTOShouldRespectEnabledAttribute() throws
NoSuchMethodException {
+ Method method = MockClass.class.getDeclaredMethod("mockMethod");
+ ShenyuSpringWebSocketClient enabledClient =
AnnotatedElementUtils.findMergedAnnotation(MockClass.class,
ShenyuSpringWebSocketClient.class);
+ ShenyuSpringWebSocketClient disabledClient =
AnnotatedElementUtils.findMergedAnnotation(DisabledMockClass.class,
ShenyuSpringWebSocketClient.class);
+ MetaDataRegisterDTO enabledMetaData =
eventListener.buildMetaDataDTO(mockClass, enabledClient, SUPER_PATH,
MockClass.class, method, Constants.SYS_DEFAULT_NAMESPACE_ID);
+ MetaDataRegisterDTO disabledMetaData =
eventListener.buildMetaDataDTO(mockClass, disabledClient, SUPER_PATH,
DisabledMockClass.class, method, Constants.SYS_DEFAULT_NAMESPACE_ID);
+ assertTrue(enabledMetaData.isEnabled());
+ assertFalse(disabledMetaData.isEnabled());
+ }
+
@Test
public void testGetPort() {
String port = eventListener.getPort();
@@ -218,4 +232,13 @@ public class SpringWebSocketClientEventListenerTest {
}
}
+ /**
+ * class for mock with the enabled attribute set to false.
+ */
+ @ShenyuSpringWebSocketClient(enabled = false)
+ private static class DisabledMockClass {
+ public void mockMethod() {
+ }
+ }
+
}