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,6 +234,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
LogUtil.error(e.getMessage(), e); LogUtil.error(e.getMessage(), e);
} }
} else { } else {
if (!isCustomizeReq()) {
//1.9 增加对Mock环境的判断 //1.9 增加对Mock环境的判断
if (this.isMockEnvironment()) { if (this.isMockEnvironment()) {
url = httpConfig.getProtocol() + "://" + httpConfig.getSocket() + "/mock/" + this.getProjectId(); url = httpConfig.getProtocol() + "://" + httpConfig.getSocket() + "/mock/" + this.getProjectId();
@ -260,6 +261,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
sampler.setPort(httpConfig.getPort()); sampler.setPort(httpConfig.getPort());
sampler.setPath(envPath); 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()) {
envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8")); envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8"));
@ -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,20 +80,18 @@ 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);
}
} }
private void jsonMockParse(JSONObject jsonObject) { private void jsonMockParse(JSONObject jsonObject) {

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