From 0b4daf2e9694b7a20db4ddaa8de0721d991ed131 Mon Sep 17 00:00:00 2001 From: tangfudong <280620913@qq.com> Date: Wed, 6 Mar 2024 11:04:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9ws=E7=9A=84=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/websocket/conf/WebsocketConfig.java | 10 ++-------- .../websocket/service/WebsocketVerticle.java | 12 ++++-------- .../src/main/resources/application.yml | 3 ++- websocket-plugin/src/main/resources/config.json | 17 ++++++++++++----- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/websocket-plugin/src/main/java/cc/iotkit/plugins/websocket/conf/WebsocketConfig.java b/websocket-plugin/src/main/java/cc/iotkit/plugins/websocket/conf/WebsocketConfig.java index abd0c50..e4bb7eb 100644 --- a/websocket-plugin/src/main/java/cc/iotkit/plugins/websocket/conf/WebsocketConfig.java +++ b/websocket-plugin/src/main/java/cc/iotkit/plugins/websocket/conf/WebsocketConfig.java @@ -13,8 +13,6 @@ import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; -import java.util.List; - @Data @Component @ConfigurationProperties(prefix = "websocket") @@ -28,12 +26,8 @@ public class WebsocketConfig { private boolean ssl; - private List accessTokens; + private String tokenKey; - @Data - public static class AccessToken{ - private String tokenName; - private String tokenStr; - } + private String accessToken; } diff --git a/websocket-plugin/src/main/java/cc/iotkit/plugins/websocket/service/WebsocketVerticle.java b/websocket-plugin/src/main/java/cc/iotkit/plugins/websocket/service/WebsocketVerticle.java index 78713e5..ccb5f9a 100644 --- a/websocket-plugin/src/main/java/cc/iotkit/plugins/websocket/service/WebsocketVerticle.java +++ b/websocket-plugin/src/main/java/cc/iotkit/plugins/websocket/service/WebsocketVerticle.java @@ -31,7 +31,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -66,10 +65,10 @@ public class WebsocketVerticle extends AbstractVerticle { @Override public void start() { - Executors.newSingleThreadScheduledExecutor().schedule(this::initMqttServer, 3, TimeUnit.SECONDS); + Executors.newSingleThreadScheduledExecutor().schedule(this::initWsServer, 3, TimeUnit.SECONDS); } - private void initMqttServer() { + private void initWsServer() { HttpServerOptions options = new HttpServerOptions() .setPort(config.getPort()); if (config.isSsl()) { @@ -186,11 +185,8 @@ public class WebsocketVerticle extends AbstractVerticle { }).listen(config.getPort(), server -> { if (server.succeeded()) { log.info("webSocket server is listening on port " + config.getPort()); - if(config.getAccessTokens()!=null){ - List tokenConfig= config.getAccessTokens(); - for (WebsocketConfig.AccessToken obj:tokenConfig) { - tokens.put(obj.getTokenName(),obj.getTokenStr()); - } + if(config.getTokenKey()!=null&&config.getAccessToken()!=null){ + tokens.put(config.getTokenKey(),config.getAccessToken()); } } else { log.error("webSocket server on starting the server", server.cause()); diff --git a/websocket-plugin/src/main/resources/application.yml b/websocket-plugin/src/main/resources/application.yml index 062764a..122b872 100644 --- a/websocket-plugin/src/main/resources/application.yml +++ b/websocket-plugin/src/main/resources/application.yml @@ -4,4 +4,5 @@ plugin: websocket: port: 1662 - accessTokens: [{"tokenName":"test_token","tokenStr":"123456789"}] + tokenKey: "test_token" + accessToken: "123456789" diff --git a/websocket-plugin/src/main/resources/config.json b/websocket-plugin/src/main/resources/config.json index d6fb543..f746ef7 100644 --- a/websocket-plugin/src/main/resources/config.json +++ b/websocket-plugin/src/main/resources/config.json @@ -7,10 +7,17 @@ "desc": "websocket端口,默认为1662" }, { - "id": "accessTokens", - "name": "token表", - "type": "json", - "value": "[{'tokenName':'test_token','tokenStr':'123456789'}]", - "desc": "token表,可多个" + "id": "tokenKey", + "name": "令牌key", + "type": "text", + "value": "test_token", + "desc": "令牌key" + }, + { + "id": "accessToken", + "name": "令牌", + "type": "text", + "value": "123456789", + "desc": "令牌" } ] \ No newline at end of file