diff --git a/backend/src/main/java/org/apache/jmeter/extractor/RegexExtractor.java b/backend/src/main/java/org/apache/jmeter/extractor/RegexExtractor.java index 356b19ba1d..606a77d652 100644 --- a/backend/src/main/java/org/apache/jmeter/extractor/RegexExtractor.java +++ b/backend/src/main/java/org/apache/jmeter/extractor/RegexExtractor.java @@ -83,7 +83,6 @@ public class RegexExtractor extends AbstractScopedTestElement implements PostPro private transient List template; - private JMeterVariables regexVars; /** * Parses the response data using regular expressions and saving the results * into variables for use later in the test. @@ -93,7 +92,6 @@ public class RegexExtractor extends AbstractScopedTestElement implements PostPro @Override public void process() { initTemplate(); - regexVars = new JMeterVariables(); JMeterContext context = getThreadContext(); SampleResult previousResult = context.getPreviousResult(); if (previousResult == null) { @@ -109,7 +107,6 @@ public class RegexExtractor extends AbstractScopedTestElement implements PostPro final String defaultValue = getDefaultValue(); if (defaultValue.length() > 0 || isEmptyDefaultValue()) {// Only replace default if it is provided or empty default value is explicitly requested vars.put(refName, defaultValue); - regexVars.put(refName, defaultValue); } Perl5Matcher matcher = JMeterUtils.getMatcher(); @@ -135,8 +132,6 @@ public class RegexExtractor extends AbstractScopedTestElement implements PostPro match = getCorrectMatch(matches, matchNumber); if (match != null) { vars.put(refName, generateResult(match)); - regexVars.put(refName, generateResult(match)); - saveGroups(vars, refName, match); } else { // refname has already been set to the default (if present) @@ -147,15 +142,11 @@ public class RegexExtractor extends AbstractScopedTestElement implements PostPro removeGroups(vars, refName); // remove any single matches matchCount = matches.size(); vars.put(refName + REF_MATCH_NR, Integer.toString(matchCount));// Save the count - regexVars.put(refName + REF_MATCH_NR, Integer.toString(matchCount));// Save the count - for (int i = 1; i <= matchCount; i++) { match = getCorrectMatch(matches, i); if (match != null) { final String refName_n = refName + UNDERSCORE + i; vars.put(refName_n, generateResult(match)); - regexVars.put(refName_n, generateResult(match)); - saveGroups(vars, refName_n, match); } } @@ -166,7 +157,7 @@ public class RegexExtractor extends AbstractScopedTestElement implements PostPro vars.remove(refName_n); removeGroups(vars, refName_n); } - previousResult.addVars(regexVars); + previousResult.addVars(refName, vars.get(refName)); } catch (RuntimeException e) { log.warn("Error while generating result"); } diff --git a/backend/src/main/java/org/apache/jmeter/extractor/XPath2Extractor.java b/backend/src/main/java/org/apache/jmeter/extractor/XPath2Extractor.java index 4946ecafe2..8d0412704a 100644 --- a/backend/src/main/java/org/apache/jmeter/extractor/XPath2Extractor.java +++ b/backend/src/main/java/org/apache/jmeter/extractor/XPath2Extractor.java @@ -152,7 +152,7 @@ public class XPath2Extractor for (int i = matchCount + 2; i <= prevCount; i++) { vars.remove(concat(refName, i)); } - previousResult.addVars(vars); + previousResult.addVars(refName,vars.get(refName)); } catch (Exception e) {// Saxon exception if (log.isWarnEnabled()) { log.warn("Exception while processing '{}', message:{}", getXPathQuery(), e.getMessage()); diff --git a/backend/src/main/java/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java b/backend/src/main/java/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java index f879b2f5fb..b035faadb0 100644 --- a/backend/src/main/java/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java +++ b/backend/src/main/java/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java @@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory; /** * JSON-PATH based extractor + * * @since 3.0 */ public class JSONPostProcessor @@ -89,7 +90,7 @@ public class JSONPostProcessor } } SampleResult previousResult = context.getPreviousResult(); - previousResult.addVars(vars); + previousResult.addVars(currentRefName, vars.get(currentRefName)); } catch (Exception e) { // if something wrong, default value added if (log.isDebugEnabled()) { @@ -172,7 +173,7 @@ public class JSONPostProcessor } // extract at position if (matchNumber > extractedValues.size()) { - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug( "matchNumber({}) exceeds number of items found({}), default value will be used", matchNumber, extractedValues.size()); @@ -194,7 +195,7 @@ public class JSONPostProcessor } private void handleEmptyResponse(JMeterVariables vars, String[] defaultValues, int i, String currentRefName) { - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("Response or source variable is null or empty for {}", getName()); } vars.put(currentRefName, defaultValues[i]); @@ -221,7 +222,7 @@ public class JSONPostProcessor private void clearOldRefVars(JMeterVariables vars, String refName) { vars.remove(refName + REF_MATCH_NR); - for (int i=1; vars.get(refName + "_" + i) != null; i++) { + for (int i = 1; vars.get(refName + "_" + i) != null; i++) { vars.remove(refName + "_" + i); } } diff --git a/backend/src/main/java/org/apache/jmeter/samplers/SampleResult.java b/backend/src/main/java/org/apache/jmeter/samplers/SampleResult.java index 4d1c3af09e..359a8615fa 100644 --- a/backend/src/main/java/org/apache/jmeter/samplers/SampleResult.java +++ b/backend/src/main/java/org/apache/jmeter/samplers/SampleResult.java @@ -1612,8 +1612,11 @@ public class SampleResult implements Serializable, Cloneable, Searchable { this.testLogicalAction = testLogicalAction; } - public void addVars(JMeterVariables vars) { - this.vars = vars; + public void addVars(String key, String value) { + if (this.vars == null) { + this.vars = new JMeterVariables(); + } + this.vars.put(key, value); } public JMeterVariables getVars() {