测试脚本
This commit is contained in:
parent
f8bf4b10fb
commit
4616f1b700
27
pom.xml
27
pom.xml
@ -14,8 +14,8 @@
|
||||
<vertx>3.4.2</vertx>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<maven.compiler.source>1.6</maven.compiler.source>
|
||||
<maven.compiler.target>1.6</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -38,6 +38,16 @@
|
||||
<groupId>com.sunyard</groupId>
|
||||
<artifactId>proto</artifactId>
|
||||
<version>1.1.20221215</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-all</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
@ -75,11 +85,11 @@
|
||||
<!-- <scope>provided</scope>-->
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.4.M1</version>
|
||||
<!-- <scope>provided</scope>-->
|
||||
<version>5.8.38</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -94,6 +104,13 @@
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.13.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.codehaus.groovy</groupId>-->
|
||||
<!-- <artifactId>groovy-all</artifactId>-->
|
||||
<!-- <version>3.0.9</version>-->
|
||||
<!-- <version>4.0.26</version>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
@ -119,6 +136,7 @@
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-compiler</artifactId>
|
||||
<version>2.9.2-01</version>
|
||||
<!-- <version>3.5.0-01</version>-->
|
||||
<extensions>true</extensions>
|
||||
</plugin>
|
||||
|
||||
@ -126,6 +144,7 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<!-- <version>3.8.1</version>-->
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
|
||||
@ -10,7 +10,7 @@ import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class TestCert {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
public static void main(String[] args) throws Exception {
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
System.out.println("-----------start---------------");
|
||||
@ -29,15 +29,7 @@ public class TestCert {
|
||||
String bkCode = map.get("bkcode");
|
||||
Map<String, String> snmpMap = readFileToMap(snmpInfo);
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
sydApi4j.importCertToServers(ipList, timeout, cert, bkCode, gson.toJson(snmpMap));
|
||||
} catch (Exception e) {
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
System.out.println("---------------------证书导入失败日志----------------------");
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
sydApi4j.importCertToServers(ipList, timeout, cert, bkCode, gson.toJson(snmpMap));
|
||||
System.out.println("------------end-----------------------");
|
||||
stopWatch.stop();
|
||||
System.out.println("耗时:" + stopWatch.getTotalTimeMillis() + "ms");
|
||||
|
||||
@ -120,5 +120,4 @@ public interface SydApi extends
|
||||
|
||||
public void setBindObject(Object bindObject);
|
||||
|
||||
void importCertToServers(List<String> addressList, int timeout, String cert, String bkCode, String snmpConfig);
|
||||
}
|
||||
|
||||
@ -32,9 +32,7 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.snmp4j.PDU;
|
||||
import org.snmp4j.event.ResponseEvent;
|
||||
import org.snmp4j.mp.SnmpConstants;
|
||||
import racal.sunyard.main.dto.DTO77;
|
||||
import racal.sunyard.main.dto.DTO78;
|
||||
import racal.sunyard.main.dto.DTO79;
|
||||
@ -56,7 +54,6 @@ import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
@ -1312,8 +1309,7 @@ public class SydApi4j implements SydApi {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void importCertToServers(List<String> addressList, int timeout, String cert, String bkCode, String snmpConfig) {
|
||||
public String importCertToServers(List<String> addressList, int timeout, String cert, String bkCode, String snmpConfig) {
|
||||
if (null == addressList || addressList.isEmpty()) {
|
||||
throw new IllegalArgumentException("签名服务器地址不能为空");
|
||||
}
|
||||
@ -1337,17 +1333,17 @@ public class SydApi4j implements SydApi {
|
||||
stringBuilder.append("签名服务器:").append(taskOutcome.getContext().getAddress()).append("/导入失败:").append(taskOutcome.getError().getMessage()).append("\n");
|
||||
}
|
||||
}
|
||||
String dn = null;
|
||||
String serialNumber = null;
|
||||
X509Certificate certificate = null;
|
||||
try {
|
||||
certificate = CertUtil.convertToX509Cert(cert);
|
||||
dn = certificate.getSubjectDN().toString();
|
||||
serialNumber = certificate.getSerialNumber().toString();
|
||||
} catch (Exception e) {
|
||||
log.warn("导入证书格式错误!");
|
||||
}
|
||||
if (!failures.isEmpty()) {
|
||||
String dn = "";
|
||||
String serialNumber = "";
|
||||
X509Certificate certificate = null;
|
||||
try {
|
||||
certificate = CertUtil.convertToX509Cert(cert);
|
||||
dn = certificate.getSubjectDN().toString();
|
||||
serialNumber = certificate.getSerialNumber().toString();
|
||||
} catch (Exception e) {
|
||||
log.info("证书格式错误!");
|
||||
}
|
||||
//记录失败日志
|
||||
stringBuilder.append("行号:").append(bkCode).append("\n").append("DN:").append(dn)
|
||||
.append("\n序列号:").append(serialNumber).append("\n证书:").append(cert);
|
||||
@ -1374,9 +1370,9 @@ public class SydApi4j implements SydApi {
|
||||
} catch (Exception e) {
|
||||
log.warn("snmp告警消息发送失败:{}", e.getMessage());
|
||||
}
|
||||
throw new SydApiException("证书导入失败!", 56300, true);
|
||||
// throw new SydApiException("证书未全部导入成功!", 56300, true);
|
||||
}
|
||||
|
||||
return dn;
|
||||
}
|
||||
|
||||
private TaskContext<String> createTaskContext(String address, int timeout, String cert) {
|
||||
|
||||
@ -27,26 +27,26 @@ public class Test4NongxinCW {
|
||||
|
||||
byte[] orgData = new byte[100];
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
// 通过设置debug的属性开启debug,如果不设置则默认不打开
|
||||
api = (SydApi4j) new SydApi4j().connect("172.16.18.6", 8889, null, 1000);
|
||||
|
||||
}
|
||||
// @Before
|
||||
// public void before() {
|
||||
// // 通过设置debug的属性开启debug,如果不设置则默认不打开
|
||||
// api = (SydApi4j) new SydApi4j().connect("172.16.18.6", 8889, null, 1000);
|
||||
//
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void connection() {
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
try {
|
||||
this.api.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// @After
|
||||
// public void after() {
|
||||
// try {
|
||||
// this.api.disconnect();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void nakeSign(){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user