From ee5442b44d406a2703c9d76b865377cfaed00c66 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 22 Dec 2022 15:36:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B?= =?UTF-8?q?=E8=AF=95):=20=E4=BC=98=E5=8C=96=E6=89=A7=E8=A1=8C=E8=BF=87?= =?UTF-8?q?=E7=A8=8B=E9=99=84=E4=BB=B6=E4=B8=8B=E8=BD=BD=E5=8E=8B=E7=BC=A9?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ApiJMeterFileService.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java b/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java index 23069e8d8f..d6b85e7cf0 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java @@ -288,21 +288,21 @@ public class ApiJMeterFileService { return listBytesToZip(files); } - private byte[] listBytesToZip(Map mapReport) { - try { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ZipOutputStream zos = new ZipOutputStream(baos); - for (Map.Entry report : mapReport.entrySet()) { - ZipEntry entry = new ZipEntry(report.getKey()); - entry.setSize(report.getValue().length); + private byte[] listBytesToZip(Map content) { + try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ZipOutputStream zos = new ZipOutputStream(byteArrayOutputStream)) { + for (String key : content.keySet()) { + ZipEntry entry = new ZipEntry(key); + entry.setSize(content.get(key).length); zos.putNextEntry(entry); - zos.write(report.getValue()); + zos.write(content.get(key)); } zos.closeEntry(); zos.close(); - return baos.toByteArray(); + return byteArrayOutputStream.toByteArray(); } catch (Exception e) { - return null; + LogUtil.error(e); + return new byte[0]; } } From 078f24d86b0c1a7303f926ed077763d867f4ef68 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Thu, 22 Dec 2022 16:00:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=A4=84=E7=90=86json=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 --- .../java/io/metersphere/sechedule/SwaggerUrlImportJob.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/sechedule/SwaggerUrlImportJob.java b/api-test/backend/src/main/java/io/metersphere/sechedule/SwaggerUrlImportJob.java index abaae59881..f6e6dac02b 100644 --- a/api-test/backend/src/main/java/io/metersphere/sechedule/SwaggerUrlImportJob.java +++ b/api-test/backend/src/main/java/io/metersphere/sechedule/SwaggerUrlImportJob.java @@ -43,7 +43,6 @@ public class SwaggerUrlImportJob extends MsScheduleJob { request.setPlatform("Swagger2"); request.setUserId(jobDataMap.getString("userId")); request.setType("schedule"); - request.setUserId(jobDataMap.getString("userId")); request.setResourceId(resourceId); apiDefinitionService.apiTestImport(null, request); } @@ -59,7 +58,7 @@ public class SwaggerUrlImportJob extends MsScheduleJob { public void setAuthInfo(String config, ApiTestImportRequest request) { // 获取鉴权设置 if (StringUtils.isNotBlank(config)) { - JSONObject configObj = JSON.parseObject(config, JSONObject.class); + JSONObject configObj = JSONUtil.parseObject(config); List headers = JSONUtil.parseArray(configObj.optString("headers"), KeyValue.class); if (CollectionUtils.isNotEmpty(headers)) { request.setHeaders(headers);