瀏覽代碼

修改pom文件依赖本来,导致证书创建失败

gt 2 年之前
父節點
當前提交
c31665f6f1

+ 1 - 1
chuanyi_server/pom.xml

@@ -155,7 +155,7 @@
         <dependency>
             <groupId>org.bouncycastle</groupId>
             <artifactId>bcpkix-jdk15on</artifactId>
-            <version>1.65</version>
+            <version>1.57</version>
         </dependency>
         <!--Milo服务端的依赖-->
         <dependency>

+ 3 - 3
chuanyi_server/src/main/java/com/judong/chuanyiserver/config/OpcServerDaPoolFactory.java → chuanyi_server/src/main/java/com/judong/chuanyiserver/config/KepOpcServerPoolFactory.java

@@ -19,7 +19,7 @@ import java.util.concurrent.Executors;
  * OPCserver工厂类
  */
 @Slf4j
-public class OpcServerDaPoolFactory {
+public class KepOpcServerPoolFactory {
 
     /**
      * 对象池
@@ -132,13 +132,13 @@ public class OpcServerDaPoolFactory {
      */
     public synchronized static void init() {
         if (pool != null) return;
-        pool = new GenericKeyedObjectPool<String, Server>(new MyOpcServerDaPooledFactory(), config);
+        pool = new GenericKeyedObjectPool<String, Server>(new MyKepOpcServerPooledFactory(), config);
     }
 
     /**
      * 对象工厂
      */
-    static class MyOpcServerDaPooledFactory extends BaseKeyedPooledObjectFactory<String, Server> {
+    static class MyKepOpcServerPooledFactory extends BaseKeyedPooledObjectFactory<String, Server> {
         /**
          * 创建对象
          *

+ 0 - 4
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ConnectServiceImpl.java

@@ -8,14 +8,10 @@ import com.judong.chuanyiserver.exception.CustomException;
 import com.judong.chuanyiserver.service.ConnectService;
 import com.judong.chuanyiserver.util.*;
 import lombok.extern.slf4j.Slf4j;
-import org.jinterop.dcom.common.JIException;
-import org.openscada.opc.lib.common.AlreadyConnectedException;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.net.UnknownHostException;
 
 @Service
 @Transactional

+ 5 - 6
chuanyi_server/src/main/java/com/judong/chuanyiserver/util/KepOpcServerUtil.java

@@ -1,7 +1,7 @@
 package com.judong.chuanyiserver.util;
 
 import com.alibaba.fastjson.JSONObject;
-import com.judong.chuanyiserver.config.OpcServerDaPoolFactory;
+import com.judong.chuanyiserver.config.KepOpcServerPoolFactory;
 import com.judong.chuanyiserver.entity.ServerInformation;
 import com.judong.chuanyiserver.enums.ConnectModeEnum;
 import com.judong.chuanyiserver.enums.ResultEnum;
@@ -10,7 +10,6 @@ import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
 import org.jinterop.dcom.common.JIException;
 import org.jinterop.dcom.core.JIVariant;
 import org.openscada.opc.dcom.da.OPCSERVERSTATE;
-import org.openscada.opc.lib.common.AlreadyConnectedException;
 import org.openscada.opc.lib.common.ConnectionInformation;
 import org.openscada.opc.lib.da.Group;
 import org.openscada.opc.lib.da.Item;
@@ -78,14 +77,14 @@ public class KepOpcServerUtil {
      * @throws Exception
      */
     public static Server getServer(String key) throws Exception {
-        return OpcServerDaPoolFactory.getServer(key);
+        return KepOpcServerPoolFactory.getServer(key);
     }
 
     /**
      * 返回Server给连接池
      */
     public static void returnServer(String key, Server server) throws Exception {
-        OpcServerDaPoolFactory.returnServer(key, server);
+        KepOpcServerPoolFactory.returnServer(key, server);
     }
 
     /**
@@ -94,9 +93,9 @@ public class KepOpcServerUtil {
      * @return
      */
     public static GenericKeyedObjectPool<String, Server> getPool() throws Exception {
-        GenericKeyedObjectPool<String, Server> pool = OpcServerDaPoolFactory.getPool();
+        GenericKeyedObjectPool<String, Server> pool = KepOpcServerPoolFactory.getPool();
 //        System.out.println(pool.);
-        return OpcServerDaPoolFactory.getPool();
+        return KepOpcServerPoolFactory.getPool();
     }
 
     public static Result opcTestConnect(ServerInformation serverInformation) {

+ 9 - 7
chuanyi_server/src/main/java/com/judong/chuanyiserver/util/KeyStoreLoader.java

@@ -1,16 +1,11 @@
-/**
- * Created by Jellyleo on 2019年12月19日
- * Copyright © 2019 jellyleo.com
- * All rights reserved.
- */
 package com.judong.chuanyiserver.util;
 
+
 import org.eclipse.milo.opcua.sdk.server.util.HostnameUtil;
 import org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateBuilder;
 import org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateGenerator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Component;
 
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -20,6 +15,12 @@ import java.security.*;
 import java.security.cert.X509Certificate;
 import java.util.regex.Pattern;
 
+/**
+ * @author Jellyleo
+ * @ClassName: KeyStoreLoader
+ * @Description: KeyStoreLoader
+ * @date 2019年12月11日
+ */
 public class KeyStoreLoader {
 
     private static final Pattern IP_ADDR_PATTERN = Pattern
@@ -53,7 +54,7 @@ public class KeyStoreLoader {
         // 而其他如.der等的格式只包含公钥,私钥在另外的文件中。
         Path serverKeyStore = baseDir.resolve("jellyleo-client.pfx");
 
-        logger.info("正在加载KeyStore{}", serverKeyStore);
+        logger.info("正在加载 KeyStore at {}", serverKeyStore);
 
         // 如果文件不存在则创建.pfx证书文件。
         if (!Files.exists(serverKeyStore)) {
@@ -123,3 +124,4 @@ public class KeyStoreLoader {
         return clientKeyPair;
     }
 }
+

+ 5 - 14
chuanyi_server/src/main/java/com/judong/chuanyiserver/util/OpcServerUaUtil.java

@@ -11,28 +11,16 @@ import org.eclipse.milo.opcua.sdk.client.api.identity.UsernameProvider;
 import org.eclipse.milo.opcua.sdk.client.nodes.UaNode;
 import org.eclipse.milo.opcua.stack.client.DiscoveryClient;
 import org.eclipse.milo.opcua.stack.core.Identifiers;
-import org.eclipse.milo.opcua.stack.core.Stack;
 import org.eclipse.milo.opcua.stack.core.UaException;
 import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy;
 import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText;
-import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
 import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned;
-import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
 import org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription;
-import org.jinterop.dcom.common.JIException;
-import org.openscada.opc.dcom.da.OPCSERVERSTATE;
-import org.openscada.opc.lib.da.Server;
-import org.openscada.opc.lib.da.browser.Branch;
-import org.openscada.opc.lib.da.browser.TreeBrowser;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.util.ObjectUtils;
 
-import java.net.UnknownHostException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.CompletableFuture;
@@ -60,7 +48,7 @@ public class OpcServerUaUtil {
             log.info("无法创建安全目录: " + securityTempDir);
             return null;
         }
-        KeyStoreLoader keyStoreLoader = new KeyStoreLoader();
+        KeyStoreLoader keyStoreLoader=new KeyStoreLoader();
         KeyStoreLoader loader = keyStoreLoader.load(securityTempDir);
         // 搜索OPC节点
         List<EndpointDescription> endpoints = null;
@@ -157,8 +145,11 @@ public class OpcServerUaUtil {
         OpcUaClient opcUaClient = null;
         try {
             opcUaClient = createClient(serverInformation);
+            if (Blank.isEmpty(opcUaClient)){
+                return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "客户端创建失败");
+            }
             long start = System.currentTimeMillis();
-            opcUaClient.connect();
+            opcUaClient.connect().get();
             long finish = System.currentTimeMillis();
             log.info("连接耗费时间为:" + (finish - start) + "毫秒");
             return Result.ok(true);