diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java b/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java index 5169b0c324..11af6ae202 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java @@ -1,10 +1,13 @@ package io.metersphere.api.dto.automation.parse; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import io.metersphere.api.dto.automation.ApiScenarioModuleDTO; import io.metersphere.api.dto.definition.ApiDefinitionResult; import io.metersphere.api.dto.definition.parse.ms.NodeTree; +import io.metersphere.api.dto.definition.response.HttpResponse; +import io.metersphere.api.parse.ApiImportAbstractParser; import io.metersphere.api.service.ApiDefinitionService; import io.metersphere.api.service.ApiScenarioModuleService; import io.metersphere.api.service.ApiTestCaseService; @@ -180,7 +183,15 @@ public class ApiScenarioImportUtil { test.setId(id); test.setNum(apiDefinitionService.getNextNum(projectId)+i); test.setName(object.getString("name")); - test.setPath(object.getString("path")); + if(StringUtils.isBlank(object.getString("path"))){ + if(StringUtils.isNotBlank(object.getString("url"))){ + ApiImportAbstractParser apiImportAbstractParser = CommonBeanFactory.getBean(ApiImportAbstractParser.class); + String path = apiImportAbstractParser.formatPath(object.getString("url")); + test.setPath(path); + } + }else{ + test.setPath(object.getString("path")); + } test.setCreateUser(SessionUtils.getUserId()); test.setProjectId(projectId); test.setCreateTime(System.currentTimeMillis()); @@ -193,20 +204,12 @@ public class ApiScenarioImportUtil { object.put("resourceId", test.getId()); object.put("projectId", projectId); object.put("useEnvironment",""); + object.put("url",""); JSONObject objectNew = JSONObject.parseObject(object.toJSONString()); objectNew.remove("refType"); objectNew.remove("referenced"); test.setRequest(objectNew.toJSONString()); - JSONObject obj = new JSONObject(); - obj.put("type", object.get("protocol")); - obj.put("body", object.get("body")); - obj.put("headers", object.get("headers")); - Mapmap = new HashMap<>(); - map.put("enable", true); - List> list = new ArrayList<>(); - list.add(map); - obj.put("statusCode", list); - test.setResponse(obj.toJSONString()); + test.setResponse(JSON.toJSONString(new HttpResponse())); test.setUserId(SessionUtils.getUserId()); test.setLatest(true); test.setOrder(apiDefinitionService.getImportNextOrder(projectId)); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/MsDefinitionParser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/MsDefinitionParser.java index 5297b9e124..4abafe5a7d 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/MsDefinitionParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/MsDefinitionParser.java @@ -7,11 +7,13 @@ import io.metersphere.api.dto.ApiTestImportRequest; import io.metersphere.api.dto.definition.parse.ms.NodeTree; import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; import io.metersphere.api.dto.scenario.request.RequestType; +import io.metersphere.api.parse.ApiImportAbstractParser; import io.metersphere.api.parse.MsAbstractParser; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.base.domain.ApiModule; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.commons.constants.ApiImportPlatform; +import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.SessionUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -123,6 +125,14 @@ public class MsDefinitionParser extends MsAbstractParser { if(requestObj.get("projectId")!=null){ requestObj.put("projectId", apiDefinition.getProjectId()); } + if(StringUtils.isBlank(requestObj.getString("path"))){ + if(StringUtils.isNotBlank(requestObj.getString("url"))){ + ApiImportAbstractParser apiImportAbstractParser = CommonBeanFactory.getBean(ApiImportAbstractParser.class); + String path = apiImportAbstractParser.formatPath(requestObj.getString("url")); + requestObj.put("path",path); + } + } + requestObj.put("url",""); apiDefinition.setRequest(JSONObject.toJSONString(requestObj)); apiDefinition.setCreateUser(SessionUtils.getUserId()); apiDefinition.setUserId(SessionUtils.getUserId()); diff --git a/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java b/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java index 015e647764..72a67d5ffd 100644 --- a/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java +++ b/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java @@ -135,7 +135,7 @@ public abstract class ApiImportAbstractParser implements ApiImportParser { return apiDefinition; } - private String formatPath(String url) { + public String formatPath(String url) { try { URL urlObject = new URL(url); String path = StringUtils.isBlank(urlObject.getPath()) ? "/" : urlObject.getPath();