fix(接口测试): 修复JSON对象格式化内容包含@type报错问题
--bug=1012064 --user=赵勇 [接口测试]github#124031.19.2,已复测,post请求,请求体json类型,当属性名称为@type,值为正常的字符串,保存出现 http 500 https://www.tapd.cn/55049933/s/1132448
This commit is contained in:
parent
80553d5eb4
commit
db866363e3
|
@ -137,7 +137,7 @@
|
|||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.72</version>
|
||||
<version>1.2.80</version>
|
||||
</dependency>
|
||||
|
||||
<!-- openapi -->
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.metersphere.api.dto.automation.parse;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import io.metersphere.api.dto.automation.ApiScenarioModuleDTO;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.parse.ms.NodeTree;
|
||||
|
@ -13,7 +14,10 @@ import io.metersphere.api.parse.ApiImportAbstractParser;
|
|||
import io.metersphere.api.service.ApiDefinitionService;
|
||||
import io.metersphere.api.service.ApiScenarioModuleService;
|
||||
import io.metersphere.api.service.ApiTestCaseService;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.domain.ApiDefinition;
|
||||
import io.metersphere.base.domain.ApiDefinitionExample;
|
||||
import io.metersphere.base.domain.ApiScenarioModule;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.base.mapper.ApiDefinitionMapper;
|
||||
import io.metersphere.base.mapper.ApiTestCaseMapper;
|
||||
import io.metersphere.commons.constants.APITestStatus;
|
||||
|
@ -22,7 +26,6 @@ import io.metersphere.commons.utils.CommonBeanFactory;
|
|||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.service.CheckPermissionService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
@ -208,7 +211,7 @@ public class ApiScenarioImportUtil {
|
|||
object.put("projectId", projectId);
|
||||
object.put("useEnvironment","");
|
||||
object.put("url","");
|
||||
JSONObject objectNew = JSONObject.parseObject(object.toJSONString());
|
||||
JSONObject objectNew = JSONObject.parseObject(object.toJSONString(), Feature.DisableSpecialKeyDetect);
|
||||
objectNew.remove("refType");
|
||||
objectNew.remove("referenced");
|
||||
test.setRequest(objectNew.toJSONString());
|
||||
|
@ -249,7 +252,7 @@ public class ApiScenarioImportUtil {
|
|||
object.put("resourceId", apiTestCase.getId());
|
||||
object.put("projectId", projectId);
|
||||
object.put("useEnvironment","");
|
||||
JSONObject objectNew = JSONObject.parseObject(object.toJSONString());
|
||||
JSONObject objectNew = JSONObject.parseObject(object.toJSONString(),Feature.DisableSpecialKeyDetect);
|
||||
objectNew.remove("refType");
|
||||
objectNew.remove("referenced");
|
||||
apiTestCase.setRequest(objectNew.toJSONString());
|
||||
|
|
|
@ -61,7 +61,7 @@ public class MsScenarioParser extends MsAbstractParser<ScenarioImport> {
|
|||
}
|
||||
|
||||
private ScenarioImport parseMsFormat(String testStr, ApiTestImportRequest importRequest) {
|
||||
ScenarioImport scenarioImport = JSON.parseObject(testStr, ScenarioImport.class);
|
||||
ScenarioImport scenarioImport = JSON.parseObject(testStr, ScenarioImport.class,Feature.DisableSpecialKeyDetect);
|
||||
List<ApiScenarioWithBLOBs> data = scenarioImport.getData();
|
||||
|
||||
Set<String> moduleIdSet = scenarioImport.getData().stream()
|
||||
|
|
|
@ -72,7 +72,7 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
|||
}
|
||||
|
||||
private ApiDefinitionImport parseMsFormat(String testStr, ApiTestImportRequest importRequest) {
|
||||
ApiDefinitionImport apiDefinitionImport = JSON.parseObject(testStr, ApiDefinitionImport.class);
|
||||
ApiDefinitionImport apiDefinitionImport = JSON.parseObject(testStr, ApiDefinitionImport.class,Feature.DisableSpecialKeyDetect);
|
||||
|
||||
Map<String, List<ApiTestCaseWithBLOBs>> caseMap = new HashMap<>();
|
||||
if (apiDefinitionImport.getCases() != null) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.api.dto.definition.parse;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
import io.metersphere.api.dto.parse.postman.PostmanCollection;
|
||||
|
@ -9,15 +10,15 @@ import io.metersphere.api.dto.parse.postman.PostmanKeyValue;
|
|||
import io.metersphere.api.parse.PostmanAbstractParserParser;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.commons.constants.ProjectApplicationType;
|
||||
import io.metersphere.dto.ProjectConfig;
|
||||
import io.metersphere.service.ProjectApplicationService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.base.domain.Project;
|
||||
import io.metersphere.base.mapper.ProjectMapper;
|
||||
import io.metersphere.commons.constants.ProjectApplicationType;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.dto.ProjectConfig;
|
||||
import io.metersphere.service.ProjectApplicationService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
@ -32,7 +33,7 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
|
|||
public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest request) {
|
||||
String testStr = getApiTestStr(source);
|
||||
this.projectId = request.getProjectId();
|
||||
PostmanCollection postmanCollection = JSON.parseObject(testStr, PostmanCollection.class);
|
||||
PostmanCollection postmanCollection = JSON.parseObject(testStr, PostmanCollection.class, Feature.DisableSpecialKeyDetect);
|
||||
List<PostmanKeyValue> variables = postmanCollection.getVariable();
|
||||
ApiDefinitionImport apiImport = new ApiDefinitionImport();
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
|
|
|
@ -3,10 +3,13 @@ package io.metersphere.api.dto.definition.parse;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.definition.ApiModuleDTO;
|
||||
import io.metersphere.api.dto.definition.SwaggerApiExportResult;
|
||||
import io.metersphere.api.dto.definition.parse.swagger.*;
|
||||
import io.metersphere.api.dto.definition.parse.swagger.SwaggerApiInfo;
|
||||
import io.metersphere.api.dto.definition.parse.swagger.SwaggerInfo;
|
||||
import io.metersphere.api.dto.definition.parse.swagger.SwaggerParams;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
import io.metersphere.api.dto.definition.request.variable.JsonSchemaItem;
|
||||
import io.metersphere.api.dto.definition.response.HttpResponse;
|
||||
|
@ -33,6 +36,7 @@ import org.apache.commons.collections.CollectionUtils;
|
|||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -594,17 +598,17 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
}
|
||||
swaggerApiInfo.setTags(Arrays.asList(moduleName));
|
||||
// 设置请求体
|
||||
JSONObject requestObject = JSON.parseObject(apiDefinition.getRequest()); // 将api的request属性转换成JSON对象以便获得参数
|
||||
JSONObject requestObject = JSON.parseObject(apiDefinition.getRequest(), Feature.DisableSpecialKeyDetect); // 将api的request属性转换成JSON对象以便获得参数
|
||||
JSONObject requestBody = buildRequestBody(requestObject);
|
||||
swaggerApiInfo.setRequestBody(requestBody);
|
||||
// 设置响应体
|
||||
JSONObject responseObject = JSON.parseObject(apiDefinition.getResponse());
|
||||
JSONObject responseObject = JSON.parseObject(apiDefinition.getResponse(),Feature.DisableSpecialKeyDetect);
|
||||
swaggerApiInfo.setResponses(buildResponseBody(responseObject));
|
||||
// 设置请求参数列表
|
||||
List<JSONObject> paramsList = buildParameters(requestObject);
|
||||
swaggerApiInfo.setParameters(paramsList);
|
||||
swaggerApiInfo.setDescription(apiDefinition.getDescription());
|
||||
JSONObject methodDetail = JSON.parseObject(JSON.toJSONString(swaggerApiInfo));
|
||||
JSONObject methodDetail = JSON.parseObject(JSON.toJSONString(swaggerApiInfo),Feature.DisableSpecialKeyDetect);
|
||||
if (paths.getJSONObject(apiDefinition.getPath()) == null) {
|
||||
paths.put(apiDefinition.getPath(), new JSONObject());
|
||||
} // 一个路径下有多个发方法,如post,get,因此是一个 JSONObject 类型
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.metersphere.api.dto.definition.request;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -302,7 +303,7 @@ public class ElementUtil {
|
|||
}
|
||||
if (element.get("clazzName") == null && element.getString("type").equals("TCPSampler")) {
|
||||
if (element.getString("tcpPreProcessor") != null) {
|
||||
JSONObject tcpPreProcessor = JSON.parseObject(element.getString("tcpPreProcessor"));
|
||||
JSONObject tcpPreProcessor = JSON.parseObject(element.getString("tcpPreProcessor"), Feature.DisableSpecialKeyDetect);
|
||||
if (tcpPreProcessor != null && tcpPreProcessor.get("clazzName") == null) {
|
||||
tcpPreProcessor.fluentPut("clazzName", clazzMap.get(tcpPreProcessor.getString("type")));
|
||||
element.fluentPut("tcpPreProcessor", tcpPreProcessor);
|
||||
|
@ -310,7 +311,7 @@ public class ElementUtil {
|
|||
}
|
||||
} else if (element.getString("type").equals("HTTPSamplerProxy")) {
|
||||
if (element.getString("authManager") != null) {
|
||||
JSONObject authManager = JSON.parseObject(element.getString("authManager"));
|
||||
JSONObject authManager = JSON.parseObject(element.getString("authManager"),Feature.DisableSpecialKeyDetect);
|
||||
if (authManager != null && authManager.get("clazzName") == null) {
|
||||
authManager.fluentPut("clazzName", clazzMap.get(authManager.getString("type")));
|
||||
element.fluentPut("authManager", authManager);
|
||||
|
@ -388,7 +389,7 @@ public class ElementUtil {
|
|||
if (StringUtils.equals(environmentType, EnvironmentType.GROUP.name())) {
|
||||
environmentMap = environmentGroupProjectService.getEnvMap(environmentGroupId);
|
||||
} else if (StringUtils.equals(environmentType, EnvironmentType.JSON.name())) {
|
||||
environmentMap = JSON.parseObject(environmentJson, Map.class);
|
||||
environmentMap = JSON.parseObject(environmentJson, Map.class,Feature.DisableSpecialKeyDetect);
|
||||
}
|
||||
Map<String, EnvironmentConfig> envConfig = new HashMap<>(16);
|
||||
if (environmentMap != null && !environmentMap.isEmpty()) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.fastjson.annotation.JSONType;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -216,7 +217,7 @@ public class MsScenario extends MsTestElement {
|
|||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
ApiScenarioWithBLOBs scenario = apiAutomationService.selectByPrimaryKey(this.getId());
|
||||
if (scenario != null && StringUtils.isNotEmpty(scenario.getScenarioDefinition())) {
|
||||
JSONObject element = JSON.parseObject(scenario.getScenarioDefinition());
|
||||
JSONObject element = JSON.parseObject(scenario.getScenarioDefinition(), Feature.DisableSpecialKeyDetect);
|
||||
// 历史数据处理
|
||||
ElementUtil.dataFormatting(element.getJSONArray("hashTree"));
|
||||
this.setName(scenario.getName());
|
||||
|
@ -260,7 +261,7 @@ public class MsScenario extends MsTestElement {
|
|||
if (StringUtils.equals(environmentType, EnvironmentType.GROUP.name())) {
|
||||
this.environmentMap = environmentGroupProjectService.getEnvMap(environmentGroupId);
|
||||
} else if (StringUtils.equals(environmentType, EnvironmentType.JSON.name())) {
|
||||
this.environmentMap = JSON.parseObject(environmentJson, Map.class);
|
||||
this.environmentMap = JSON.parseObject(environmentJson, Map.class,Feature.DisableSpecialKeyDetect);
|
||||
}
|
||||
} else {
|
||||
this.setEnvironmentEnable(false);
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.fastjson.annotation.JSONType;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -182,7 +183,7 @@ public class MsJDBCPostProcessor extends MsTestElement {
|
|||
if (bloBs != null) {
|
||||
this.setName(bloBs.getName());
|
||||
this.setProjectId(bloBs.getProjectId());
|
||||
JSONObject element = JSON.parseObject(bloBs.getRequest());
|
||||
JSONObject element = JSON.parseObject(bloBs.getRequest(), Feature.DisableSpecialKeyDetect);
|
||||
ElementUtil.dataFormatting(element);
|
||||
proxy = mapper.readValue(element.toJSONString(), new TypeReference<MsJDBCPostProcessor>() {
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.fastjson.annotation.JSONType;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -182,7 +183,7 @@ public class MsJDBCPreProcessor extends MsTestElement {
|
|||
if (bloBs != null) {
|
||||
this.setName(bloBs.getName());
|
||||
this.setProjectId(bloBs.getProjectId());
|
||||
JSONObject element = JSON.parseObject(bloBs.getRequest());
|
||||
JSONObject element = JSON.parseObject(bloBs.getRequest(), Feature.DisableSpecialKeyDetect);
|
||||
ElementUtil.dataFormatting(element);
|
||||
proxy = mapper.readValue(element.toJSONString(), new TypeReference<MsJDBCPreProcessor>() {
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.fastjson.annotation.JSONType;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
|
@ -116,7 +117,7 @@ public class MsDubboSampler extends MsTestElement {
|
|||
ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId());
|
||||
if (bloBs != null) {
|
||||
this.setProjectId(bloBs.getProjectId());
|
||||
JSONObject element = JSON.parseObject(bloBs.getRequest());
|
||||
JSONObject element = JSON.parseObject(bloBs.getRequest(), Feature.DisableSpecialKeyDetect);
|
||||
ElementUtil.dataFormatting(element);
|
||||
proxy = mapper.readValue(element.toJSONString(), new TypeReference<MsDubboSampler>() {
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.fastjson.annotation.JSONType;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -289,7 +290,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
ApiTestCaseWithBLOBs bloBs = CommonBeanFactory.getBean(ApiTestCaseService.class).get(this.getId());
|
||||
if (bloBs != null) {
|
||||
this.setProjectId(bloBs.getProjectId());
|
||||
JSONObject element = JSON.parseObject(bloBs.getRequest());
|
||||
JSONObject element = JSON.parseObject(bloBs.getRequest(), Feature.DisableSpecialKeyDetect);
|
||||
ElementUtil.dataFormatting(element);
|
||||
proxy = mapper.readValue(element.toJSONString(), new TypeReference<MsHTTPSamplerProxy>() {
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.fastjson.annotation.JSONType;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -240,7 +241,7 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
if (bloBs != null) {
|
||||
this.setName(bloBs.getName());
|
||||
this.setProjectId(bloBs.getProjectId());
|
||||
JSONObject element = JSON.parseObject(bloBs.getRequest());
|
||||
JSONObject element = JSON.parseObject(bloBs.getRequest(), Feature.DisableSpecialKeyDetect);
|
||||
ElementUtil.dataFormatting(element);
|
||||
proxy = mapper.readValue(element.toJSONString(), new TypeReference<MsJDBCSampler>() {
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.fastjson.annotation.JSONType;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -195,7 +196,7 @@ public class MsTCPSampler extends MsTestElement {
|
|||
if (bloBs != null) {
|
||||
this.setName(bloBs.getName());
|
||||
this.setProjectId(bloBs.getProjectId());
|
||||
JSONObject element = JSON.parseObject(bloBs.getRequest());
|
||||
JSONObject element = JSON.parseObject(bloBs.getRequest(), Feature.DisableSpecialKeyDetect);
|
||||
ElementUtil.dataFormatting(element);
|
||||
proxy = mapper.readValue(element.toJSONString(), new TypeReference<MsTCPSampler>() {
|
||||
});
|
||||
|
|
|
@ -97,7 +97,7 @@ public class Body {
|
|||
} else {
|
||||
try {
|
||||
if (StringUtils.isNotEmpty(this.getRaw())) {
|
||||
JSONObject jsonObject = JSON.parseObject(this.getRaw(), Feature.OrderedField);
|
||||
JSONObject jsonObject = JSON.parseObject(this.getRaw(), Feature.OrderedField,Feature.DisableSpecialKeyDetect);
|
||||
if (!this.getRaw().contains("$ref")) {
|
||||
jsonMockParse(jsonObject);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.api.exec.api;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.metersphere.api.dto.definition.RunCaseRequest;
|
||||
|
@ -192,7 +193,7 @@ public class ApiExecuteService {
|
|||
}
|
||||
|
||||
public HashTree generateHashTree(RunCaseRequest request, ApiTestCaseWithBLOBs testCaseWithBLOBs) throws Exception {
|
||||
JSONObject elementObj = JSON.parseObject(testCaseWithBLOBs.getRequest());
|
||||
JSONObject elementObj = JSON.parseObject(testCaseWithBLOBs.getRequest(), Feature.DisableSpecialKeyDetect);
|
||||
ElementUtil.dataFormatting(elementObj);
|
||||
|
||||
MsTestElement element = mapper.readValue(elementObj.toJSONString(), new TypeReference<MsTestElement>() {
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.api.exec.scenario;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -177,7 +178,7 @@ public class ApiScenarioEnvService {
|
|||
if (apiScenario != null) {
|
||||
env.getProjectIds().add(apiScenario.getProjectId());
|
||||
String scenarioDefinition = apiScenario.getScenarioDefinition();
|
||||
JSONObject element1 = JSON.parseObject(scenarioDefinition);
|
||||
JSONObject element1 = JSON.parseObject(scenarioDefinition, Feature.DisableSpecialKeyDetect);
|
||||
ElementUtil.dataFormatting(element1);
|
||||
LinkedList<MsTestElement> hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>() {
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.api.exec.scenario;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||
|
@ -194,7 +195,7 @@ public class ApiScenarioSerialService {
|
|||
private MsTestElement parse(ApiTestCaseWithBLOBs caseWithBLOBs, String planId, String envId) {
|
||||
try {
|
||||
String api = caseWithBLOBs.getRequest();
|
||||
JSONObject element = JSON.parseObject(api);
|
||||
JSONObject element = JSON.parseObject(api, Feature.DisableSpecialKeyDetect);
|
||||
ElementUtil.dataFormatting(element);
|
||||
|
||||
LinkedList<MsTestElement> list = new LinkedList<>();
|
||||
|
@ -205,7 +206,7 @@ public class ApiScenarioSerialService {
|
|||
list.addAll(elements);
|
||||
}
|
||||
if (element.getString("type").equals("HTTPSamplerProxy")) {
|
||||
MsHTTPSamplerProxy httpSamplerProxy = JSON.parseObject(api, MsHTTPSamplerProxy.class);
|
||||
MsHTTPSamplerProxy httpSamplerProxy = JSON.parseObject(api, MsHTTPSamplerProxy.class,Feature.DisableSpecialKeyDetect);
|
||||
httpSamplerProxy.setHashTree(list);
|
||||
httpSamplerProxy.setName(planId);
|
||||
if (StringUtils.isNotEmpty(envId)) {
|
||||
|
@ -214,7 +215,7 @@ public class ApiScenarioSerialService {
|
|||
return httpSamplerProxy;
|
||||
}
|
||||
if (element.getString("type").equals("TCPSampler")) {
|
||||
MsTCPSampler msTCPSampler = JSON.parseObject(api, MsTCPSampler.class);
|
||||
MsTCPSampler msTCPSampler = JSON.parseObject(api, MsTCPSampler.class,Feature.DisableSpecialKeyDetect);
|
||||
if (StringUtils.isNotEmpty(envId)) {
|
||||
msTCPSampler.setUseEnvironment(envId);
|
||||
}
|
||||
|
@ -223,7 +224,7 @@ public class ApiScenarioSerialService {
|
|||
return msTCPSampler;
|
||||
}
|
||||
if (element.getString("type").equals("DubboSampler")) {
|
||||
MsDubboSampler dubboSampler = JSON.parseObject(api, MsDubboSampler.class);
|
||||
MsDubboSampler dubboSampler = JSON.parseObject(api, MsDubboSampler.class,Feature.DisableSpecialKeyDetect);
|
||||
if (StringUtils.isNotEmpty(envId)) {
|
||||
dubboSampler.setUseEnvironment(envId);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.api.exec.utils;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
|
@ -38,7 +39,7 @@ public class GenerateHashTreeUtil {
|
|||
|
||||
public static MsScenario parseScenarioDefinition(String scenarioDefinition) {
|
||||
if (StringUtils.isNotEmpty(scenarioDefinition)) {
|
||||
MsScenario scenario = JSONObject.parseObject(scenarioDefinition, MsScenario.class);
|
||||
MsScenario scenario = JSONObject.parseObject(scenarioDefinition, MsScenario.class, Feature.DisableSpecialKeyDetect);
|
||||
if (scenario != null) {
|
||||
parse(scenarioDefinition, scenario);
|
||||
}
|
||||
|
@ -51,7 +52,7 @@ public class GenerateHashTreeUtil {
|
|||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
try {
|
||||
JSONObject element = JSON.parseObject(scenarioDefinition);
|
||||
JSONObject element = JSON.parseObject(scenarioDefinition, Feature.DisableSpecialKeyDetect);
|
||||
ElementUtil.dataFormatting(element);
|
||||
// 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取
|
||||
if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) {
|
||||
|
@ -74,7 +75,7 @@ public class GenerateHashTreeUtil {
|
|||
public static LinkedList<MsTestElement> getScenarioHashTree(String definition) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
JSONObject element = JSON.parseObject(definition);
|
||||
JSONObject element = JSON.parseObject(definition, Feature.DisableSpecialKeyDetect);
|
||||
try {
|
||||
if (element != null) {
|
||||
ElementUtil.dataFormatting(element);
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.api.jmeter;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import io.metersphere.commons.constants.DelimiterConstants;
|
||||
import io.metersphere.dto.RequestResult;
|
||||
import lombok.Data;
|
||||
|
@ -135,7 +136,7 @@ public class TestResult {
|
|||
String itemAndScenarioName = "";
|
||||
if (StringUtils.isNotEmpty(item.getScenario())) {
|
||||
//第1个:当前场景, 第all_id_names个:最后一层场景
|
||||
List<String> all_id_names = JSON.parseObject(item.getScenario(), List.class);
|
||||
List<String> all_id_names = JSON.parseObject(item.getScenario(), List.class, Feature.DisableSpecialKeyDetect);
|
||||
if (all_id_names.size() > 1) {
|
||||
StringBuffer scenarioNames = new StringBuffer();
|
||||
//因为要进行步骤统计,第一层级下的场景算作步骤,所以统计视角只按照第一级别场景来计算
|
||||
|
|
|
@ -18,7 +18,7 @@ public class MsParser extends ApiImportAbstractParser {
|
|||
@Override
|
||||
public ApiImport parse(InputStream source, ApiTestImportRequest request) {
|
||||
String testStr = getApiTestStr(source);
|
||||
ApiImport apiImport = JSON.parseObject(parsePluginFormat(testStr), ApiImport.class);
|
||||
ApiImport apiImport = JSON.parseObject(parsePluginFormat(testStr), ApiImport.class,Feature.DisableSpecialKeyDetect);
|
||||
apiImport.getScenarios().forEach(scenario -> setScenarioByRequest(scenario, request));
|
||||
return apiImport;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class MsParser extends ApiImportAbstractParser {
|
|||
@Override
|
||||
public ApiDefinitionImport parseApi(InputStream source, ApiTestImportRequest request) {
|
||||
String testStr = getApiTestStr(source);
|
||||
ApiDefinitionImport apiImport = JSON.parseObject(testStr, ApiDefinitionImport.class);
|
||||
ApiDefinitionImport apiImport = JSON.parseObject(testStr, ApiDefinitionImport.class,Feature.DisableSpecialKeyDetect);
|
||||
return apiImport;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2,6 +2,7 @@ package io.metersphere.api.service;
|
|||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import io.metersphere.base.domain.ApiScenarioReferenceId;
|
||||
import io.metersphere.base.domain.ApiScenarioReferenceIdExample;
|
||||
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
||||
|
@ -55,7 +56,7 @@ public class ApiScenarioReferenceIdService {
|
|||
this.deleteByScenarioId(scenario.getId());
|
||||
Map<String, ApiScenarioReferenceId> referenceIdMap = new HashMap<>();
|
||||
if (StringUtils.isNotEmpty(scenario.getScenarioDefinition())) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(scenario.getScenarioDefinition());
|
||||
JSONObject jsonObject = JSONObject.parseObject(scenario.getScenarioDefinition(), Feature.DisableSpecialKeyDetect);
|
||||
if (!jsonObject.containsKey(MsHashTreeService.HASH_TREE)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.metersphere.api.service;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import io.metersphere.api.dto.ApiScenarioReportDTO;
|
||||
import io.metersphere.api.dto.RequestResultExpandDTO;
|
||||
import io.metersphere.api.dto.StepTreeDTO;
|
||||
|
@ -84,7 +85,7 @@ public class ApiScenarioReportStructureService {
|
|||
}
|
||||
|
||||
public static StepTreeDTO dataFormatting(ApiScenarioWithBLOBs apiScenario, String reportType) {
|
||||
JSONObject element = JSON.parseObject(apiScenario.getScenarioDefinition());
|
||||
JSONObject element = JSON.parseObject(apiScenario.getScenarioDefinition(), Feature.DisableSpecialKeyDetect);
|
||||
StepTreeDTO dto = null;
|
||||
if (element != null && element.getBoolean("enable")) {
|
||||
element = getRefElement(element);
|
||||
|
@ -112,7 +113,7 @@ public class ApiScenarioReportStructureService {
|
|||
if (StringUtils.equals(element.getString("type"), "scenario")) {
|
||||
ApiScenarioWithBLOBs scenarioWithBLOBs = CommonBeanFactory.getBean(ApiScenarioMapper.class).selectByPrimaryKey(element.getString("id"));
|
||||
if (scenarioWithBLOBs != null) {
|
||||
return JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition());
|
||||
return JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition(),Feature.DisableSpecialKeyDetect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -246,18 +247,18 @@ public class ApiScenarioReportStructureService {
|
|||
if (reportResults.size() > 1) {
|
||||
for (int i = 0; i < reportResults.size(); i++) {
|
||||
if (i == 0) {
|
||||
dto.setValue(JSON.parseObject(new String(reportResults.get(i).getContent(), StandardCharsets.UTF_8), RequestResult.class));
|
||||
dto.setValue(JSON.parseObject(new String(reportResults.get(i).getContent(), StandardCharsets.UTF_8), RequestResult.class,Feature.DisableSpecialKeyDetect));
|
||||
dto.setErrorCode(reportResults.get(0).getErrorCode());
|
||||
} else {
|
||||
StepTreeDTO step = new StepTreeDTO(dto.getLabel(), UUID.randomUUID().toString(), dto.getType(), (i + 1));
|
||||
step.setValue(JSON.parseObject(new String(reportResults.get(i).getContent(), StandardCharsets.UTF_8), RequestResult.class));
|
||||
step.setValue(JSON.parseObject(new String(reportResults.get(i).getContent(), StandardCharsets.UTF_8), RequestResult.class,Feature.DisableSpecialKeyDetect));
|
||||
step.setErrorCode(reportResults.get(i).getErrorCode());
|
||||
dtoList.add(step);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String content = new String(reportResults.get(0).getContent(), StandardCharsets.UTF_8);
|
||||
dto.setValue(JSON.parseObject(content, RequestResult.class));
|
||||
dto.setValue(JSON.parseObject(content, RequestResult.class,Feature.DisableSpecialKeyDetect));
|
||||
dto.setErrorCode(reportResults.get(0).getErrorCode());
|
||||
}
|
||||
}
|
||||
|
@ -385,10 +386,10 @@ public class ApiScenarioReportStructureService {
|
|||
BeanUtils.copyBean(vo, item);
|
||||
if (StringUtils.isNotEmpty(item.getContent())) {
|
||||
try {
|
||||
RequestResultExpandDTO resultExpandDTO = JSON.parseObject(item.getContent(), RequestResultExpandDTO.class);
|
||||
RequestResultExpandDTO resultExpandDTO = JSON.parseObject(item.getContent(), RequestResultExpandDTO.class,Feature.DisableSpecialKeyDetect);
|
||||
vo.setRequestResult(resultExpandDTO);
|
||||
} catch (Exception e) {
|
||||
vo.setRequestResult(JSON.parseObject(item.getContent(), RequestResult.class));
|
||||
vo.setRequestResult(JSON.parseObject(item.getContent(), RequestResult.class,Feature.DisableSpecialKeyDetect));
|
||||
}
|
||||
if (vo.getRequestResult() != null) {
|
||||
vo.setPassAssertions(vo.getRequestResult().getPassAssertions());
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.api.service;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.metersphere.api.dto.ApiCaseEditRequest;
|
||||
|
@ -705,7 +706,7 @@ public class ApiTestCaseService {
|
|||
ApiTestCaseMapper batchMapper = sqlSession.getMapper(ApiTestCaseMapper.class);
|
||||
|
||||
bloBs.forEach(apiTestCase -> {
|
||||
JSONObject req = JSON.parseObject(apiTestCase.getRequest());
|
||||
JSONObject req = JSON.parseObject(apiTestCase.getRequest(), Feature.DisableSpecialKeyDetect);
|
||||
req.put("useEnvironment", request.getEnvId());
|
||||
String requestStr = JSON.toJSONString(req);
|
||||
apiTestCase.setRequest(requestStr);
|
||||
|
@ -727,9 +728,9 @@ public class ApiTestCaseService {
|
|||
ApiTestCaseMapper batchMapper = sqlSession.getMapper(ApiTestCaseMapper.class);
|
||||
|
||||
bloBs.forEach(apiTestCase -> {
|
||||
MsHTTPSamplerProxy req = JSON.parseObject(apiTestCase.getRequest(), MsHTTPSamplerProxy.class);
|
||||
MsHTTPSamplerProxy req = JSON.parseObject(apiTestCase.getRequest(), MsHTTPSamplerProxy.class,Feature.DisableSpecialKeyDetect);
|
||||
try {
|
||||
JSONObject element = JSON.parseObject(apiTestCase.getRequest());
|
||||
JSONObject element = JSON.parseObject(apiTestCase.getRequest(),Feature.DisableSpecialKeyDetect);
|
||||
ElementUtil.dataFormatting(element);
|
||||
|
||||
if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.metersphere.api.service;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import io.metersphere.api.dto.automation.ApiScenarioDTO;
|
||||
import io.metersphere.api.dto.datacount.ApiMethodUrlDTO;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
|
@ -77,7 +78,7 @@ public class MsHashTreeService {
|
|||
if (refType.equals(CASE)) {
|
||||
ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(object.getString(ID));
|
||||
if (bloBs != null) {
|
||||
object = JSON.parseObject(bloBs.getRequest());
|
||||
object = JSON.parseObject(bloBs.getRequest(), Feature.DisableSpecialKeyDetect);
|
||||
object.put(ID, bloBs.getId());
|
||||
object.put(NAME, bloBs.getName());
|
||||
hashTree.set(i, object);
|
||||
|
@ -85,14 +86,14 @@ public class MsHashTreeService {
|
|||
} else {
|
||||
ApiScenarioWithBLOBs bloBs = apiScenarioMapper.selectByPrimaryKey(object.getString(ID));
|
||||
if (bloBs != null) {
|
||||
object = JSON.parseObject(bloBs.getScenarioDefinition());
|
||||
object = JSON.parseObject(bloBs.getScenarioDefinition(),Feature.DisableSpecialKeyDetect);
|
||||
hashTree.set(i, object);
|
||||
}
|
||||
}
|
||||
} else if (SCENARIO.equals(object.getString(TYPE))) {
|
||||
ApiScenarioWithBLOBs bloBs = apiScenarioMapper.selectByPrimaryKey(object.getString(ID));
|
||||
if (bloBs != null) {
|
||||
object = JSON.parseObject(bloBs.getScenarioDefinition());
|
||||
object = JSON.parseObject(bloBs.getScenarioDefinition(),Feature.DisableSpecialKeyDetect);
|
||||
hashTree.set(i, object);
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +183,7 @@ public class MsHashTreeService {
|
|||
ApiTestCaseInfo apiTestCase = apiTestCaseService.get(element.getString(ID));
|
||||
if (apiTestCase != null) {
|
||||
if (StringUtils.equalsIgnoreCase(element.getString(REFERENCED), REF)) {
|
||||
JSONObject refElement = JSON.parseObject(apiTestCase.getRequest());
|
||||
JSONObject refElement = JSON.parseObject(apiTestCase.getRequest(),Feature.DisableSpecialKeyDetect);
|
||||
ElementUtil.dataFormatting(refElement);
|
||||
JSONArray array = refElement.getJSONArray(HASH_TREE);
|
||||
ElementUtil.copyBean(element, refElement);
|
||||
|
@ -255,7 +256,7 @@ public class MsHashTreeService {
|
|||
? element.getBoolean(VARIABLE_ENABLE) : true;
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(element.getString(REFERENCED), REF)) {
|
||||
element = JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition());
|
||||
element = JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition(),Feature.DisableSpecialKeyDetect);
|
||||
element.put(REFERENCED, REF);
|
||||
element.put(NAME, scenarioWithBLOBs.getName());
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package io.metersphere.log.aspect;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import io.metersphere.base.domain.OperatingLogWithBLOBs;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.log.annotation.MsAuditLog;
|
||||
import io.metersphere.log.service.OperatingLogService;
|
||||
import io.metersphere.log.utils.ReflexObjectUtil;
|
||||
|
@ -188,7 +188,7 @@ public class MsLogAspect {
|
|||
String content = expression.getValue(context, String.class);
|
||||
try {
|
||||
if (StringUtils.isNotEmpty(content)) {
|
||||
OperatingLogDetails details = JSON.parseObject(content, OperatingLogDetails.class);
|
||||
OperatingLogDetails details = JSON.parseObject(content, OperatingLogDetails.class, Feature.DisableSpecialKeyDetect);
|
||||
if (StringUtils.isNotEmpty(details.getProjectId())) {
|
||||
msOperLog.setProjectId(details.getProjectId());
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ public class MsLogAspect {
|
|||
msOperLog.setCreateUser(details.getCreateUser());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(content) && StringUtils.isNotEmpty(msLog.beforeValue())) {
|
||||
OperatingLogDetails details = JSON.parseObject(content, OperatingLogDetails.class);
|
||||
OperatingLogDetails details = JSON.parseObject(content, OperatingLogDetails.class,Feature.DisableSpecialKeyDetect);
|
||||
List<DetailColumn> columns = ReflexObjectUtil.compared(JSON.parseObject(msLog.beforeValue(), OperatingLogDetails.class), details, msLog.module());
|
||||
details.setColumns(columns);
|
||||
msOperLog.setOperContent(JSON.toJSONString(details));
|
||||
|
|
Loading…
Reference in New Issue