Skip to content

Commit 943e4ab

Browse files
committed
3.7.3
1 parent 069a3d7 commit 943e4ab

File tree

3 files changed

+13
-33
lines changed

3 files changed

+13
-33
lines changed

solon-projects/solon-server/solon-server-tomcat/src/main/java/org/noear/solon/server/tomcat/TomcatServer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
*/
4545
public class TomcatServer extends TomcatServerBase {
4646
protected boolean isSecure;
47-
protected boolean enableWebSocket;
4847

4948
public boolean isSecure() {
5049
return isSecure;

solon-projects/solon-server/solon-server-tomcat/src/main/java/org/noear/solon/server/tomcat/TomcatServerBase.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public abstract class TomcatServerBase implements ServerLifecycle, HttpServerCon
4949

5050
protected Set<Integer> addHttpPorts = new LinkedHashSet<>();
5151

52+
protected boolean enableWebSocket;
5253
protected boolean enableHttp2 = false;
5354

5455
public TomcatServerBase(HttpServerProps props) {
@@ -115,9 +116,9 @@ public void start(String host, int port) throws Throwable {
115116
}
116117

117118
_server.start();
118-
119-
if(TcWebSocketManager.isEnableWebSocket()) {
120-
TcWebSocketManager.registerEndpoints(_context);
119+
120+
if(enableWebSocket) {
121+
TcWebSocketManager.registerEndpoints(_context);
121122
}
122123
}
123124

solon-projects/solon-server/solon-server-tomcat/src/main/java/org/noear/solon/server/tomcat/websocket/TcWebSocketManager.java

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
*/
3535
public class TcWebSocketManager {
3636
private static final Logger log = LoggerFactory.getLogger(TcWebSocketManager.class);
37-
private static boolean enableWebSocket = false;
38-
39-
private TcWebSocketManager() {}
40-
37+
38+
private TcWebSocketManager() {
39+
}
40+
4141
/**
4242
* 在Tomcat上下文中初始化WebSocket支持
4343
* 注意:此方法需要在上下文初始化之前调用
@@ -47,17 +47,16 @@ public static void init(Context context) {
4747
log.error("Tomcat Context is null, cannot initialize WebSocket");
4848
return;
4949
}
50-
50+
5151
try {
5252
// 注册WebSocket容器初始化器
5353
context.addServletContainerInitializer(new WsSci(), null);
54-
enableWebSocket = true;
5554
log.info("Tomcat WebSocket initialized");
5655
} catch (Exception e) {
5756
log.error("Failed to initialize Tomcat WebSocket", e);
5857
}
5958
}
60-
59+
6160
/**
6261
* 注册WebSocket端点
6362
* 注意:此方法需要在服务器启动后调用
@@ -67,12 +66,12 @@ public static void registerEndpoints(Context context) {
6766
log.error("Tomcat Context is null, cannot register WebSocket endpoints");
6867
return;
6968
}
70-
69+
7170
try {
7271
// 获取ServerContainer
7372
ServerContainer serverContainer = (ServerContainer) context.getServletContext()
7473
.getAttribute("javax.websocket.server.ServerContainer");
75-
74+
7675
if (serverContainer == null) {
7776
log.error("Tomcat Context Missing javax.websocket.server.ServerContainer");
7877
return;
@@ -88,7 +87,7 @@ public static void registerEndpoints(Context context) {
8887
.create(TcWebSocketEndpoint.class, path)
8988
.configurator(new TcWebSocketConfigurator())
9089
.build();
91-
90+
9291
serverContainer.addEndpoint(endpointConfig);
9392
log.info("Tomcat Registered WebSocket endpoint: {}", path);
9493
}
@@ -97,23 +96,4 @@ public static void registerEndpoints(Context context) {
9796
log.error("Failed to register Tomcat WebSocket endpoints", e);
9897
}
9998
}
100-
101-
/**
102-
* 检查WebSocket是否已启用
103-
*/
104-
public static boolean isEnableWebSocket() {
105-
return enableWebSocket;
106-
}
107-
108-
/**
109-
* 获取WebSocket容器
110-
*/
111-
// public static ServerContainer getServerContainer(Context context) {
112-
// if (context == null) {
113-
// return null;
114-
// }
115-
//
116-
// return (ServerContainer) context.getServletContext()
117-
// .getAttribute("javax.websocket.server.ServerContainer");
118-
// }
11999
}

0 commit comments

Comments
 (0)