fix:修改ws的参数格式

master
tangfudong 2024-03-06 11:04:19 +08:00
parent f631bbfd8a
commit 0b4daf2e96
4 changed files with 20 additions and 22 deletions

View File

@ -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<AccessToken> accessTokens;
private String tokenKey;
@Data
public static class AccessToken{
private String tokenName;
private String tokenStr;
}
private String accessToken;
}

View File

@ -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<WebsocketConfig.AccessToken> 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());

View File

@ -4,4 +4,5 @@ plugin:
websocket:
port: 1662
accessTokens: [{"tokenName":"test_token","tokenStr":"123456789"}]
tokenKey: "test_token"
accessToken: "123456789"

View File

@ -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": "令牌"
}
]