fix(接口测试): 修复包含excel文件的请求执行失败问题

--bug=1015442 --user=赵勇 【接口测试】执行带excel文件的接口会报错 https://www.tapd.cn/55049933/s/1213910
This commit is contained in:
fit2-zhao 2022-07-27 16:20:26 +08:00 committed by f2c-ci-robot[bot]
parent 4fdaf95a8c
commit 6cf6579601
6 changed files with 30 additions and 37 deletions

View File

@ -210,7 +210,7 @@
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId> <artifactId>easyexcel</artifactId>
<version>2.2.10</version> <version>3.1.1</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -1,7 +1,7 @@
package io.metersphere.api.controller; package io.metersphere.api.controller;
import io.metersphere.api.jmeter.JMeterThreadUtils; import io.metersphere.api.jmeter.JMeterThreadUtils;
import io.metersphere.api.service.ApiJmeterFileService; import io.metersphere.api.service.ApiJMeterFileService;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -12,10 +12,10 @@ import java.util.UUID;
@RestController @RestController
@RequestMapping("/api/jmeter") @RequestMapping("/api/jmeter")
public class ApiJmeterFileController { public class ApiJMeterFileController {
@Resource @Resource
private ApiJmeterFileService apiJmeterFileService; private ApiJMeterFileService apiJmeterFileService;
@GetMapping("stop/{name}") @GetMapping("stop/{name}")
public String stop(@PathVariable String name) { public String stop(@PathVariable String name) {

View File

@ -501,21 +501,15 @@ public class ESBParser extends EsbAbstractParser {
private String getCellValue(Cell cell) { private String getCellValue(Cell cell) {
String returnCellValue = ""; String returnCellValue = "";
int cellType = cell.getCellType(); if (cell.getCellType() == CellType.BLANK) {
switch (cellType) {
case Cell.CELL_TYPE_BLANK:
returnCellValue = ""; returnCellValue = "";
break; } else if (cell.getCellType() == CellType.BOOLEAN) {
case Cell.CELL_TYPE_BOOLEAN:
returnCellValue = String.valueOf(cell.getBooleanCellValue()); returnCellValue = String.valueOf(cell.getBooleanCellValue());
break; } else if (cell.getCellType() == CellType.ERROR) {
case Cell.CELL_TYPE_ERROR:
returnCellValue = ""; returnCellValue = "";
break; } else if (cell.getCellType() == CellType.NUMERIC) {
case Cell.CELL_TYPE_NUMERIC:
returnCellValue = getValueOfNumericCell(cell); returnCellValue = getValueOfNumericCell(cell);
break; } else if (cell.getCellType() == CellType.FORMULA) {
case Cell.CELL_TYPE_FORMULA:
try { try {
returnCellValue = getValueOfNumericCell(cell); returnCellValue = getValueOfNumericCell(cell);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
@ -526,8 +520,7 @@ public class ESBParser extends EsbAbstractParser {
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e);
} }
break; } else {
default:
returnCellValue = cell.getRichStringCellValue().getString(); returnCellValue = cell.getRichStringCellValue().getString();
} }
if (returnCellValue == null) { if (returnCellValue == null) {

View File

@ -35,7 +35,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
@Service @Service
public class ApiJmeterFileService { public class ApiJMeterFileService {
@Resource @Resource
private ApiCaseSerialService apiCaseSerialService; private ApiCaseSerialService apiCaseSerialService;
@Resource @Resource
@ -123,7 +123,7 @@ public class ApiJmeterFileService {
Map<String, byte[]> files = new HashMap<>(); Map<String, byte[]> files = new HashMap<>();
// 获取JAR // 获取JAR
Map<String, byte[]> jarFiles = this.getJar(); Map<String, byte[]> jarFiles = this.getJar();
if (!com.alibaba.excel.util.CollectionUtils.isEmpty(jarFiles)) { if (!MapUtils.isEmpty(jarFiles)) {
for (String k : jarFiles.keySet()) { for (String k : jarFiles.keySet()) {
byte[] v = jarFiles.get(k); byte[] v = jarFiles.get(k);
files.put(k, v); files.put(k, v);
@ -136,7 +136,7 @@ public class ApiJmeterFileService {
Map<String, byte[]> files = new HashMap<>(); Map<String, byte[]> files = new HashMap<>();
// 获取JAR // 获取JAR
Map<String, byte[]> jarFiles = this.getPlugJar(); Map<String, byte[]> jarFiles = this.getPlugJar();
if (!com.alibaba.excel.util.CollectionUtils.isEmpty(jarFiles)) { if (!MapUtils.isEmpty(jarFiles)) {
for (String k : jarFiles.keySet()) { for (String k : jarFiles.keySet()) {
byte[] v = jarFiles.get(k); byte[] v = jarFiles.get(k);
files.put(k, v); files.put(k, v);

View File

@ -4,7 +4,7 @@ package io.metersphere.performance.controller;
import io.metersphere.commons.utils.WeakConcurrentHashMap; import io.metersphere.commons.utils.WeakConcurrentHashMap;
import io.metersphere.controller.handler.annotation.NoResultHolder; import io.metersphere.controller.handler.annotation.NoResultHolder;
import io.metersphere.performance.dto.ZipDTO; import io.metersphere.performance.dto.ZipDTO;
import io.metersphere.performance.service.JmeterFileService; import io.metersphere.performance.service.JMeterFileService;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -20,9 +20,9 @@ import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping("jmeter") @RequestMapping("jmeter")
public class JmeterFileController { public class JMeterFileController {
@Resource @Resource
private JmeterFileService jmeterFileService; private JMeterFileService jmeterFileService;
private final WeakConcurrentHashMap<String, List<Double>> readyMap = new WeakConcurrentHashMap<>(30 * 60 * 1000);// 默认保留30分钟 private final WeakConcurrentHashMap<String, List<Double>> readyMap = new WeakConcurrentHashMap<>(30 * 60 * 1000);// 默认保留30分钟
@GetMapping("ping") @GetMapping("ping")

View File

@ -1,6 +1,5 @@
package io.metersphere.performance.service; package io.metersphere.performance.service;
import com.alibaba.excel.util.CollectionUtils;
import io.metersphere.base.domain.LoadTestReportWithBLOBs; import io.metersphere.base.domain.LoadTestReportWithBLOBs;
import io.metersphere.base.mapper.LoadTestReportMapper; import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper; import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
@ -10,6 +9,7 @@ import io.metersphere.performance.dto.ZipDTO;
import io.metersphere.performance.engine.EngineContext; import io.metersphere.performance.engine.EngineContext;
import io.metersphere.performance.engine.EngineFactory; import io.metersphere.performance.engine.EngineFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -23,7 +23,7 @@ import java.util.zip.ZipOutputStream;
// 非事务运行 // 非事务运行
@Service @Service
public class JmeterFileService { public class JMeterFileService {
@Resource @Resource
private ExtLoadTestReportMapper extLoadTestReportMapper; private ExtLoadTestReportMapper extLoadTestReportMapper;
@Resource @Resource