This commit is contained in:
liqiang-fit2cloud 2022-12-22 16:22:38 +08:00
commit 1186b47aed
2 changed files with 11 additions and 12 deletions

View File

@ -43,7 +43,6 @@ public class SwaggerUrlImportJob extends MsScheduleJob {
request.setPlatform("Swagger2"); request.setPlatform("Swagger2");
request.setUserId(jobDataMap.getString("userId")); request.setUserId(jobDataMap.getString("userId"));
request.setType("schedule"); request.setType("schedule");
request.setUserId(jobDataMap.getString("userId"));
request.setResourceId(resourceId); request.setResourceId(resourceId);
apiDefinitionService.apiTestImport(null, request); apiDefinitionService.apiTestImport(null, request);
} }
@ -59,7 +58,7 @@ public class SwaggerUrlImportJob extends MsScheduleJob {
public void setAuthInfo(String config, ApiTestImportRequest request) { public void setAuthInfo(String config, ApiTestImportRequest request) {
// 获取鉴权设置 // 获取鉴权设置
if (StringUtils.isNotBlank(config)) { if (StringUtils.isNotBlank(config)) {
JSONObject configObj = JSON.parseObject(config, JSONObject.class); JSONObject configObj = JSONUtil.parseObject(config);
List<KeyValue> headers = JSONUtil.parseArray(configObj.optString("headers"), KeyValue.class); List<KeyValue> headers = JSONUtil.parseArray(configObj.optString("headers"), KeyValue.class);
if (CollectionUtils.isNotEmpty(headers)) { if (CollectionUtils.isNotEmpty(headers)) {
request.setHeaders(headers); request.setHeaders(headers);

View File

@ -288,21 +288,21 @@ public class ApiJMeterFileService {
return listBytesToZip(files); return listBytesToZip(files);
} }
private byte[] listBytesToZip(Map<String, byte[]> mapReport) { private byte[] listBytesToZip(Map<String, byte[]> content) {
try { try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(byteArrayOutputStream)) {
ZipOutputStream zos = new ZipOutputStream(baos); for (String key : content.keySet()) {
for (Map.Entry<String, byte[]> report : mapReport.entrySet()) { ZipEntry entry = new ZipEntry(key);
ZipEntry entry = new ZipEntry(report.getKey()); entry.setSize(content.get(key).length);
entry.setSize(report.getValue().length);
zos.putNextEntry(entry); zos.putNextEntry(entry);
zos.write(report.getValue()); zos.write(content.get(key));
} }
zos.closeEntry(); zos.closeEntry();
zos.close(); zos.close();
return baos.toByteArray(); return byteArrayOutputStream.toByteArray();
} catch (Exception e) { } catch (Exception e) {
return null; LogUtil.error(e);
return new byte[0];
} }
} }