From c517952a20fdfb0b0ea0ced49ef01c1b19774775 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 23 Jul 2020 10:05:14 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=97=B6=E7=9A=84=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/performance/service/ReportService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/metersphere/performance/service/ReportService.java b/backend/src/main/java/io/metersphere/performance/service/ReportService.java index ff5ec96f9e..324dd1be85 100644 --- a/backend/src/main/java/io/metersphere/performance/service/ReportService.java +++ b/backend/src/main/java/io/metersphere/performance/service/ReportService.java @@ -207,14 +207,14 @@ public class ReportService { public List getReportLogs(String reportId, String resourceId) { LoadTestReportLogExample example = new LoadTestReportLogExample(); example.createCriteria().andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId); - example.setOrderByClause("part desc"); + example.setOrderByClause("part"); return loadTestReportLogMapper.selectByExampleWithBLOBs(example); } public List downloadLog(String reportId, String resourceId) { LoadTestReportLogExample example = new LoadTestReportLogExample(); example.createCriteria().andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId); - example.setOrderByClause("part desc"); + example.setOrderByClause("part"); List loadTestReportLogs = loadTestReportLogMapper.selectByExampleWithBLOBs(example); return loadTestReportLogs.stream().map(LoadTestReportLog::getContent).collect(Collectors.toList()); From bd3ea709b24fbef88a1f59c8455d0688002a4255 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 23 Jul 2020 10:26:39 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95=E6=97=A5=E5=BF=97=E7=9A=84?= =?UTF-8?q?oom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PerformanceReportController.java | 11 +------- .../performance/service/ReportService.java | 26 +++++++++++++++---- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java b/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java index 178b6304f6..2413311997 100644 --- a/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java +++ b/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java @@ -19,7 +19,6 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; -import java.io.OutputStream; import java.util.List; @RestController @@ -112,14 +111,6 @@ public class PerformanceReportController { @GetMapping("log/download/{reportId}/{resourceId}") public void downloadLog(@PathVariable String reportId, @PathVariable String resourceId, HttpServletResponse response) throws Exception { - try (OutputStream outputStream = response.getOutputStream()) { - List content = reportService.downloadLog(reportId, resourceId); - response.setContentType("application/x-download"); - response.addHeader("Content-Disposition", "attachment;filename=jmeter.log"); - for (String log : content) { - outputStream.write(log.getBytes()); - } - outputStream.flush(); - } + reportService.downloadLog(response, reportId, resourceId); } } diff --git a/backend/src/main/java/io/metersphere/performance/service/ReportService.java b/backend/src/main/java/io/metersphere/performance/service/ReportService.java index 324dd1be85..7878045515 100644 --- a/backend/src/main/java/io/metersphere/performance/service/ReportService.java +++ b/backend/src/main/java/io/metersphere/performance/service/ReportService.java @@ -23,9 +23,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.OutputStream; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; @Service @Transactional(rollbackFor = Exception.class) @@ -211,13 +212,28 @@ public class ReportService { return loadTestReportLogMapper.selectByExampleWithBLOBs(example); } - public List downloadLog(String reportId, String resourceId) { + public void downloadLog(HttpServletResponse response, String reportId, String resourceId) throws Exception { LoadTestReportLogExample example = new LoadTestReportLogExample(); - example.createCriteria().andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId); + LoadTestReportLogExample.Criteria criteria = example.createCriteria(); + criteria.andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId); example.setOrderByClause("part"); - List loadTestReportLogs = loadTestReportLogMapper.selectByExampleWithBLOBs(example); - return loadTestReportLogs.stream().map(LoadTestReportLog::getContent).collect(Collectors.toList()); + long count = loadTestReportLogMapper.countByExample(example); + + try (OutputStream outputStream = response.getOutputStream()) { + response.setContentType("application/x-download"); + response.addHeader("Content-Disposition", "attachment;filename=jmeter.log"); + for (long i = 1; i <= count; i++) { + example.clear(); + LoadTestReportLogExample.Criteria innerCriteria = example.createCriteria(); + innerCriteria.andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId).andPartEqualTo(i); + + List loadTestReportLogs = loadTestReportLogMapper.selectByExampleWithBLOBs(example); + LoadTestReportLog content = loadTestReportLogs.get(0); + outputStream.write(content.getContent().getBytes()); + } + outputStream.flush(); + } } public LoadTestReport getReport(String reportId) { From 354c6afca4c1af8170290798805d5037f4d60919 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 23 Jul 2020 10:41:31 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20URL=E5=AF=BC=E5=85=A5=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/metersphere/api/service/APITestService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index c47e54e813..44a25e32d9 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -264,7 +264,7 @@ public class APITestService { ApiImportParser apiImportParser = ApiImportParserFactory.getApiImportParser(request.getPlatform()); ApiImport apiImport = null; try { - apiImport = Objects.requireNonNull(apiImportParser).parse(file.getInputStream(), request); + apiImport = Objects.requireNonNull(apiImportParser).parse(file == null ? null : file.getInputStream(), request); } catch (Exception e) { LogUtil.error(e.getMessage(), e); MSException.throwException(Translator.get("parse_data_error"));