fix: 自定义请求会引用环境域名

This commit is contained in:
chenjianxing 2021-05-14 19:06:02 +08:00 committed by jianxing
parent 5464588b90
commit 3b053b5cd6
3 changed files with 32 additions and 31 deletions

View File

@ -234,6 +234,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
LogUtil.error(e.getMessage(), e);
}
} else {
if (!isCustomizeReq()) {
//1.9 增加对Mock环境的判断
if (this.isMockEnvironment()) {
url = httpConfig.getProtocol() + "://" + httpConfig.getSocket() + "/mock/" + this.getProjectId();
@ -260,6 +261,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
sampler.setPort(httpConfig.getPort());
sampler.setPath(envPath);
}
}
String envPath = sampler.getPath();
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8"));
@ -267,7 +269,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
}
if (CollectionUtils.isNotEmpty(this.getArguments())) {
String path = getPostQueryParameters(URLDecoder.decode(envPath, "UTF-8"));
if (HTTPConstants.DELETE.equals(this.getMethod())) {
if (HTTPConstants.DELETE.equals(this.getMethod()) && !path.startsWith("${")) {
if (!path.startsWith("/")) {
path = "/" + path;
}

View File

@ -80,20 +80,18 @@ public class Body {
}
private void parseJonBodyMock() {
try {
if (StringUtils.isNotBlank(this.type) && StringUtils.equals(this.type, "JSON")) {
if(StringUtils.isNotEmpty(this.format) && this.getJsonSchema() != null
&& "JSON-SCHEMA".equals(this.format)) {
this.raw = JSONSchemaGenerator.getJson(com.alibaba.fastjson.JSON.toJSONString(this.getJsonSchema()));
} else { // json 文本也支持 mock 参数
try {
JSONObject jsonObject = com.alibaba.fastjson.JSON.parseObject(this.getRaw());
jsonMockParse(jsonObject);
this.raw = JSONObject.toJSONString(jsonObject);
} catch (Exception e) {}
}
}
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
}
}
private void jsonMockParse(JSONObject jsonObject) {

View File

@ -145,6 +145,7 @@
if (!this.request.projectId) {
this.request.projectId = getCurrentProjectID();
}
this.request.customizeReq = this.isCustomizeReq;
//
this.getApiInfo();
if (this.request.protocol === 'HTTP') {