diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtractCommon.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtractCommon.java index 3ac9f8a662..767a295102 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtractCommon.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtractCommon.java @@ -8,7 +8,7 @@ import org.apache.commons.lang3.StringUtils; @Data public class MsExtractCommon extends MsExtractType{ private String variable; - private String value; // value: ${variable} + private String value; private String expression; private String description; private boolean multipleMatching; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index 1d179da506..88fa857651 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -83,7 +83,7 @@ public class ApiTestCaseService { } public List listSimple(ApiTestCaseRequest request) { - request = this.initRequest(request,true,true); + request = this.initRequest(request, true, true); List apiTestCases = extApiTestCaseMapper.listSimple(request); if (CollectionUtils.isEmpty(apiTestCases)) { @@ -95,16 +95,17 @@ public class ApiTestCaseService { /** * 初始化部分参数 + * * @param request * @param setDefultOrders * @param checkThisWeekData * @return */ private ApiTestCaseRequest initRequest(ApiTestCaseRequest request, boolean setDefultOrders, boolean checkThisWeekData) { - if(setDefultOrders){ + if (setDefultOrders) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); } - if(checkThisWeekData){ + if (checkThisWeekData) { if (request.isSelectThisWeedData()) { Map weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date()); Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime"); @@ -412,23 +413,38 @@ public class ApiTestCaseService { apiDefinitionWithBLOBs.setUpdateTime(System.currentTimeMillis()); apiTestCaseMapper.updateByExampleSelective(apiDefinitionWithBLOBs, apiDefinitionExample); } - if ((StringUtils.isNotEmpty(request.getMethod()) || StringUtils.isNotEmpty(request.getPath())) && request.getProtocol().equals(RequestType.HTTP)) { + if ((StringUtils.isNotEmpty(request.getMethod()) || StringUtils.isNotEmpty(request.getPath())) && RequestType.HTTP.equals(request.getProtocol())) { List bloBs = apiTestCaseMapper.selectByExampleWithBLOBs(apiDefinitionExample); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); ApiTestCaseMapper batchMapper = sqlSession.getMapper(ApiTestCaseMapper.class); + + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); bloBs.forEach(apiTestCase -> { MsHTTPSamplerProxy req = JSON.parseObject(apiTestCase.getRequest(), MsHTTPSamplerProxy.class); - if (StringUtils.isNotEmpty(request.getMethod())) { - req.setMethod(request.getMethod()); - } - if (StringUtils.isNotEmpty(request.getPath())) { - req.setPath(request.getPath()); + try { + JSONObject element = JSON.parseObject(apiTestCase.getRequest()); + if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) { + LinkedList elements = mapper.readValue(element.getString("hashTree"), new TypeReference>() { + }); + req.setHashTree(elements); + } + if (StringUtils.isNotEmpty(request.getMethod())) { + req.setMethod(request.getMethod()); + } + if (StringUtils.isNotEmpty(request.getPath())) { + req.setPath(request.getPath()); + } + } catch (Exception e) { + e.printStackTrace(); + LogUtil.error(e.getMessage()); } String requestStr = JSON.toJSONString(req); apiTestCase.setRequest(requestStr); batchMapper.updateByPrimaryKeySelective(apiTestCase); }); sqlSession.flushStatements(); + } } diff --git a/frontend/src/business/components/api/automation/scenario/component/ApiResponseComponent.vue b/frontend/src/business/components/api/automation/scenario/component/ApiResponseComponent.vue index ee14c107d7..8b74501e7c 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiResponseComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiResponseComponent.vue @@ -16,43 +16,43 @@