diff --git a/backend/src/main/java/io/metersphere/api/jmeter/JMeterVars.java b/backend/src/main/java/io/metersphere/api/jmeter/JMeterVars.java index 91dfb1edac..7d7569520e 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/JMeterVars.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/JMeterVars.java @@ -1,10 +1,12 @@ package io.metersphere.api.jmeter; +import io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample; import org.apache.jmeter.extractor.JSR223PostProcessor; import org.apache.jmeter.extractor.RegexExtractor; import org.apache.jmeter.extractor.XPath2Extractor; import org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor; import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy; +import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler; import org.apache.jmeter.threads.JMeterVariables; import org.apache.jorphan.collections.HashTree; import org.springframework.util.StringUtils; @@ -22,6 +24,7 @@ public class JMeterVars { // 线程执行过程调用提取变量值 public static void addVars(Integer testId, JMeterVariables vars, String extract) { JMeterVariables vs = new JMeterVariables(); + if (!StringUtils.isEmpty(extract) && vars != null) { List extracts = Arrays.asList(extract.split(";")); Optional.ofNullable(extracts).orElse(new ArrayList<>()).forEach(item -> { @@ -29,14 +32,15 @@ public class JMeterVars { }); vs.remove("TESTSTART.MS"); // 标示变量移除 } + variables.put(testId, vs); } - // 递归处理所有请求,对有提取变量的增加后置脚本 + // 处理所有请求,有提取变量的请求增加后置脚本提取变量值 public static void addJSR223PostProcessor(HashTree tree) { for (Object key : tree.keySet()) { HashTree node = tree.get(key); - if (key instanceof HTTPSamplerProxy) { + if (key instanceof HTTPSamplerProxy || key instanceof DubboSample || key instanceof JDBCSampler) { StringJoiner extract = new StringJoiner(";"); for (Object child : node.keySet()) { if (child instanceof RegexExtractor) { @@ -50,6 +54,7 @@ public class JMeterVars { extract.add(regexExtractor.getRefNames()); } } + if (Optional.ofNullable(extract).orElse(extract).length() > 0) { JSR223PostProcessor shell = new JSR223PostProcessor(); shell.setEnabled(true); @@ -57,6 +62,7 @@ public class JMeterVars { node.add(shell); } } + if (node != null) { addJSR223PostProcessor(node); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml index 2b2a4a80c1..306ce1e2c0 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml @@ -4,7 +4,8 @@ - + + @@ -97,7 +98,8 @@