Commit 610ae6d53237c5c9705830bc4c3db12c1f0669a0

Authored by YunaiV
1 parent 432e1ed2

feat:【iot】优化 gateway 整体代码风格(空行)等

Showing 16 changed files with 31 additions and 65 deletions
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/mqtt/manager/IotMqttConnectionManager.java
@@ -88,9 +88,9 @@ public class IotMqttConnectionManager { @@ -88,9 +88,9 @@ public class IotMqttConnectionManager {
88 connectionMap.remove(oldEndpoint); 88 connectionMap.remove(oldEndpoint);
89 } 89 }
90 90
  91 + // 注册新连接
91 connectionMap.put(endpoint, connectionInfo); 92 connectionMap.put(endpoint, connectionInfo);
92 deviceEndpointMap.put(deviceId, endpoint); 93 deviceEndpointMap.put(deviceId, endpoint);
93 -  
94 log.info("[registerConnection][注册设备连接,设备 ID: {},连接: {},product key: {},device name: {}]", 94 log.info("[registerConnection][注册设备连接,设备 ID: {},连接: {},product key: {},device name: {}]",
95 deviceId, getEndpointAddress(endpoint), connectionInfo.getProductKey(), connectionInfo.getDeviceName()); 95 deviceId, getEndpointAddress(endpoint), connectionInfo.getProductKey(), connectionInfo.getDeviceName());
96 } 96 }
@@ -102,13 +102,12 @@ public class IotMqttConnectionManager { @@ -102,13 +102,12 @@ public class IotMqttConnectionManager {
102 */ 102 */
103 public void unregisterConnection(MqttEndpoint endpoint) { 103 public void unregisterConnection(MqttEndpoint endpoint) {
104 ConnectionInfo connectionInfo = connectionMap.remove(endpoint); 104 ConnectionInfo connectionInfo = connectionMap.remove(endpoint);
105 - if (connectionInfo != null) {  
106 - Long deviceId = connectionInfo.getDeviceId();  
107 - deviceEndpointMap.remove(deviceId);  
108 -  
109 - log.info("[unregisterConnection][注销设备连接,设备 ID: {},连接: {}]", deviceId,  
110 - getEndpointAddress(endpoint)); 105 + if (connectionInfo == null) {
  106 + return;
111 } 107 }
  108 + Long deviceId = connectionInfo.getDeviceId();
  109 + deviceEndpointMap.remove(deviceId);
  110 + log.info("[unregisterConnection][注销设备连接,设备 ID: {},连接: {}]", deviceId, getEndpointAddress(endpoint));
112 } 111 }
113 112
114 /** 113 /**
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/mqtt/router/IotMqttUpstreamHandler.java
@@ -471,9 +471,7 @@ public class IotMqttUpstreamHandler { @@ -471,9 +471,7 @@ public class IotMqttUpstreamHandler {
471 /** 471 /**
472 * 注册连接 472 * 注册连接
473 */ 473 */
474 - private void registerConnection(MqttEndpoint endpoint, IotDeviceRespDTO device,  
475 - String clientId) {  
476 - 474 + private void registerConnection(MqttEndpoint endpoint, IotDeviceRespDTO device, String clientId) {
477 IotMqttConnectionManager.ConnectionInfo connectionInfo = new IotMqttConnectionManager.ConnectionInfo() 475 IotMqttConnectionManager.ConnectionInfo connectionInfo = new IotMqttConnectionManager.ConnectionInfo()
478 .setDeviceId(device.getId()) 476 .setDeviceId(device.getId())
479 .setProductKey(device.getProductKey()) 477 .setProductKey(device.getProductKey())
@@ -481,7 +479,6 @@ public class IotMqttUpstreamHandler { @@ -481,7 +479,6 @@ public class IotMqttUpstreamHandler {
481 .setClientId(clientId) 479 .setClientId(clientId)
482 .setAuthenticated(true) 480 .setAuthenticated(true)
483 .setRemoteAddress(connectionManager.getEndpointAddress(endpoint)); 481 .setRemoteAddress(connectionManager.getEndpointAddress(endpoint));
484 -  
485 connectionManager.registerConnection(endpoint, device.getId(), connectionInfo); 482 connectionManager.registerConnection(endpoint, device.getId(), connectionInfo);
486 } 483 }
487 484
@@ -510,15 +507,13 @@ public class IotMqttUpstreamHandler { @@ -510,15 +507,13 @@ public class IotMqttUpstreamHandler {
510 IotDeviceMessage offlineMessage = IotDeviceMessage.buildStateOffline(); 507 IotDeviceMessage offlineMessage = IotDeviceMessage.buildStateOffline();
511 deviceMessageService.sendDeviceMessage(offlineMessage, connectionInfo.getProductKey(), 508 deviceMessageService.sendDeviceMessage(offlineMessage, connectionInfo.getProductKey(),
512 connectionInfo.getDeviceName(), serverId); 509 connectionInfo.getDeviceName(), serverId);
513 - log.info("[cleanupConnection][设备离线,设备 ID: {},设备名称: {}]",  
514 - connectionInfo.getDeviceId(), connectionInfo.getDeviceName()); 510 + log.info("[cleanupConnection][设备离线,设备 ID: {},设备名称: {}]", connectionInfo.getDeviceId(), connectionInfo.getDeviceName());
515 } 511 }
516 512
517 // 注销连接 513 // 注销连接
518 connectionManager.unregisterConnection(endpoint); 514 connectionManager.unregisterConnection(endpoint);
519 } catch (Exception e) { 515 } catch (Exception e) {
520 - log.error("[cleanupConnection][清理连接失败,客户端 ID: {},错误: {}]",  
521 - endpoint.clientIdentifier(), e.getMessage()); 516 + log.error("[cleanupConnection][清理连接失败,客户端 ID: {},错误: {}]", endpoint.clientIdentifier(), e.getMessage());
522 } 517 }
523 } 518 }
524 519
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/IotTcpDownstreamSubscriber.java
@@ -34,7 +34,7 @@ public class IotTcpDownstreamSubscriber implements IotMessageSubscriber<IotDevic @@ -34,7 +34,7 @@ public class IotTcpDownstreamSubscriber implements IotMessageSubscriber<IotDevic
34 public void init() { 34 public void init() {
35 // 初始化下游处理器 35 // 初始化下游处理器
36 this.downstreamHandler = new IotTcpDownstreamHandler(messageService, connectionManager); 36 this.downstreamHandler = new IotTcpDownstreamHandler(messageService, connectionManager);
37 - 37 + // 注册下游订阅者
38 messageBus.register(this); 38 messageBus.register(this);
39 log.info("[init][TCP 下游订阅者初始化完成,服务器 ID: {},Topic: {}]", 39 log.info("[init][TCP 下游订阅者初始化完成,服务器 ID: {},Topic: {}]",
40 protocol.getServerId(), getTopic()); 40 protocol.getServerId(), getTopic());
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/manager/IotTcpConnectionManager.java
@@ -51,9 +51,9 @@ public class IotTcpConnectionManager { @@ -51,9 +51,9 @@ public class IotTcpConnectionManager {
51 connectionMap.remove(oldSocket); 51 connectionMap.remove(oldSocket);
52 } 52 }
53 53
  54 + // 注册新连接
54 connectionMap.put(socket, connectionInfo); 55 connectionMap.put(socket, connectionInfo);
55 deviceSocketMap.put(deviceId, socket); 56 deviceSocketMap.put(deviceId, socket);
56 -  
57 log.info("[registerConnection][注册设备连接,设备 ID: {},连接: {},product key: {},device name: {}]", 57 log.info("[registerConnection][注册设备连接,设备 ID: {},连接: {},product key: {},device name: {}]",
58 deviceId, socket.remoteAddress(), connectionInfo.getProductKey(), connectionInfo.getDeviceName()); 58 deviceId, socket.remoteAddress(), connectionInfo.getProductKey(), connectionInfo.getDeviceName());
59 } 59 }
@@ -65,12 +65,12 @@ public class IotTcpConnectionManager { @@ -65,12 +65,12 @@ public class IotTcpConnectionManager {
65 */ 65 */
66 public void unregisterConnection(NetSocket socket) { 66 public void unregisterConnection(NetSocket socket) {
67 ConnectionInfo connectionInfo = connectionMap.remove(socket); 67 ConnectionInfo connectionInfo = connectionMap.remove(socket);
68 - if (connectionInfo != null) {  
69 - Long deviceId = connectionInfo.getDeviceId();  
70 - deviceSocketMap.remove(deviceId);  
71 - log.info("[unregisterConnection][注销设备连接,设备 ID: {},连接: {}]",  
72 - deviceId, socket.remoteAddress()); 68 + if (connectionInfo == null) {
  69 + return;
73 } 70 }
  71 + Long deviceId = connectionInfo.getDeviceId();
  72 + deviceSocketMap.remove(deviceId);
  73 + log.info("[unregisterConnection][注销设备连接,设备 ID: {},连接: {}]", deviceId, socket.remoteAddress());
74 } 74 }
75 75
76 /** 76 /**
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/udp/IotUdpDownstreamSubscriber.java
@@ -34,7 +34,7 @@ public class IotUdpDownstreamSubscriber implements IotMessageSubscriber<IotDevic @@ -34,7 +34,7 @@ public class IotUdpDownstreamSubscriber implements IotMessageSubscriber<IotDevic
34 public void init() { 34 public void init() {
35 // 初始化下游处理器 35 // 初始化下游处理器
36 this.downstreamHandler = new IotUdpDownstreamHandler(messageService, sessionManager, protocol); 36 this.downstreamHandler = new IotUdpDownstreamHandler(messageService, sessionManager, protocol);
37 - 37 + // 注册下游订阅者
38 messageBus.register(this); 38 messageBus.register(this);
39 log.info("[init][UDP 下游订阅者初始化完成,服务器 ID: {},Topic: {}]", 39 log.info("[init][UDP 下游订阅者初始化完成,服务器 ID: {},Topic: {}]",
40 protocol.getServerId(), getTopic()); 40 protocol.getServerId(), getTopic());
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/websocket/IotWebSocketDownstreamSubscriber.java
@@ -34,7 +34,7 @@ public class IotWebSocketDownstreamSubscriber implements IotMessageSubscriber<Io @@ -34,7 +34,7 @@ public class IotWebSocketDownstreamSubscriber implements IotMessageSubscriber<Io
34 public void init() { 34 public void init() {
35 // 初始化下游处理器 35 // 初始化下游处理器
36 this.downstreamHandler = new IotWebSocketDownstreamHandler(messageService, connectionManager); 36 this.downstreamHandler = new IotWebSocketDownstreamHandler(messageService, connectionManager);
37 - 37 + // 注册下游订阅者
38 messageBus.register(this); 38 messageBus.register(this);
39 log.info("[init][WebSocket 下游订阅者初始化完成,服务器 ID: {},Topic: {}]", 39 log.info("[init][WebSocket 下游订阅者初始化完成,服务器 ID: {},Topic: {}]",
40 protocol.getServerId(), getTopic()); 40 protocol.getServerId(), getTopic());
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/websocket/IotWebSocketUpstreamProtocol.java
@@ -73,8 +73,7 @@ public class IotWebSocketUpstreamProtocol { @@ -73,8 +73,7 @@ public class IotWebSocketUpstreamProtocol {
73 httpServer.webSocketHandler(socket -> { 73 httpServer.webSocketHandler(socket -> {
74 // 验证路径 74 // 验证路径
75 if (ObjUtil.notEqual(wsProperties.getPath(), socket.path())) { 75 if (ObjUtil.notEqual(wsProperties.getPath(), socket.path())) {
76 - log.warn("[webSocketHandler][WebSocket 路径不匹配,拒绝连接,路径: {},期望: {}]",  
77 - socket.path(), wsProperties.getPath()); 76 + log.warn("[webSocketHandler][WebSocket 路径不匹配,拒绝连接,路径: {},期望: {}]", socket.path(), wsProperties.getPath());
78 // TODO @AI:已经被废弃,看看换什么其他方法; 77 // TODO @AI:已经被废弃,看看换什么其他方法;
79 socket.reject(); 78 socket.reject();
80 return; 79 return;
@@ -89,8 +88,7 @@ public class IotWebSocketUpstreamProtocol { @@ -89,8 +88,7 @@ public class IotWebSocketUpstreamProtocol {
89 // 3. 启动服务器 88 // 3. 启动服务器
90 try { 89 try {
91 httpServer.listen().result(); 90 httpServer.listen().result();
92 - log.info("[start][IoT 网关 WebSocket 协议启动成功,端口:{},路径:{}]",  
93 - wsProperties.getPort(), wsProperties.getPath()); 91 + log.info("[start][IoT 网关 WebSocket 协议启动成功,端口:{},路径:{}]", wsProperties.getPort(), wsProperties.getPath());
94 } catch (Exception e) { 92 } catch (Exception e) {
95 log.error("[start][IoT 网关 WebSocket 协议启动失败]", e); 93 log.error("[start][IoT 网关 WebSocket 协议启动失败]", e);
96 throw e; 94 throw e;
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/websocket/manager/IotWebSocketConnectionManager.java
@@ -51,9 +51,9 @@ public class IotWebSocketConnectionManager { @@ -51,9 +51,9 @@ public class IotWebSocketConnectionManager {
51 connectionMap.remove(oldSocket); 51 connectionMap.remove(oldSocket);
52 } 52 }
53 53
  54 + // 注册新连接
54 connectionMap.put(socket, connectionInfo); 55 connectionMap.put(socket, connectionInfo);
55 deviceSocketMap.put(deviceId, socket); 56 deviceSocketMap.put(deviceId, socket);
56 -  
57 log.info("[registerConnection][注册设备连接,设备 ID: {},连接: {},product key: {},device name: {}]", 57 log.info("[registerConnection][注册设备连接,设备 ID: {},连接: {},product key: {},device name: {}]",
58 deviceId, socket.remoteAddress(), connectionInfo.getProductKey(), connectionInfo.getDeviceName()); 58 deviceId, socket.remoteAddress(), connectionInfo.getProductKey(), connectionInfo.getDeviceName());
59 } 59 }
@@ -65,12 +65,13 @@ public class IotWebSocketConnectionManager { @@ -65,12 +65,13 @@ public class IotWebSocketConnectionManager {
65 */ 65 */
66 public void unregisterConnection(ServerWebSocket socket) { 66 public void unregisterConnection(ServerWebSocket socket) {
67 ConnectionInfo connectionInfo = connectionMap.remove(socket); 67 ConnectionInfo connectionInfo = connectionMap.remove(socket);
68 - if (connectionInfo != null) {  
69 - Long deviceId = connectionInfo.getDeviceId();  
70 - deviceSocketMap.remove(deviceId);  
71 - log.info("[unregisterConnection][注销设备连接,设备 ID: {},连接: {}]",  
72 - deviceId, socket.remoteAddress()); 68 + if (connectionInfo == null) {
  69 + return;
73 } 70 }
  71 + Long deviceId = connectionInfo.getDeviceId();
  72 + deviceSocketMap.remove(deviceId);
  73 + log.info("[unregisterConnection][注销设备连接,设备 ID: {},连接: {}]",
  74 + deviceId, socket.remoteAddress());
74 } 75 }
75 76
76 /** 77 /**
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/websocket/router/IotWebSocketUpstreamHandler.java
@@ -327,8 +327,7 @@ public class IotWebSocketUpstreamHandler implements Handler<ServerWebSocket> { @@ -327,8 +327,7 @@ public class IotWebSocketUpstreamHandler implements Handler<ServerWebSocket> {
327 .build(); 327 .build();
328 328
329 int code = success ? 0 : 401; 329 int code = success ? 0 : 401;
330 - IotDeviceMessage responseMessage = IotDeviceMessage.replyOf(requestId, AUTH_METHOD, responseData,  
331 - code, message); 330 + IotDeviceMessage responseMessage = IotDeviceMessage.replyOf(requestId, AUTH_METHOD, responseData, code, message);
332 331
333 byte[] encodedData = deviceMessageService.encodeDeviceMessage(responseMessage, CODEC_TYPE); 332 byte[] encodedData = deviceMessageService.encodeDeviceMessage(responseMessage, CODEC_TYPE);
334 socket.writeTextMessage(new String(encodedData, StandardCharsets.UTF_8)); 333 socket.writeTextMessage(new String(encodedData, StandardCharsets.UTF_8));
yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/IotDirectDeviceTcpProtocolIntegrationTest.java
@@ -84,9 +84,6 @@ public class IotDirectDeviceTcpProtocolIntegrationTest { @@ -84,9 +84,6 @@ public class IotDirectDeviceTcpProtocolIntegrationTest {
84 // 1.2 编码 84 // 1.2 编码
85 byte[] payload = CODEC.encode(request); 85 byte[] payload = CODEC.encode(request);
86 log.info("[testAuth][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length); 86 log.info("[testAuth][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length);
87 - if (CODEC instanceof IotTcpBinaryDeviceMessageCodec) {  
88 - log.info("[testAuth][二进制数据包(HEX): {}]", HexUtil.encodeHexStr(payload));  
89 - }  
90 87
91 // 2.1 发送请求 88 // 2.1 发送请求
92 try (Socket socket = new Socket(SERVER_HOST, SERVER_PORT)) { 89 try (Socket socket = new Socket(SERVER_HOST, SERVER_PORT)) {
@@ -123,9 +120,6 @@ public class IotDirectDeviceTcpProtocolIntegrationTest { @@ -123,9 +120,6 @@ public class IotDirectDeviceTcpProtocolIntegrationTest {
123 // 1.2 编码 120 // 1.2 编码
124 byte[] payload = CODEC.encode(request); 121 byte[] payload = CODEC.encode(request);
125 log.info("[testDeviceRegister][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length); 122 log.info("[testDeviceRegister][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length);
126 - if (CODEC instanceof IotTcpBinaryDeviceMessageCodec) {  
127 - log.info("[testDeviceRegister][二进制数据包(HEX): {}]", HexUtil.encodeHexStr(payload));  
128 - }  
129 123
130 // 2.1 发送请求 124 // 2.1 发送请求
131 try (Socket socket = new Socket(SERVER_HOST, SERVER_PORT)) { 125 try (Socket socket = new Socket(SERVER_HOST, SERVER_PORT)) {
yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/IotGatewayDeviceTcpProtocolIntegrationTest.java
1 package cn.iocoder.yudao.module.iot.gateway.protocol.tcp; 1 package cn.iocoder.yudao.module.iot.gateway.protocol.tcp;
2 2
3 import cn.hutool.core.map.MapUtil; 3 import cn.hutool.core.map.MapUtil;
4 -import cn.hutool.core.util.HexUtil;  
5 import cn.hutool.core.util.IdUtil; 4 import cn.hutool.core.util.IdUtil;
6 import cn.iocoder.yudao.module.iot.core.biz.dto.IotDeviceAuthReqDTO; 5 import cn.iocoder.yudao.module.iot.core.biz.dto.IotDeviceAuthReqDTO;
7 import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum; 6 import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum;
@@ -99,9 +98,6 @@ public class IotGatewayDeviceTcpProtocolIntegrationTest { @@ -99,9 +98,6 @@ public class IotGatewayDeviceTcpProtocolIntegrationTest {
99 // 1.2 编码 98 // 1.2 编码
100 byte[] payload = CODEC.encode(request); 99 byte[] payload = CODEC.encode(request);
101 log.info("[testAuth][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length); 100 log.info("[testAuth][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length);
102 - if (CODEC instanceof IotTcpBinaryDeviceMessageCodec) {  
103 - log.info("[testAuth][二进制数据包(HEX): {}]", HexUtil.encodeHexStr(payload));  
104 - }  
105 101
106 // 2.1 发送请求 102 // 2.1 发送请求
107 try (Socket socket = new Socket(SERVER_HOST, SERVER_PORT)) { 103 try (Socket socket = new Socket(SERVER_HOST, SERVER_PORT)) {
yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/IotGatewaySubDeviceTcpProtocolIntegrationTest.java
1 package cn.iocoder.yudao.module.iot.gateway.protocol.tcp; 1 package cn.iocoder.yudao.module.iot.gateway.protocol.tcp;
2 2
3 import cn.hutool.core.map.MapUtil; 3 import cn.hutool.core.map.MapUtil;
4 -import cn.hutool.core.util.HexUtil;  
5 import cn.hutool.core.util.IdUtil; 4 import cn.hutool.core.util.IdUtil;
6 import cn.iocoder.yudao.module.iot.core.biz.dto.IotDeviceAuthReqDTO; 5 import cn.iocoder.yudao.module.iot.core.biz.dto.IotDeviceAuthReqDTO;
7 import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum; 6 import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum;
@@ -85,9 +84,6 @@ public class IotGatewaySubDeviceTcpProtocolIntegrationTest { @@ -85,9 +84,6 @@ public class IotGatewaySubDeviceTcpProtocolIntegrationTest {
85 // 1.2 编码 84 // 1.2 编码
86 byte[] payload = CODEC.encode(request); 85 byte[] payload = CODEC.encode(request);
87 log.info("[testAuth][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length); 86 log.info("[testAuth][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length);
88 - if (CODEC instanceof IotTcpBinaryDeviceMessageCodec) {  
89 - log.info("[testAuth][二进制数据包(HEX): {}]", HexUtil.encodeHexStr(payload));  
90 - }  
91 87
92 // 2.1 发送请求 88 // 2.1 发送请求
93 try (Socket socket = new Socket(SERVER_HOST, SERVER_PORT)) { 89 try (Socket socket = new Socket(SERVER_HOST, SERVER_PORT)) {
yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/udp/IotDirectDeviceUdpProtocolIntegrationTest.java
1 package cn.iocoder.yudao.module.iot.gateway.protocol.udp; 1 package cn.iocoder.yudao.module.iot.gateway.protocol.udp;
2 2
3 import cn.hutool.core.map.MapUtil; 3 import cn.hutool.core.map.MapUtil;
4 -import cn.hutool.core.util.HexUtil;  
5 import cn.hutool.core.util.IdUtil; 4 import cn.hutool.core.util.IdUtil;
6 import cn.iocoder.yudao.module.iot.core.biz.dto.IotDeviceAuthReqDTO; 5 import cn.iocoder.yudao.module.iot.core.biz.dto.IotDeviceAuthReqDTO;
7 import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum; 6 import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum;
@@ -90,9 +89,6 @@ public class IotDirectDeviceUdpProtocolIntegrationTest { @@ -90,9 +89,6 @@ public class IotDirectDeviceUdpProtocolIntegrationTest {
90 // 1.2 编码 89 // 1.2 编码
91 byte[] payload = CODEC.encode(request); 90 byte[] payload = CODEC.encode(request);
92 log.info("[testAuth][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length); 91 log.info("[testAuth][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length);
93 - if (CODEC instanceof IotTcpBinaryDeviceMessageCodec) {  
94 - log.info("[testAuth][二进制数据包(HEX): {}]", HexUtil.encodeHexStr(payload));  
95 - }  
96 92
97 // 2.1 发送请求 93 // 2.1 发送请求
98 try (DatagramSocket socket = new DatagramSocket()) { 94 try (DatagramSocket socket = new DatagramSocket()) {
@@ -130,9 +126,6 @@ public class IotDirectDeviceUdpProtocolIntegrationTest { @@ -130,9 +126,6 @@ public class IotDirectDeviceUdpProtocolIntegrationTest {
130 // 1.2 编码 126 // 1.2 编码
131 byte[] payload = CODEC.encode(request); 127 byte[] payload = CODEC.encode(request);
132 log.info("[testDeviceRegister][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length); 128 log.info("[testDeviceRegister][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length);
133 - if (CODEC instanceof IotTcpBinaryDeviceMessageCodec) {  
134 - log.info("[testDeviceRegister][二进制数据包(HEX): {}]", HexUtil.encodeHexStr(payload));  
135 - }  
136 129
137 // 2.1 发送请求 130 // 2.1 发送请求
138 try (DatagramSocket socket = new DatagramSocket()) { 131 try (DatagramSocket socket = new DatagramSocket()) {
yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/udp/IotGatewayDeviceUdpProtocolIntegrationTest.java
1 package cn.iocoder.yudao.module.iot.gateway.protocol.udp; 1 package cn.iocoder.yudao.module.iot.gateway.protocol.udp;
2 2
3 import cn.hutool.core.map.MapUtil; 3 import cn.hutool.core.map.MapUtil;
4 -import cn.hutool.core.util.HexUtil;  
5 import cn.hutool.core.util.IdUtil; 4 import cn.hutool.core.util.IdUtil;
6 import cn.iocoder.yudao.module.iot.core.biz.dto.IotDeviceAuthReqDTO; 5 import cn.iocoder.yudao.module.iot.core.biz.dto.IotDeviceAuthReqDTO;
7 import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum; 6 import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum;
@@ -102,9 +101,6 @@ public class IotGatewayDeviceUdpProtocolIntegrationTest { @@ -102,9 +101,6 @@ public class IotGatewayDeviceUdpProtocolIntegrationTest {
102 // 1.2 编码 101 // 1.2 编码
103 byte[] payload = CODEC.encode(request); 102 byte[] payload = CODEC.encode(request);
104 log.info("[testAuth][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length); 103 log.info("[testAuth][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length);
105 - if (CODEC instanceof IotTcpBinaryDeviceMessageCodec) {  
106 - log.info("[testAuth][二进制数据包(HEX): {}]", HexUtil.encodeHexStr(payload));  
107 - }  
108 104
109 // 2.1 发送请求 105 // 2.1 发送请求
110 try (DatagramSocket socket = new DatagramSocket()) { 106 try (DatagramSocket socket = new DatagramSocket()) {
yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/udp/IotGatewaySubDeviceUdpProtocolIntegrationTest.java
1 package cn.iocoder.yudao.module.iot.gateway.protocol.udp; 1 package cn.iocoder.yudao.module.iot.gateway.protocol.udp;
2 2
3 import cn.hutool.core.map.MapUtil; 3 import cn.hutool.core.map.MapUtil;
4 -import cn.hutool.core.util.HexUtil;  
5 import cn.hutool.core.util.IdUtil; 4 import cn.hutool.core.util.IdUtil;
6 import cn.iocoder.yudao.module.iot.core.biz.dto.IotDeviceAuthReqDTO; 5 import cn.iocoder.yudao.module.iot.core.biz.dto.IotDeviceAuthReqDTO;
7 import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum; 6 import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum;
@@ -91,9 +90,6 @@ public class IotGatewaySubDeviceUdpProtocolIntegrationTest { @@ -91,9 +90,6 @@ public class IotGatewaySubDeviceUdpProtocolIntegrationTest {
91 // 1.2 编码 90 // 1.2 编码
92 byte[] payload = CODEC.encode(request); 91 byte[] payload = CODEC.encode(request);
93 log.info("[testAuth][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length); 92 log.info("[testAuth][Codec: {}, 请求消息: {}, 数据包长度: {} 字节]", CODEC.type(), request, payload.length);
94 - if (CODEC instanceof IotTcpBinaryDeviceMessageCodec) {  
95 - log.info("[testAuth][二进制数据包(HEX): {}]", HexUtil.encodeHexStr(payload));  
96 - }  
97 93
98 // 2.1 发送请求 94 // 2.1 发送请求
99 try (DatagramSocket socket = new DatagramSocket()) { 95 try (DatagramSocket socket = new DatagramSocket()) {
yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/websocket/IotDirectDeviceWebSocketProtocolIntegrationTest.java
@@ -81,6 +81,8 @@ public class IotDirectDeviceWebSocketProtocolIntegrationTest { @@ -81,6 +81,8 @@ public class IotDirectDeviceWebSocketProtocolIntegrationTest {
81 81
82 // ===================== 认证测试 ===================== 82 // ===================== 认证测试 =====================
83 83
  84 + // TODO @AI:参考 /Users/yunai/Java/ruoyi-vue-pro-jdk25/yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/IotDirectDeviceTcpProtocolIntegrationTest.java 或 /Users/yunai/Java/ruoyi-vue-pro-jdk25/yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/mqtt/IotDirectDeviceMqttProtocolIntegrationTest.java 类,优化代码结构
  85 +
84 /** 86 /**
85 * 认证测试:获取设备 Token 87 * 认证测试:获取设备 Token
86 */ 88 */
@@ -96,6 +98,7 @@ public class IotDirectDeviceWebSocketProtocolIntegrationTest { @@ -96,6 +98,7 @@ public class IotDirectDeviceWebSocketProtocolIntegrationTest {
96 .setPort(SERVER_PORT) 98 .setPort(SERVER_PORT)
97 .setURI(WS_PATH); 99 .setURI(WS_PATH);
98 100
  101 + // TODO @AI:这里有告警;Deprecate /instead use WebSocketClient.connect(WebSocketConnectOptions)
99 client.webSocket(options).onComplete(ar -> { 102 client.webSocket(options).onComplete(ar -> {
100 if (ar.succeeded()) { 103 if (ar.succeeded()) {
101 WebSocket ws = ar.result(); 104 WebSocket ws = ar.result();