Java :调用 bsh 方法时出错:eval 源文件:内联评估:``

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38768099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 20:37:46  来源:igfitidea点击:

: Error invoking bsh method: eval Sourced file: inline evaluation of: ``

javajmeterbeanshell

提问by

This is the code I'm trying to execute in beanshell sampler:

这是我试图在beanshell 采样器中执行的代码:

import java.lang.*;
import java.util.*;

String name_lead = vars.get("Name_lead");

String[] lead = name_lead.split("\s+");
//vars.put("myname",lead[0]);
//vars.put("myname1",lead[1]);
//vars.put("myname2",lead[2]);
for(int i=1; i<=Integer.parseInt(vars.get("title_pass_matchNr")); i++)
{
    String title = vars.get("title_pass_"+i);
    String fname = vars.get("firstname_"+i);
    String lname = vars.get("lastname_"+i);
    String[] fn = fname.split("");
//vars.put("title",title);
//vars.put("fname",fn[1]);
//vars.put("lname",lname);

    if(lead[i-1].equals(title) && lead[i].equals(fn[1]) && lead[i+1].equals(lname))
    {
        vars.put("namep",lead[i]);
    }
}

But I'm getting the following error:

但我收到以下错误:

Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import java.lang.; import java.util.; String name_lead=vars.get("Name_lead"); . . . ''

响应消息:org.apache.jorphan.util.JMeterException:调用 bsh 方法时出错:eval 源文件:内联评估:``import java.lang。; 导入 java.util。; String name_lead=vars.get("Name_lead"); . . . ''

I'm not able to understand it. Can sombody help me? How do I fix this?

我无法理解。有人可以帮助我吗?我该如何解决?

name_leadhas something like Mr P singh ..and taking using regex extractor

name_lead有像 P singh 先生之类的东西 .. 并使用正则表达式提取器

采纳答案by Dmitri T

There is a good way to convert this Error invoking bsh methoderror into a more human-readable stacktrace: put your code into a try blocklike:

有一种很好的方法可以将此Error invoking bsh method错误转换为更易读的堆栈跟踪:将您的代码放入try 块中,例如:

try {
    //your code here
}
catch (Throwable ex) {
    log.error("Error in Beanshell", ex);
    throw ex;
}

This way you will able to see the exception details in jmeter.logfile

这样您就可以在jmeter.log文件中看到异常详细信息

Another way to add debug()directive at the very beginning of your Beanshell script. This way you'll get a lot of debugging output into stdout.

在 Beanshell 脚本的开头添加debug()指令的另一种方法。通过这种方式,您将获得大量调试输出到stdout 中

See How to Use BeanShell: JMeter's Favorite Built-in Componentguide for more information on using Beanshell in JMeter tests and scripts development and troubleshooting

有关在 JMeter 测试和脚本开发和故障排除中使用 Beanshell 的更多信息,请参阅如何使用 BeanShell:JMeter 最喜欢的内置组件指南