Search in sources :

Example 36 with Perl5Matcher

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;
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) Arguments(org.apache.jmeter.config.Arguments) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) PatternCacheLRU(org.apache.oro.text.PatternCacheLRU)

Example 37 with Perl5Matcher

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);
    }
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult)

Example 38 with Perl5Matcher

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);
}
Also used : Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) PatternCacheLRU(org.apache.oro.text.PatternCacheLRU)

Example 39 with Perl5Matcher

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);
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher)

Example 40 with Perl5Matcher

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;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher)

Aggregations

Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)72 Pattern (org.apache.oro.text.regex.Pattern)50 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)23 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)22 MatchResult (org.apache.oro.text.regex.MatchResult)21 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)17 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)14 ArrayList (java.util.ArrayList)12 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)8 IOException (java.io.IOException)6 MalformedURLException (java.net.MalformedURLException)6 MalformedCachePatternException (org.apache.oro.text.MalformedCachePatternException)5 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 SampleResult (org.apache.jmeter.samplers.SampleResult)3 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)3 PatternCacheLRU (org.apache.oro.text.PatternCacheLRU)3 BufferedReader (java.io.BufferedReader)2 EOFException (java.io.EOFException)2 File (java.io.File)2