当前位置: 首页>>代码示例>>Java>>正文


Java JMeterUtils.getMatcher方法代码示例

本文整理汇总了Java中org.apache.jmeter.util.JMeterUtils.getMatcher方法的典型用法代码示例。如果您正苦于以下问题:Java JMeterUtils.getMatcher方法的具体用法?Java JMeterUtils.getMatcher怎么用?Java JMeterUtils.getMatcher使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.jmeter.util.JMeterUtils的用法示例。


在下文中一共展示了JMeterUtils.getMatcher方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBoundaryStringFromContentType

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
private String getBoundaryStringFromContentType(String requestHeaders) {
    Perl5Matcher localMatcher = JMeterUtils.getMatcher();
    String regularExpression = "^" + HTTPConstants.HEADER_CONTENT_TYPE + ": multipart/form-data; boundary=(.+)$"; 
    Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
    if(localMatcher.contains(requestHeaders, pattern)) {
        MatchResult match = localMatcher.getMatch();
        String matchString =  match.group(1);
        // Header may contain ;charset= , regexp extracts it so computed boundary is wrong
        int indexOf = matchString.indexOf(';');
        if(indexOf>=0) {
            return matchString.substring(0, indexOf);
        } else {
            return matchString;
        }
    }
    else {
        return null;
    }
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:20,代码来源:TestHTTPSamplersAgainstHttpMirrorServer.java

示例2: initTemplate

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
private void initTemplate() {
    if (template != null) {
        return;
    }
    // Contains Strings and Integers
    List<Object> combined = new ArrayList<>();
    String rawTemplate = getTemplate();
    PatternMatcher matcher = JMeterUtils.getMatcher();
    Pattern templatePattern = JMeterUtils.getPatternCache().getPattern("\\$(\\d+)\\$"  // $NON-NLS-1$
            , Perl5Compiler.READ_ONLY_MASK
            & Perl5Compiler.SINGLELINE_MASK);
    if (log.isDebugEnabled()) {
        log.debug("Pattern = " + templatePattern.getPattern());
        log.debug("template = " + rawTemplate);
    }
    int beginOffset = 0;
    MatchResult currentResult;
    PatternMatcherInput pinput = new PatternMatcherInput(rawTemplate);
    while(matcher.contains(pinput, templatePattern)) {
        currentResult = matcher.getMatch();
        final int beginMatch = currentResult.beginOffset(0);
        if (beginMatch > beginOffset) { // string is not empty
            combined.add(rawTemplate.substring(beginOffset, beginMatch));
        }
        combined.add(Integer.valueOf(currentResult.group(1)));// add match as Integer
        beginOffset = currentResult.endOffset(0);
    }

    if (beginOffset < rawTemplate.length()) { // trailing string is not empty
        combined.add(rawTemplate.substring(beginOffset, rawTemplate.length()));
    }
    if (log.isDebugEnabled()){
        log.debug("Template item count: "+combined.size());
        for(Object o : combined){
            log.debug(o.getClass().getSimpleName()+" '"+o.toString()+"'");
        }
    }
    template = combined;
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:40,代码来源:RegexExtractor.java

示例3: transformValue

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
@Override
public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariableException {
    PatternMatcher pm = JMeterUtils.getMatcher();
    Pattern pattern = null;
    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 = 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);
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:28,代码来源:ReplaceFunctionsWithStrings.java

示例4: getRequestHeaderValue

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
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
//            System.out.println("Found:'"+localMatcher.getMatch().group(1)+"'");
//            System.out.println("in: '"+localMatcher.getMatch().group(0)+"'");
            return localMatcher.getMatch().group(1);
        }
        else {
            return null;
        }
    }
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:16,代码来源:HttpMirrorThread.java

示例5: getPositionOfBody

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
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;
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:15,代码来源:HttpMirrorThread.java

示例6: getHeaderValue

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
private 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;
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:12,代码来源:MultipartUrlConfig.java

示例7: getIpAddress

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
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);
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:8,代码来源:SessionFilter.java

示例8: generateTemplate

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
private Object[] generateTemplate(String rawTemplate) {
    List<String> pieces = new ArrayList<>();
    // String or Integer
    List<Object> combined = new LinkedList<>();
    PatternMatcher matcher = JMeterUtils.getMatcher();
    Util.split(pieces, matcher, templatePattern, rawTemplate);
    PatternMatcherInput input = new PatternMatcherInput(rawTemplate);
    boolean startsWith = isFirstElementGroup(rawTemplate);
    if (startsWith) {
        pieces.remove(0);// Remove initial empty entry
    }
    Iterator<String> iter = pieces.iterator();
    while (iter.hasNext()) {
        boolean matchExists = matcher.contains(input, templatePattern);
        if (startsWith) {
            if (matchExists) {
                combined.add(Integer.valueOf(matcher.getMatch().group(1)));
            }
            combined.add(iter.next());
        } else {
            combined.add(iter.next());
            if (matchExists) {
                combined.add(Integer.valueOf(matcher.getMatch().group(1)));
            }
        }
    }
    if (matcher.contains(input, templatePattern)) {
        combined.add(Integer.valueOf(matcher.getMatch().group(1)));
    }
    return combined.toArray();
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:32,代码来源:RegexFunction.java

示例9: generateTemplate

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
private Object[] generateTemplate(String rawTemplate) {
    List<String> pieces = new ArrayList<String>();
    // String or Integer
    List<Object> combined = new LinkedList<Object>();
    PatternMatcher matcher = JMeterUtils.getMatcher();
    Util.split(pieces, matcher, templatePattern, rawTemplate);
    PatternMatcherInput input = new PatternMatcherInput(rawTemplate);
    boolean startsWith = isFirstElementGroup(rawTemplate);
    if (startsWith) {
        pieces.remove(0);// Remove initial empty entry
    }
    Iterator<String> iter = pieces.iterator();
    while (iter.hasNext()) {
        boolean matchExists = matcher.contains(input, templatePattern);
        if (startsWith) {
            if (matchExists) {
                combined.add(Integer.valueOf(matcher.getMatch().group(1)));
            }
            combined.add(iter.next());
        } else {
            combined.add(iter.next());
            if (matchExists) {
                combined.add(Integer.valueOf(matcher.getMatch().group(1)));
            }
        }
    }
    if (matcher.contains(input, templatePattern)) {
        combined.add(Integer.valueOf(matcher.getMatch().group(1)));
    }
    return combined.toArray();
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:32,代码来源:RegexFunction.java

示例10: transformValue

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
@Override
public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariableException {
    PatternMatcher pm = JMeterUtils.getMatcher();
    Pattern pattern = null;
    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 = compiler.compile("\\b("+value+")\\b");
                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);
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:28,代码来源:ReplaceFunctionsWithStrings.java

示例11: initTemplate

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
private void initTemplate() {
    if (template != null) {
        return;
    }
    // Contains Strings and Integers
    List<Object> combined = new ArrayList<Object>();
    String rawTemplate = getTemplate();
    PatternMatcher matcher = JMeterUtils.getMatcher();
    Pattern templatePattern = JMeterUtils.getPatternCache().getPattern("\\$(\\d+)\\$"  // $NON-NLS-1$
            , Perl5Compiler.READ_ONLY_MASK
            & Perl5Compiler.SINGLELINE_MASK);
    if (log.isDebugEnabled()) {
        log.debug("Pattern = " + templatePattern.getPattern());
        log.debug("template = " + rawTemplate);
    }
    int beginOffset = 0;
    MatchResult currentResult;
    PatternMatcherInput pinput = new PatternMatcherInput(rawTemplate);
    while(matcher.contains(pinput, templatePattern)) {
        currentResult = matcher.getMatch();
        final int beginMatch = currentResult.beginOffset(0);
        if (beginMatch > beginOffset) { // string is not empty
            combined.add(rawTemplate.substring(beginOffset, beginMatch));
        }
        combined.add(Integer.valueOf(currentResult.group(1)));// add match as Integer
        beginOffset = currentResult.endOffset(0);
    }

    if (beginOffset < rawTemplate.length()) { // trailing string is not empty
        combined.add(rawTemplate.substring(beginOffset, rawTemplate.length()));
    }
    if (log.isDebugEnabled()){
        log.debug("Template item count: "+combined.size());
        for(Object o : combined){
            log.debug(o.getClass().getSimpleName()+" '"+o.toString()+"'");
        }
    }
    template = combined;
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:40,代码来源:RegexExtractor.java

示例12: getSentRequestHeaderValue

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
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;
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:11,代码来源:TestHTTPSamplersAgainstHttpMirrorServer.java

示例13: getPositionOfBody

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
private int getPositionOfBody(String stringToCheck) {
    Perl5Matcher localMatcher = JMeterUtils.getMatcher();
    // The headers and body are divided by a blank line
    String regularExpression = "^.$"; 
    Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
    
    PatternMatcherInput input = new PatternMatcherInput(stringToCheck);
    while(localMatcher.contains(input, pattern)) {
        MatchResult match = localMatcher.getMatch();
        return match.beginOffset(0);
    }
    // No divider was found
    return -1;
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:15,代码来源:TestHTTPSamplersAgainstHttpMirrorServer.java

示例14: getSampleSaveConfiguration

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
/**
 * Parse a CSV header line
 * 
 * @param headerLine
 *            from CSV file
 * @param filename
 *            name of file (for log message only)
 * @return config corresponding to the header items found or null if not a
 *         header line
 */
public static SampleSaveConfiguration getSampleSaveConfiguration(
        String headerLine, String filename) {
    String[] parts = splitHeader(headerLine, _saveConfig.getDelimiter()); // Try
                                                                          // default
                                                                          // delimiter

    String delim = null;

    if (parts == null) {
        Perl5Matcher matcher = JMeterUtils.getMatcher();
        PatternMatcherInput input = new PatternMatcherInput(headerLine);
        Pattern pattern = JMeterUtils.getPatternCache()
        // This assumes the header names are all single words with no spaces
        // word followed by 0 or more repeats of (non-word char + word)
        // where the non-word char (\2) is the same
        // e.g. abc|def|ghi but not abd|def~ghi
                .getPattern("\\w+((\\W)\\w+)?(\\2\\w+)*(\\2\"\\w+\")*", // $NON-NLS-1$
                        // last entries may be quoted strings
                        Perl5Compiler.READ_ONLY_MASK);
        if (matcher.matches(input, pattern)) {
            delim = matcher.getMatch().group(2);
            parts = splitHeader(headerLine, delim);// now validate the
                                                   // result
        }
    }

    if (parts == null) {
        return null; // failed to recognise the header
    }

    // We know the column names all exist, so create the config
    SampleSaveConfiguration saveConfig = new SampleSaveConfiguration(false);

    int varCount = 0;
    for (String label : parts) {
        if (isVariableName(label)) {
            varCount++;
        } else {
            Functor set = (Functor) headerLabelMethods.get(label);
            set.invoke(saveConfig, new Boolean[]{Boolean.TRUE});
        }
    }

    if (delim != null) {
        log.warn("Default delimiter '" + _saveConfig.getDelimiter()
                + "' did not work; using alternate '" + delim
                + "' for reading " + filename);
        saveConfig.setDelimiter(delim);
    }

    saveConfig.setVarCount(varCount);

    return saveConfig;
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:65,代码来源:CSVSaveService.java

示例15: isAnchorMatched

import org.apache.jmeter.util.JMeterUtils; //导入方法依赖的package包/类
/**
 * 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 = null;
    try {
        query = URLDecoder.decode(newLink.getQueryString(), "UTF-8"); // $NON-NLS-1$
    } 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(), patternCache.getPattern("[/]*" + path, // $NON-NLS-1$
                    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;
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:59,代码来源:HtmlParsingUtils.java


注:本文中的org.apache.jmeter.util.JMeterUtils.getMatcher方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。