use of org.apache.oro.text.regex.Perl5Matcher in project jmeter by apache.
the class HtmlParsingUtils method isAnchorMatched.
/**
* Check if anchor matches by checking against:
* - protocol
* - domain
* - path
* - parameter names
*
* @param newLink target to match
* @param config pattern to match against
*
* @return true if target URL matches pattern URL
*/
public static boolean isAnchorMatched(HTTPSamplerBase newLink, HTTPSamplerBase config) {
String query;
try {
query = URLDecoder.decode(newLink.getQueryString(), StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
// UTF-8 unsupported? You must be joking!
log.error("UTF-8 encoding not supported!");
throw new Error("Should not happen: " + e.toString(), e);
}
final Arguments arguments = config.getArguments();
final Perl5Matcher matcher = JMeterUtils.getMatcher();
final PatternCacheLRU patternCache = JMeterUtils.getPatternCache();
if (!isEqualOrMatches(newLink.getProtocol(), config.getProtocol(), matcher, patternCache)) {
return false;
}
final String domain = config.getDomain();
if (domain != null && domain.length() > 0) {
if (!isEqualOrMatches(newLink.getDomain(), domain, matcher, patternCache)) {
return false;
}
}
final String path = config.getPath();
if (!newLink.getPath().equals(path) && !matcher.matches(newLink.getPath(), // $NON-NLS-1$
patternCache.getPattern(// $NON-NLS-1$
"[/]*" + path, Perl5Compiler.READ_ONLY_MASK))) {
return false;
}
for (JMeterProperty argument : arguments) {
Argument item = (Argument) argument.getObjectValue();
final String name = item.getName();
if (!query.contains(name + "=")) {
// $NON-NLS-1$
if (!matcher.contains(query, patternCache.getPattern(name, Perl5Compiler.READ_ONLY_MASK))) {
return false;
}
}
}
return true;
}
use of org.apache.oro.text.regex.Perl5Matcher in project jmeter by apache.
the class HtmlParsingUtils method extractStyleURLs.
public static void extractStyleURLs(final URL baseUrl, final URLCollection urls, String styleTagStr) {
Perl5Matcher matcher = JMeterUtils.getMatcher();
Pattern pattern = JMeterUtils.getPatternCache().getPattern(// $NON-NLS-1$
"URL\\(\\s*('|\")(.*)('|\")\\s*\\)", Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK | Perl5Compiler.READ_ONLY_MASK);
PatternMatcherInput input;
input = new PatternMatcherInput(styleTagStr);
while (matcher.contains(input, pattern)) {
MatchResult match = matcher.getMatch();
// The value is in the second group
String styleUrl = match.group(2);
urls.addURL(styleUrl, baseUrl);
}
}
use of org.apache.oro.text.regex.Perl5Matcher in project jmeter by apache.
the class HtmlParsingUtils method isArgumentMatched.
/**
* Arguments match if the input name matches the corresponding pattern name
* and the input value matches the pattern value, where the matching is done
* first using String equals, and then Regular Expression matching if the equals test fails.
*
* @param arg - input Argument
* @param patternArg - pattern to match against
* @return true if both name and value match
*/
public static boolean isArgumentMatched(Argument arg, Argument patternArg) {
final Perl5Matcher matcher = JMeterUtils.getMatcher();
final PatternCacheLRU patternCache = JMeterUtils.getPatternCache();
return isEqualOrMatches(arg.getName(), patternArg.getName(), matcher, patternCache) && isEqualOrMatches(arg.getValue(), patternArg.getValue(), matcher, patternCache);
}
use of org.apache.oro.text.regex.Perl5Matcher in project jmeter by apache.
the class TestHTTPSamplersAgainstHttpMirrorServer method checkRegularExpression.
private boolean checkRegularExpression(String stringToCheck, String regularExpression) {
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK);
return localMatcher.contains(stringToCheck, pattern);
}
use of org.apache.oro.text.regex.Perl5Matcher in project jmeter by apache.
the class TestHTTPSamplersAgainstHttpMirrorServer method getSentRequestHeaderValue.
private String getSentRequestHeaderValue(String requestHeaders, String headerName) {
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
String expression = ".*" + headerName + ": (\\d*).*";
Pattern pattern = JMeterUtils.getPattern(expression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK);
if (localMatcher.matches(requestHeaders, pattern)) {
// The value is in the first group, group 0 is the whole match
return localMatcher.getMatch().group(1);
}
return null;
}
Aggregations