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); LogUtil.error(e.getMessage(), e);
} }
} else { } else {
//1.9 增加对Mock环境的判断 if (!isCustomizeReq()) {
if (this.isMockEnvironment()) { //1.9 增加对Mock环境的判断
url = httpConfig.getProtocol() + "://" + httpConfig.getSocket() + "/mock/" + this.getProjectId(); if (this.isMockEnvironment()) {
} else {
if (httpConfig.isMock()) {
url = httpConfig.getProtocol() + "://" + httpConfig.getSocket() + "/mock/" + this.getProjectId(); url = httpConfig.getProtocol() + "://" + httpConfig.getSocket() + "/mock/" + this.getProjectId();
} else { } 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(); String envPath = sampler.getPath();
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) { if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
@ -267,7 +269,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
} }
if (CollectionUtils.isNotEmpty(this.getArguments())) { if (CollectionUtils.isNotEmpty(this.getArguments())) {
String path = getPostQueryParameters(URLDecoder.decode(envPath, "UTF-8")); 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("/")) { if (!path.startsWith("/")) {
path = "/" + path; path = "/" + path;
} }

View File

@ -80,19 +80,17 @@ public class Body {
} }
private void parseJonBodyMock() { private void parseJonBodyMock() {
try { if (StringUtils.isNotBlank(this.type) && StringUtils.equals(this.type, "JSON")) {
if (StringUtils.isNotBlank(this.type) && StringUtils.equals(this.type, "JSON")) { if(StringUtils.isNotEmpty(this.format) && this.getJsonSchema() != null
if(StringUtils.isNotEmpty(this.format) && this.getJsonSchema() != null && "JSON-SCHEMA".equals(this.format)) {
&& "JSON-SCHEMA".equals(this.format)) { this.raw = JSONSchemaGenerator.getJson(com.alibaba.fastjson.JSON.toJSONString(this.getJsonSchema()));
this.raw = JSONSchemaGenerator.getJson(com.alibaba.fastjson.JSON.toJSONString(this.getJsonSchema())); } else { // json 文本也支持 mock 参数
} else { // json 文本也支持 mock 参数 try {
JSONObject jsonObject = com.alibaba.fastjson.JSON.parseObject(this.getRaw()); JSONObject jsonObject = com.alibaba.fastjson.JSON.parseObject(this.getRaw());
jsonMockParse(jsonObject); jsonMockParse(jsonObject);
this.raw = JSONObject.toJSONString(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) { if (!this.request.projectId) {
this.request.projectId = getCurrentProjectID(); this.request.projectId = getCurrentProjectID();
} }
this.request.customizeReq = this.isCustomizeReq;
// //
this.getApiInfo(); this.getApiInfo();
if (this.request.protocol === 'HTTP') { if (this.request.protocol === 'HTTP') {