需要从Bean Shell Sampler Jmeter中仅提取模数值吗?

时间:2018-02-28 12:32:36

标签: jmeter jmeter-3.2

在我的Bean Shell Sampler中,我得到了响应

Sun RSA公钥,2048位   模量:22295351891298217229975679072351263454572804823888397394956934480688545098388363434555311921650592166059251017638546278442305958792511628365321549674368487249258317999232492062784515102404906734978121435799114700302881045885988703962970888009290777606595760751230036638945779986258956916131307234869683993065702144540870733479633460269689089976061715241046980179651894991519601546098863574672792649655278518708922038045203420614818093220439077000089729610115783652292803355176127125944925842204444536282480600674854449097908926668384181326756503446116301460522215211454108585731728225508829847198093781511594519426983   公共指数:65537

我只需要提取模数字段中的值。我们怎样才能在Jmeter中做到这一点?帮助很有用!

1 个答案:

答案 0 :(得分:1)

  1. 切换为JSR223 SamplerGroovy语言
  2. 使用以下代码提取您的"模数"使用正则表达式Matcher之类的值

    def response = 'Sun RSA public key, 2048 bits modulus: 22295351891298217229975679072351263454572804823888397394956934480688545098388363434555311921650592166059251017638546278442305958792511628365321549674368487249258317999232492062784515102404906734978121435799114700302881045885988703962970888009290777606595760751230036638945779986258956916131307234869683993065702144540870733479633460269689089976061715241046980179651894991519601546098863574672792649655278518708922038045203420614818093220439077000089729610115783652292803355176127125944925842204444536282480600674854449097908926668384181326756503446116301460522215211454108585731728225508829847198093781511594519426983 public exponent: 65537'
    
    def matcher = response =~ /modulus: (.+?) public/
    
    if (matcher.find()) {
        log.info(matcher.group(1))
    }
    
  3. 参考文献:

    Beanshell等效以防万一:

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    
    String response = "Sun RSA public key, 2048 bits modulus: 22295351891298217229975679072351263454572804823888397394956934480688545098388363434555311921650592166059251017638546278442305958792511628365321549674368487249258317999232492062784515102404906734978121435799114700302881045885988703962970888009290777606595760751230036638945779986258956916131307234869683993065702144540870733479633460269689089976061715241046980179651894991519601546098863574672792649655278518708922038045203420614818093220439077000089729610115783652292803355176127125944925842204444536282480600674854449097908926668384181326756503446116301460522215211454108585731728225508829847198093781511594519426983 public exponent: 65537";
    Pattern p = Pattern.compile("modulus: (.+?) public");
    Matcher m = p.matcher(response);
    if (m.find()){
        log.info(m.group(1));
    }
    
相关问题