From 9f2f17fe9f1b8fbf0c5cea000d88bb8b52484f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Tue, 7 Mar 2023 18:36:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=83=E6=AD=A3=E5=BC=8F=E5=8C=85?= =?UTF-8?q?=200.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++---- pom.xml | 6 +++--- servlet-core/pom.xml | 2 +- .../org/smartboot/servlet/ContainerRuntime.java | 2 +- .../plugins/websocket/WebsocketProviderImpl.java | 14 ++++++++++++-- smart-servlet-maven-plugin/pom.xml | 2 +- spring-boot-starter/pom.xml | 2 +- .../springboot/starter/SmartServletServer.java | 10 ++++------ testsuite/pom.xml | 2 +- 9 files changed, 28 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ea4a3e2..26062e3 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ smart-servlet 在 smart-http 的架构之上,通过继承 HttpHandle 实现了 org.smartboot.servlet smart-servlet-maven-plugin - 0.1.9-SNAPSHOT + 0.2 8080 @@ -67,12 +67,12 @@ smart-servlet 在 smart-http 的架构之上,通过继承 HttpHandle 实现了 org.smartboot.servlet plugin-session - 0.1.9-SNAPSHOT + 0.2 org.smartboot.servlet plugin-dispatcher - 0.1.9-SNAPSHOT + 0.2 @@ -102,7 +102,7 @@ smart-servlet 在 smart-http 的架构之上,通过继承 HttpHandle 实现了 org.smartboot.servlet smart-servlet-spring-boot-starter - 0.1.9-SNAPSHOT + 0.2 diff --git a/pom.xml b/pom.xml index fa65d4e..ede6181 100644 --- a/pom.xml +++ b/pom.xml @@ -5,12 +5,12 @@ 4.0.0 org.smartboot.servlet smart-servlet-parent - 0.1.9-SNAPSHOT + 0.2 pom - 1.1.20-SNAPSHOT - 0.1.9-SNAPSHOT + 1.1.22 + 0.2 3.1.0 1.3.2 diff --git a/servlet-core/pom.xml b/servlet-core/pom.xml index 08c676a..f39a12e 100644 --- a/servlet-core/pom.xml +++ b/servlet-core/pom.xml @@ -5,7 +5,7 @@ smart-servlet-parent org.smartboot.servlet - 0.1.9-SNAPSHOT + 0.2 servlet-core 4.0.0 diff --git a/servlet-core/src/main/java/org/smartboot/servlet/ContainerRuntime.java b/servlet-core/src/main/java/org/smartboot/servlet/ContainerRuntime.java index e5b4e54..cd55233 100644 --- a/servlet-core/src/main/java/org/smartboot/servlet/ContainerRuntime.java +++ b/servlet-core/src/main/java/org/smartboot/servlet/ContainerRuntime.java @@ -62,7 +62,7 @@ public class ContainerRuntime { * Font Name: Puffy */ private static final String BANNER = " _ _ _ \n" + " ( )_ (_ ) ( )_ \n" + " ___ ___ ___ _ _ _ __ | ,_) ___ __ _ __ _ _ | | __ | ,_)\n" + "/',__)/' _ ` _ `\\ /'_` )( '__)| | /',__) /'__`\\( '__)( ) ( ) | | /'__`\\| | \n" + "\\__, \\| ( ) ( ) |( (_| || | | |_ \\__, \\( ___/| | | \\_/ | | | ( ___/| |_ \n" + "(____/(_) (_) (_)`\\__,_)(_) `\\__) (____/`\\____)(_) `\\___/'(___)`\\____)`\\__)"; - public static final String VERSION = "0.1.9-SNAPSHOT"; + public static final String VERSION = "0.2"; /** * 注册在当前 Servlet 容器中的运行环境 */ diff --git a/servlet-core/src/main/java/org/smartboot/servlet/plugins/websocket/WebsocketProviderImpl.java b/servlet-core/src/main/java/org/smartboot/servlet/plugins/websocket/WebsocketProviderImpl.java index 7bcd3ce..8262dd4 100644 --- a/servlet-core/src/main/java/org/smartboot/servlet/plugins/websocket/WebsocketProviderImpl.java +++ b/servlet-core/src/main/java/org/smartboot/servlet/plugins/websocket/WebsocketProviderImpl.java @@ -21,6 +21,8 @@ import org.smartboot.servlet.plugins.websocket.impl.SmartServerEndpointConfig; import org.smartboot.servlet.plugins.websocket.impl.WebsocketServerContainer; import org.smartboot.servlet.plugins.websocket.impl.WebsocketSession; import org.smartboot.servlet.provider.WebsocketProvider; +import org.smartboot.socket.util.AttachKey; +import org.smartboot.socket.util.Attachment; import javax.websocket.PongMessage; import javax.websocket.Session; @@ -39,6 +41,8 @@ import java.util.Map; * @version V1.0 , 2021/3/31 */ public class WebsocketProviderImpl implements WebsocketProvider { + + private static final AttachKey WEBSOCKET_SESSION_ATTACH_KEY = AttachKey.valueOf("websocketSession"); private final WebsocketServerContainer container; public WebsocketProviderImpl(WebsocketServerContainer container) { @@ -48,7 +52,8 @@ public class WebsocketProviderImpl implements WebsocketProvider { @Override public void doHandle(ServletContextRuntime runtime, WebSocketRequest request, WebSocketResponse response) { try { - WebsocketSession session = request.getAttachment(); + Attachment attachment = request.getAttachment(); + WebsocketSession session = attachment.get(WEBSOCKET_SESSION_ATTACH_KEY); switch (request.getFrameOpcode()) { case WebSocketRequestImpl.OPCODE_TEXT: handleTextMessage(session.getTextMessageHandler(), new String(request.getPayload(), StandardCharsets.UTF_8)); @@ -117,8 +122,13 @@ public class WebsocketProviderImpl implements WebsocketProvider { } AnnotatedEndpoint endpoint = new AnnotatedEndpoint(matchedServerEndpointConfig, data); + Attachment attachment = request.getAttachment(); + if (attachment == null) { + attachment = new Attachment(); + request.setAttachment(attachment); + } WebsocketSession websocketSession = new WebsocketSession(container, endpoint, URI.create(request.getRequestURI())); - request.setAttachment(websocketSession); + attachment.put(WEBSOCKET_SESSION_ATTACH_KEY, websocketSession); //注册 OnMessage 回调 Map finalData = data; diff --git a/smart-servlet-maven-plugin/pom.xml b/smart-servlet-maven-plugin/pom.xml index ad0e330..7dfa6f5 100644 --- a/smart-servlet-maven-plugin/pom.xml +++ b/smart-servlet-maven-plugin/pom.xml @@ -5,7 +5,7 @@ smart-servlet-parent org.smartboot.servlet - 0.1.9-SNAPSHOT + 0.2 4.0.0 maven-plugin diff --git a/spring-boot-starter/pom.xml b/spring-boot-starter/pom.xml index c76f380..88fc921 100644 --- a/spring-boot-starter/pom.xml +++ b/spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ smart-servlet-parent org.smartboot.servlet - 0.1.9-SNAPSHOT + 0.2 4.0.0 diff --git a/spring-boot-starter/src/main/java/org/smartboot/springboot/starter/SmartServletServer.java b/spring-boot-starter/src/main/java/org/smartboot/springboot/starter/SmartServletServer.java index fb697a0..90820e2 100644 --- a/spring-boot-starter/src/main/java/org/smartboot/springboot/starter/SmartServletServer.java +++ b/spring-boot-starter/src/main/java/org/smartboot/springboot/starter/SmartServletServer.java @@ -16,14 +16,13 @@ import org.smartboot.http.server.HttpServerHandler; import org.smartboot.http.server.WebSocketHandler; import org.smartboot.http.server.WebSocketRequest; import org.smartboot.http.server.WebSocketResponse; -import org.smartboot.http.server.impl.Request; +import org.smartboot.http.server.impl.WebSocketRequestImpl; +import org.smartboot.http.server.impl.WebSocketResponseImpl; import org.smartboot.servlet.ContainerRuntime; import org.smartboot.servlet.ServletContextRuntime; import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.server.WebServerException; -import java.io.IOException; - /** * @author 三刀 * @version V1.0 , 2020/10/12 @@ -48,9 +47,8 @@ public class SmartServletServer implements WebServer { } }).webSocketHandler(new WebSocketHandler() { @Override - public void onHeaderComplete(Request request) throws IOException { - super.onHeaderComplete(request); - containerRuntime.onHeaderComplete(request); + public void whenHeaderComplete(WebSocketRequestImpl request, WebSocketResponseImpl response) { + containerRuntime.onHeaderComplete(request.getRequest()); } @Override diff --git a/testsuite/pom.xml b/testsuite/pom.xml index 77f78ef..0ba0ed7 100644 --- a/testsuite/pom.xml +++ b/testsuite/pom.xml @@ -73,7 +73,7 @@ org.smartboot.servlet smart-servlet-maven-plugin - 0.1.9-SNAPSHOT + 0.2 8081 /demo -- Gitee