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

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

View File

@ -234,31 +234,33 @@ public class MsHTTPSamplerProxy extends MsTestElement {
LogUtil.error(e.getMessage(), e);
}
} else {
//1.9 增加对Mock环境的判断
if (this.isMockEnvironment()) {
url = httpConfig.getProtocol() + "://" + httpConfig.getSocket() + "/mock/" + this.getProjectId();
} else {
if (httpConfig.isMock()) {
if (!isCustomizeReq()) {
//1.9 增加对Mock环境的判断
if (this.isMockEnvironment()) {
url = httpConfig.getProtocol() + "://" + httpConfig.getSocket() + "/mock/" + this.getProjectId();
} else {
url = httpConfig.getProtocol() + "://" + httpConfig.getSocket();
}
if (httpConfig.isMock()) {
url = httpConfig.getProtocol() + "://" + httpConfig.getSocket() + "/mock/" + this.getProjectId();
} else {
url = httpConfig.getProtocol() + "://" + httpConfig.getSocket();
}
}
URL urlObject = new URL(url);
String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath();
if (StringUtils.isNotBlank(this.getPath())) {
envPath += this.getPath();
}
if (StringUtils.isNotEmpty(httpConfig.getDomain())) {
sampler.setDomain(httpConfig.getDomain());
sampler.setProtocol(httpConfig.getProtocol());
} else {
sampler.setDomain("");
sampler.setProtocol("");
}
sampler.setPort(httpConfig.getPort());
sampler.setPath(envPath);
}
URL urlObject = new URL(url);
String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath();
if (StringUtils.isNotBlank(this.getPath())) {
envPath += this.getPath();
}
if (StringUtils.isNotEmpty(httpConfig.getDomain())) {
sampler.setDomain(httpConfig.getDomain());
sampler.setProtocol(httpConfig.getProtocol());
} else {
sampler.setDomain("");
sampler.setProtocol("");
}
sampler.setPort(httpConfig.getPort());
sampler.setPath(envPath);
}
String envPath = sampler.getPath();
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
@ -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,19 +80,17 @@ 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 参数
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);
}
}

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') {