diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsJmeterParser.java b/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsJmeterParser.java index 9cd7cac04e..577f13ede5 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsJmeterParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsJmeterParser.java @@ -63,6 +63,7 @@ import org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor; import org.apache.jmeter.modifiers.JSR223PreProcessor; import org.apache.jmeter.protocol.http.control.HeaderManager; import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy; +import org.apache.jmeter.protocol.http.util.HTTPArgument; import org.apache.jmeter.protocol.http.util.HTTPFileArg; import org.apache.jmeter.protocol.java.sampler.JSR223Sampler; import org.apache.jmeter.protocol.jdbc.config.DataSourceElement; @@ -71,6 +72,7 @@ import org.apache.jmeter.protocol.tcp.sampler.TCPSampler; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.testelement.TestPlan; +import org.apache.jmeter.testelement.property.JMeterProperty; import org.apache.jmeter.timers.ConstantTimer; import org.apache.jorphan.collections.HashTree; @@ -88,6 +90,7 @@ public class MsJmeterParser extends ApiImportAbstractParser { * todo 存放单个请求下的Header 为了和平台对应 */ private Map> headerMap = new HashMap<>(); + private static final String ALWAYS_ENCODE = "HTTPArgument.always_encode"; @Override public ScenarioImport parse(InputStream inputSource, ApiTestImportRequest request) { @@ -291,16 +294,18 @@ public class MsJmeterParser extends ApiImportAbstractParser { samplerProxy.getBody().initKvs(); } else if (source.getDoMultipart()) { samplerProxy.getBody().setType(Body.FORM_DATA); - source.getArguments().getArgumentsAsMap().forEach((k, v) -> { - KeyValue keyValue = new KeyValue(k, v); + source.getArguments().getArguments().forEach(params -> { + KeyValue keyValue = new KeyValue(); + parseParams(params, keyValue); samplerProxy.getBody().getKvs().add(keyValue); }); } else if (StringUtils.isNotEmpty(bodyType) || (source.getMethod().equalsIgnoreCase("POST") && MapUtils.isNotEmpty(source.getArguments().getArgumentsAsMap()))) { samplerProxy.getBody().setType(Body.WWW_FROM); - source.getArguments().getArgumentsAsMap().forEach((k, v) -> { - KeyValue keyValue = new KeyValue(k, v); + source.getArguments().getArguments().forEach(params -> { + KeyValue keyValue = new KeyValue(); + parseParams(params, keyValue); samplerProxy.getBody().getKvs().add(keyValue); }); } else if (samplerProxy.getBody() != null && samplerProxy.getBody().getType().equals(Body.FORM_DATA)) { @@ -310,8 +315,9 @@ public class MsJmeterParser extends ApiImportAbstractParser { }); } else { List keyValues = new LinkedList<>(); - source.getArguments().getArgumentsAsMap().forEach((k, v) -> { - KeyValue keyValue = new KeyValue(k, v); + source.getArguments().getArguments().forEach(params -> { + KeyValue keyValue = new KeyValue(); + parseParams(params, keyValue); keyValues.add(keyValue); }); if (CollectionUtils.isNotEmpty(keyValues)) { @@ -337,6 +343,20 @@ public class MsJmeterParser extends ApiImportAbstractParser { } } + private void parseParams(JMeterProperty params, KeyValue keyValue) { + if (params == null || keyValue == null) { + return; + } + Object objValue = params.getObjectValue(); + if (objValue instanceof HTTPArgument) { + HTTPArgument argument = (HTTPArgument) objValue; + boolean propertyAsBoolean = argument.getPropertyAsBoolean(ALWAYS_ENCODE); + keyValue.setUrlEncode(propertyAsBoolean); + keyValue.setName(argument.getName()); + keyValue.setValue(argument.getValue()); + } + } + private void convertTCPSampler(MsTCPSampler msTCPSampler, TCPSampler tcpSampler) { msTCPSampler.setName(tcpSampler.getName()); msTCPSampler.setType("TCPSampler"); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/JmeterDefinitionParser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/JmeterDefinitionParser.java index 028e28b766..a02050aaa2 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/JmeterDefinitionParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/JmeterDefinitionParser.java @@ -55,6 +55,7 @@ import org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor; import org.apache.jmeter.modifiers.JSR223PreProcessor; import org.apache.jmeter.protocol.http.control.HeaderManager; import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy; +import org.apache.jmeter.protocol.http.util.HTTPArgument; import org.apache.jmeter.protocol.http.util.HTTPFileArg; import org.apache.jmeter.protocol.jdbc.config.DataSourceElement; import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler; @@ -62,6 +63,7 @@ import org.apache.jmeter.protocol.tcp.sampler.TCPSampler; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.testelement.TestPlan; +import org.apache.jmeter.testelement.property.JMeterProperty; import org.apache.jmeter.threads.ThreadGroup; import org.apache.jmeter.timers.ConstantTimer; import org.apache.jorphan.collections.HashTree; @@ -79,6 +81,7 @@ public class JmeterDefinitionParser extends ApiImportAbstractParser 0)) { samplerProxy.getBody().setType(Body.WWW_FROM); - source.getArguments().getArgumentsAsMap().forEach((k, v) -> { - KeyValue keyValue = new KeyValue(k, v); + source.getArguments().getArguments().forEach(params -> { + KeyValue keyValue = new KeyValue(); + parseParams(params, keyValue); samplerProxy.getBody().getKvs().add(keyValue); }); } else if (samplerProxy.getBody() != null && samplerProxy.getBody().getType().equals(Body.FORM_DATA)) { - source.getArguments().getArgumentsAsMap().forEach((k, v) -> { - KeyValue keyValue = new KeyValue(k, v); + source.getArguments().getArguments().forEach(params -> { + KeyValue keyValue = new KeyValue(); + parseParams(params, keyValue); samplerProxy.getBody().getKvs().add(keyValue); }); } else { List keyValues = new LinkedList<>(); - source.getArguments().getArgumentsAsMap().forEach((k, v) -> { - KeyValue keyValue = new KeyValue(k, v); + source.getArguments().getArguments().forEach(params -> { + KeyValue keyValue = new KeyValue(); + parseParams(params, keyValue); keyValues.add(keyValue); }); if (CollectionUtils.isNotEmpty(keyValues)) { @@ -775,6 +781,20 @@ public class JmeterDefinitionParser extends ApiImportAbstractParser headers) { if (CollectionUtils.isNotEmpty(headers)) { List keyValues = headers.stream().filter(keyValue -> "Content-Type".equals(keyValue.getName()) && "application/x-www-form-urlencoded".equals(keyValue.getValue())).collect(Collectors.toList());