fix(接口测试): 修复jmx文件请求头解析的问题

--bug=1046513 --user=宋天阳 【接口测试】定义-导入jmeter接口文件-导入信息请求头错误 https://www.tapd.cn/55049933/s/1579922
This commit is contained in:
Jianguo-Genius 2024-09-18 15:49:21 +08:00 committed by Craftsman
parent 3b9bce189a
commit 7d2fa6ae0d
3 changed files with 14 additions and 3 deletions

View File

@ -504,6 +504,7 @@
api_definition.num like concat('%', #{request.condition.keyword},'%')
or api_definition.name like concat('%', #{request.condition.keyword},'%')
or api_definition.tags like concat('%', #{request.condition.keyword},'%')
or api_definition.path like concat('%', #{request.condition.keyword},'%')
)
</if>
<include refid="filters">

View File

@ -363,8 +363,9 @@ public class HarParserApiDefinition extends HttpApiDefinitionImportAbstractParse
if (StringUtils.equalsIgnoreCase("GET", requestBody.method) || requestBody.postData == null) {
return;
}
String bodyType = Body.BodyType.NONE.name();
String bodyType = content.mimeType;
if (StringUtils.isEmpty(bodyType)) {
bodyType = Body.BodyType.RAW.name();
body.setRawBody(new RawBody() {{
this.setValue(content.text);
}});

View File

@ -4,6 +4,7 @@ import io.metersphere.api.dto.request.http.MsHTTPElement;
import io.metersphere.api.dto.request.http.MsHeader;
import io.metersphere.plugin.api.spi.AbstractMsElementConverter;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import jodd.util.StringUtil;
import org.apache.jmeter.protocol.http.control.HeaderManager;
import org.apache.jmeter.testelement.property.CollectionProperty;
import org.apache.jmeter.testelement.property.JMeterProperty;
@ -23,10 +24,18 @@ public class HeaderManagerConverter extends AbstractMsElementConverter<HeaderMan
for (int i = 0; i < collectionProperty.size(); i++) {
JMeterProperty jMeterProperty = collectionProperty.get(i);
String key = jMeterProperty.getName();
String value = jMeterProperty.getStringValue();
if (StringUtil.isEmpty(key)) {
String[] valueArr = value.split("\t");
key = valueArr[0];
value = valueArr[1];
}
if (!extendsHeaderKey.contains(key)) {
String finalKey = key;
String finalValue = value;
headerKvList.add(new MsHeader() {{
this.setKey(key);
this.setValue(jMeterProperty.getStringValue());
this.setKey(finalKey);
this.setValue(finalValue);
}});
}
}