fix(接口测试) 完善插件运行支持node加载插件
This commit is contained in:
parent
0edd845474
commit
3b099091ab
|
@ -54,4 +54,13 @@ public class ApiJmeterFileController {
|
|||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + testId + ".zip\"")
|
||||
.body(bytes);
|
||||
}
|
||||
|
||||
@GetMapping("download/plug/jar")
|
||||
public ResponseEntity<byte[]> downloadPlugFiles() {
|
||||
byte[] bytes = apiJmeterFileService.downloadPlugJar();
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + UUID.randomUUID().toString() + ".zip\"")
|
||||
.body(bytes);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,10 @@ package io.metersphere.api.service;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import io.metersphere.api.dto.definition.request.MsTestPlan;
|
||||
import io.metersphere.api.dto.scenario.request.BodyFile;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
||||
import io.metersphere.base.domain.JarConfig;
|
||||
import io.metersphere.base.domain.Plugin;
|
||||
import io.metersphere.base.domain.TestPlanApiScenario;
|
||||
import io.metersphere.base.mapper.ApiScenarioMapper;
|
||||
import io.metersphere.base.mapper.TestPlanApiScenarioMapper;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
|
@ -12,6 +15,7 @@ import io.metersphere.commons.utils.CommonBeanFactory;
|
|||
import io.metersphere.commons.utils.FileUtils;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.service.JarConfigService;
|
||||
import io.metersphere.service.PluginService;
|
||||
import io.metersphere.track.service.TestPlanApiCaseService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -23,6 +27,7 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
|
@ -118,6 +123,19 @@ public class ApiJmeterFileService {
|
|||
return listBytesToZip(files);
|
||||
}
|
||||
|
||||
public byte[] downloadPlugJar() {
|
||||
Map<String, byte[]> files = new HashMap<>();
|
||||
// 获取JAR
|
||||
Map<String, byte[]> jarFiles = this.getPlugJar();
|
||||
if (!com.alibaba.excel.util.CollectionUtils.isEmpty(jarFiles)) {
|
||||
for (String k : jarFiles.keySet()) {
|
||||
byte[] v = jarFiles.get(k);
|
||||
files.put(k, v);
|
||||
}
|
||||
}
|
||||
return listBytesToZip(files);
|
||||
}
|
||||
|
||||
private Map<String, byte[]> getJar() {
|
||||
Map<String, byte[]> jarFiles = new LinkedHashMap<>();
|
||||
// jar 包
|
||||
|
@ -141,6 +159,33 @@ public class ApiJmeterFileService {
|
|||
return jarFiles;
|
||||
}
|
||||
|
||||
private Map<String, byte[]> getPlugJar() {
|
||||
Map<String, byte[]> jarFiles = new LinkedHashMap<>();
|
||||
// jar 包
|
||||
PluginService pluginService = CommonBeanFactory.getBean(PluginService.class);
|
||||
|
||||
List<Plugin> plugins = pluginService.list();
|
||||
if (CollectionUtils.isNotEmpty(plugins)) {
|
||||
plugins = plugins.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()
|
||||
-> new TreeSet<>(Comparator.comparing(Plugin::getPluginId))), ArrayList::new));
|
||||
|
||||
if (CollectionUtils.isNotEmpty(plugins)) {
|
||||
plugins.forEach(item -> {
|
||||
String path = item.getSourcePath();
|
||||
File file = new File(path);
|
||||
if (file.isDirectory() && !path.endsWith("/")) {
|
||||
file = new File(path + "/");
|
||||
}
|
||||
byte[] fileByte = FileUtils.fileToByte(file);
|
||||
if (fileByte != null) {
|
||||
jarFiles.put(file.getName(), fileByte);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return jarFiles;
|
||||
}
|
||||
|
||||
private Map<String, byte[]> getMultipartFiles(HashTree hashTree) {
|
||||
Map<String, byte[]> multipartFiles = new LinkedHashMap<>();
|
||||
// 获取附件
|
||||
|
|
|
@ -40,6 +40,7 @@ public class ShiroUtils {
|
|||
filterChainDefinitionMap.put("/api/jmeter/download", "anon");
|
||||
filterChainDefinitionMap.put("/api/jmeter/download/files", "anon");
|
||||
filterChainDefinitionMap.put("/api/jmeter/download/jar", "anon");
|
||||
filterChainDefinitionMap.put("/api/jmeter/download/plug/jar", "anon");
|
||||
|
||||
// for swagger
|
||||
filterChainDefinitionMap.put("/swagger-ui.html", "anon");
|
||||
|
|
|
@ -221,4 +221,10 @@ public class PluginService {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Plugin> list() {
|
||||
PluginExample example = new PluginExample();
|
||||
List<Plugin> plugins = pluginMapper.selectByExample(example);
|
||||
return plugins;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue