/** * By default, the method assumes the entry is not included, unless it * matches. In that case, it will return true. * * @param text text to be checked * @return <code>true</code> if text is included */ protected boolean incPattern(String text) { this.USEFILE = false; for (Pattern includePattern : this.INCPATTERNS) { if (JMeterUtils.getMatcher().contains(text, includePattern)) { this.USEFILE = true; break; } } return this.USEFILE; }
/** * The method assumes by default the text is not excluded. If the text * matches the pattern, it will then return true. * * @param text text to be checked * @return <code>true</code> if text is excluded */ protected boolean excPattern(String text) { this.USEFILE = true; boolean exc = false; for (Pattern excludePattern : this.EXCPATTERNS) { if (JMeterUtils.getMatcher().contains(text, excludePattern)) { exc = true; this.USEFILE = false; break; } } return exc; }
/** * Match the input argument against the pattern using String.equals() or pattern matching if that fails * using case-insensitive matching. * * @param arg input string * @param pat pattern string * * @return true if input matches the pattern */ public static boolean isEqualOrMatches(String arg, String pat){ return isEqualOrMatches(arg, pat, JMeterUtils.getMatcher(), JMeterUtils.getPatternCache()); }
/** * Match the input argument against the pattern using String.equals() or pattern matching if that fails * using case-insensitive matching. * * @param arg input string * @param pat pattern string * * @return true if input matches the pattern */ public static boolean isEqualOrMatchesCaseBlind(String arg, String pat){ return isEqualOrMatchesCaseBlind(arg, pat, JMeterUtils.getMatcher(), JMeterUtils.getPatternCache()); }
/** * Returns true if matching pattern was different from expectedToMatch * @param expression Expression to match * @param sampleContentType * @return boolean true if Matching expression */ private boolean testPattern(String expression, String sampleContentType, boolean expectedToMatch) { if(expression != null && expression.length() > 0) { if(log.isDebugEnabled()) { log.debug( "Testing Expression : {} on sampleContentType: {}, expected to match: {}", expression, sampleContentType, expectedToMatch); } Pattern pattern = null; try { pattern = JMeterUtils.getPatternCache().getPattern(expression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK); if(JMeterUtils.getMatcher().contains(sampleContentType, pattern) != expectedToMatch) { return false; } } catch (MalformedCachePatternException e) { log.warn("Skipped invalid content pattern: {}", expression, e); } } return true; }
private boolean isFirstElementGroup(String rawData) { Pattern pattern = JMeterUtils.getPatternCache().getPattern("^\\$\\d+\\$", //$NON-NLS-1$ Perl5Compiler.READ_ONLY_MASK); return JMeterUtils.getMatcher().contains(rawData, pattern); }
private boolean matchesPatterns(String url, CollectionProperty patterns) { for (JMeterProperty jMeterProperty : patterns) { String item = jMeterProperty.getStringValue(); try { Pattern pattern = JMeterUtils.getPatternCache().getPattern( item, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK); if (JMeterUtils.getMatcher().matches(url, pattern)) { return true; } } catch (MalformedCachePatternException e) { log.warn("Skipped invalid pattern: {}", item, e); } } return false; }
PatternMatcher matcher = JMeterUtils.getMatcher(); Util.split(pieces, matcher, templatePattern, rawTemplate); PatternMatcherInput input = new PatternMatcherInput(rawTemplate);
private static String getHeaderValue(String headerName, String multiPart) { String regularExpression = headerName + "\\s*:\\s*(.*)$"; //$NON-NLS-1$ Perl5Matcher localMatcher = JMeterUtils.getMatcher(); Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK); if(localMatcher.contains(multiPart, pattern)) { return localMatcher.getMatch().group(1).trim(); } else { return null; } } }
private boolean isEquals(String subj) { Pattern pattern = JMeterUtils.getPatternCache().getPattern(getExpectedValue()); return JMeterUtils.getMatcher().matches(subj, pattern); }
private String filterString(final String content) { if (stringsToSkip == null || stringsToSkip.isEmpty()) { return content; } else { String result = content; for (SubstitutionElement regex : stringsToSkip) { emptySub.setSubstitution(regex.getSubstitute()); result = Util.substitute(JMeterUtils.getMatcher(), JMeterUtils.getPatternCache().getPattern(regex.getRegex()), emptySub, result, Util.SUBSTITUTE_ALL); } return result; } }
private static String getRequestHeaderValue(String requestHeaders, String headerName) { Perl5Matcher localMatcher = JMeterUtils.getMatcher(); // We use multi-line mask so can prefix the line with ^ String expression = "^" + headerName + ":\\s+([^\\r\\n]+)"; // $NON-NLS-1$ $NON-NLS-2$ Pattern pattern = JMeterUtils.getPattern(expression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK); if(localMatcher.contains(requestHeaders, pattern)) { // The value is in the first group, group 0 is the whole match return localMatcher.getMatch().group(1); } else { return null; } }
private boolean isEquals(Object subj) { String str = JSONPathExtractor.objectToString(subj); if (isUseRegex()) { Pattern pattern = JMeterUtils.getPatternCache().getPattern(getExpectedValue()); return JMeterUtils.getMatcher().matches(str, pattern); } else { return str.equals(getExpectedValue()); } }
protected String getIpAddress(String logLine) { Pattern incIp = JMeterUtils.getPatternCache().getPattern("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}", Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK); Perl5Matcher matcher = JMeterUtils.getMatcher(); matcher.contains(logLine, incIp); return matcher.getMatch().group(0); }
private List<MatchResult> processMatches(Pattern pattern, String regex, SampleResult result, int matchNumber, JMeterVariables vars) { log.debug("Regex = '{}'", regex); Perl5Matcher matcher = JMeterUtils.getMatcher(); List<MatchResult> matches = new ArrayList<>(); int found = 0; if (isScopeVariable()){ String inputString=vars.get(getVariableName()); if(inputString == null) { if (log.isWarnEnabled()) { log.warn("No variable '{}' found to process by RegexExtractor '{}', skipping processing", getVariableName(), getName()); } return Collections.emptyList(); } matchStrings(matchNumber, matcher, pattern, matches, found, inputString); } else { List<SampleResult> sampleList = getSampleList(result); for (SampleResult sr : sampleList) { String inputString = getInputString(sr); found = matchStrings(matchNumber, matcher, pattern, matches, found, inputString); if (matchNumber > 0 && found == matchNumber){// no need to process further break; } } } return matches; }
private boolean isEquals(Object subj) { String str = objectToString(subj); if (isUseRegex()) { Pattern pattern = JMeterUtils.getPatternCache().getPattern(getExpectedValue()); return JMeterUtils.getMatcher().matches(str, pattern); } else { return str.equals(getExpectedValue()); } }
@Override public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariableException { PatternMatcher pm = JMeterUtils.getMatcher(); PatternCompiler compiler = new Perl5Compiler(); String input = prop.getStringValue(); if(input == null) { return prop; } for(Entry<String, String> entry : getVariables().entrySet()){ String key = entry.getKey(); String value = entry.getValue(); if (regexMatch) { try { Pattern pattern = compiler.compile(constructPattern(value)); input = Util.substitute(pm, pattern, new StringSubstitution(FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX), input, Util.SUBSTITUTE_ALL); } catch (MalformedPatternException e) { log.warn("Malformed pattern: {}", value); } } else { input = StringUtilities.substitute(input, value, FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX); } } return new StringProperty(prop.getName(), input); }
private static int getPositionOfBody(String stringToCheck) { Perl5Matcher localMatcher = JMeterUtils.getMatcher(); // The headers and body are divided by a blank line (the \r is to allow for the CR before LF) String regularExpression = "^\\r$"; // $NON-NLS-1$ Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK); PatternMatcherInput input = new PatternMatcherInput(stringToCheck); if(localMatcher.contains(input, pattern)) { MatchResult match = localMatcher.getMatch(); return match.beginOffset(0); } // No divider was found return -1; } }
public static void extractStyleURLs(final URL baseUrl, final URLCollection urls, String styleTagStr) { Perl5Matcher matcher = JMeterUtils.getMatcher(); Pattern pattern = JMeterUtils.getPatternCache().getPattern( "URL\\(\\s*('|\")(.*)('|\")\\s*\\)", // $NON-NLS-1$ Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK | Perl5Compiler.READ_ONLY_MASK); PatternMatcherInput input = null; 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); } } }
/** * 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); }