Method from org.apache.jmeter.extractor.RegexExtractor Detail: |
public Object clone() {
RegexExtractor cloned = (RegexExtractor) super.clone();
cloned.template = this.template;
return cloned;
}
|
public String getDefaultValue() {
return getPropertyAsString(DEFAULT);
}
|
public int getMatchNumber() {
return getPropertyAsInt(MATCH_NUMBER);
}
|
public String getMatchNumberAsString() {
return getPropertyAsString(MATCH_NUMBER);
}
|
public String getRefName() {
return getPropertyAsString(REFNAME);
}
|
public String getRegex() {
return getPropertyAsString(REGEX);
}
|
public String getTemplate() {
return getPropertyAsString(TEMPLATE);
}
|
public void process() {
initTemplate();
JMeterContext context = getThreadContext();
SampleResult previousResult = context.getPreviousResult();
if (previousResult == null) {
return;
}
log.debug("RegexExtractor processing result");
// Fetch some variables
JMeterVariables vars = context.getVariables();
String refName = getRefName();
int matchNumber = getMatchNumber();
final String defaultValue = getDefaultValue();
if (defaultValue.length() > 0){// Only replace default if it is provided
vars.put(refName, defaultValue);
}
Perl5Matcher matcher = JMeterUtils.getMatcher();
String inputString =
useUrl() ? previousResult.getUrlAsString() // Bug 39707
: useHeaders() ? previousResult.getResponseHeaders()
: useCode() ? previousResult.getResponseCode() //Bug 43451
: useMessage() ? previousResult.getResponseMessage() //Bug 43451
: useUnescapedBody() ? StringEscapeUtils.unescapeHtml(previousResult.getResponseDataAsString())
: previousResult.getResponseDataAsString() // Bug 36898
;
if (log.isDebugEnabled()) {
log.debug("Input = " + inputString);
}
PatternMatcherInput input = new PatternMatcherInput(inputString);
String regex = getRegex();
if (log.isDebugEnabled()) {
log.debug("Regex = " + regex);
}
try {
Pattern pattern = JMeterUtils.getPatternCache().getPattern(regex, Perl5Compiler.READ_ONLY_MASK);
List matches = new ArrayList();
int x = 0;
boolean done = false;
do {
if (matcher.contains(input, pattern)) {
log.debug("RegexExtractor: Match found!");
matches.add(matcher.getMatch());
} else {
done = true;
}
x++;
} while (x != matchNumber && !done);
int prevCount = 0;
String prevString = vars.get(refName + REF_MATCH_NR);
if (prevString != null) {
vars.remove(refName + REF_MATCH_NR);// ensure old value is not left defined
try {
prevCount = Integer.parseInt(prevString);
} catch (NumberFormatException e1) {
log.warn("Could not parse "+prevString+" "+e1);
}
}
int matchCount=0;// Number of refName_n variable sets to keep
try {
MatchResult match;
if (matchNumber >= 0) {// Original match behaviour
match = getCorrectMatch(matches, matchNumber);
if (match != null) {
vars.put(refName, generateResult(match));
saveGroups(vars, refName, match);
} else {
// refname has already been set to the default (if present)
removeGroups(vars, refName);
}
} else // < 0 means we save all the matches
{
removeGroups(vars, refName); // remove any single matches
matchCount = matches.size();
vars.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 = new StringBuffer(refName).append(UNDERSCORE).append(i).toString();
vars.put(refName_n, generateResult(match));
saveGroups(vars, refName_n, match);
}
}
}
// Remove any left-over variables
for (int i = matchCount + 1; i < = prevCount; i++) {
final String refName_n = new StringBuffer(refName).append(UNDERSCORE).append(i).toString();
vars.remove(refName_n);
removeGroups(vars, refName_n);
}
} catch (RuntimeException e) {
log.warn("Error while generating result");
}
} catch (MalformedCachePatternException e) {
log.warn("Error in pattern: " + regex);
}
}
Parses the response data using regular expressions and saving the results
into variables for use later in the test. |
public void setDefaultValue(String defaultValue) {
setProperty(DEFAULT, defaultValue);
}
Sets the value of the variable if no matches are found |
public void setMatchNumber(int matchNumber) {
setProperty(new IntegerProperty(MATCH_NUMBER, matchNumber));
}
Set which Match to use. This can be any positive number, indicating the
exact match to use, or 0, which is interpreted as meaning random. |
public void setMatchNumber(String matchNumber) {
setProperty(MATCH_NUMBER, matchNumber);
}
|
public void setRefName(String refName) {
setProperty(REFNAME, refName);
}
|
public void setRegex(String regex) {
setProperty(REGEX, regex);
}
|
public void setTemplate(String template) {
setProperty(TEMPLATE, template);
}
|
public void setUseField(String actionCommand) {
setProperty(MATCH_AGAINST,actionCommand);
}
|
public boolean useBody() {
String prop = getPropertyAsString(MATCH_AGAINST);
return prop.length()==0 || USE_BODY.equalsIgnoreCase(prop);// $NON-NLS-1$
}
|
public boolean useCode() {
String prop = getPropertyAsString(MATCH_AGAINST);
return USE_CODE.equalsIgnoreCase(prop);
}
|
public boolean useHeaders() {
return USE_HDRS.equalsIgnoreCase( getPropertyAsString(MATCH_AGAINST));
}
|
public boolean useMessage() {
String prop = getPropertyAsString(MATCH_AGAINST);
return USE_MESSAGE.equalsIgnoreCase(prop);
}
|
public boolean useUnescapedBody() {
String prop = getPropertyAsString(MATCH_AGAINST);
return USE_BODY_UNESCAPED.equalsIgnoreCase(prop);// $NON-NLS-1$
}
|
public boolean useUrl() {
String prop = getPropertyAsString(MATCH_AGAINST);
return USE_URL.equalsIgnoreCase(prop);
}
|