diff --git a/pom.xml b/pom.xml index 87d0823..a091496 100644 --- a/pom.xml +++ b/pom.xml @@ -157,8 +157,9 @@ org.springframework.boot spring-boot-maven-plugin 2.5.4 - + + org.projectlombok diff --git a/src/main/java/com/qgs/dc/opcua/controller/OperateController.java b/src/main/java/com/qgs/dc/opcua/controller/OperateController.java index 3990e15..d47278c 100644 --- a/src/main/java/com/qgs/dc/opcua/controller/OperateController.java +++ b/src/main/java/com/qgs/dc/opcua/controller/OperateController.java @@ -69,6 +69,9 @@ public class OperateController { List currentSubscribeVarForVisited = uaService.getCurrentSubscribeVarForVisited(plcName); List ns = new ArrayList<>(); List iden = new ArrayList<>(); + if(currentSubscribeVarForVisited == null){ + return; + } for(CurrentSubEntity currentSubEntity:currentSubscribeVarForVisited){ ns.add(currentSubEntity.getNameSpace()); iden.add(currentSubEntity.getIdentifier()); diff --git a/src/main/java/com/qgs/dc/opcua/selfunion/UAService.java b/src/main/java/com/qgs/dc/opcua/selfunion/UAService.java index 1ebd6a8..3d19ff9 100644 --- a/src/main/java/com/qgs/dc/opcua/selfunion/UAService.java +++ b/src/main/java/com/qgs/dc/opcua/selfunion/UAService.java @@ -168,7 +168,6 @@ public class UAService { return new ArrayList<>(opcUaClients.keySet()); } - private OpcUaClient createClient(PLCConfig plcConfig) throws Exception { //会获取系统的临时目录 可能是linux 或者 是windows //Path securityTempDir = Paths.get(System.getProperty("java.io.tmpdir"), "security"); @@ -216,6 +215,7 @@ public class UAService { endpoints = DiscoveryClient.getEndpoints(discoveryUrl).get(); } + MessageSecurityMode filterMessageMode = MessageSecurityMode.from(plcConfig.getMessageMode()); EndpointDescription endpoint = endpoints.stream() @@ -1182,7 +1182,9 @@ public class UAService { users = user_configs.split(","); } PLCConfig plcConfig = new PLCConfig(plcName, url_config, SecurityPolicy.valueOf(policy_config), users, ip,messageMode); - opcUaClients.put(plcName,createClient(plcConfig)); + OpcUaClient client = createClient(plcConfig); + + opcUaClients.put(plcName,client); opcUaClients.get(plcName).connect().get(); //只有当写入无异常的时候在录到本地json文件中去 @@ -1232,8 +1234,11 @@ public class UAService { logger.error(err); //出现异常后把 连接给中断,,然后回收资源 - opcUaClients.get(plcName).disconnect().get(); - opcUaClients.remove(plcName); + OpcUaClient uaClient = opcUaClients.get(plcName); + if(uaClient!=null){ + opcUaClients.get(plcName).disconnect().get(); + opcUaClients.remove(plcName); + } throw e; } } diff --git a/src/test/java/com/qgs/dc/DcApplicationTests.java b/src/test/java/com/qgs/dc/DcApplicationTests.java deleted file mode 100644 index 1e72865..0000000 --- a/src/test/java/com/qgs/dc/DcApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.qgs.dc; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class DcApplicationTests { - - @Test - void contextLoads() { - } - -}