简体   繁体   English

从Beanshell Jmeter运行时不包含JSON

[英]JSON not getting included when running from Beanshell Jmeter

We have a CURL command which basically pushes the status of the run to a dashboard. 我们有一个CURL命令,该命令基本上将运行状态推送到仪表板。 Below is the command with a dummy URL. 以下是带有虚拟URL的命令。

The command has to send two information details to the dashboard; 该命令必须将两个信息详细信息发送到仪表板。 info and info which has contents Text is missing and Please check. info和包含内容的info Text is missingPlease check. This curl command when executed from any Linux box is running correctly and the information sent in the JSON is being displayed but when we try to run the same command from Jmeter Beanshell , it is running successfully but the info in the JSON alone is not coming to the dashboard. 从任何Linux盒执行时,此curl命令都可以正确运行,并且会显示JSON发送的信息,但是当我们尝试从Jmeter Beanshell运行相同命令时,该命令已成功运行,但仅JSON中的信息就无法运行仪表板。

String command = "curl -X POST -d \"status=GREEN\" -d 'info={\"error\":[{\"info\":\"Text is missing\"},{\"info\":\"Please check.\"}]}' abc.com/api/run-dashboard/apikey=456655656";
    Process p = Runtime.getRuntime().exec(command);
    p.waitFor();
#to display the output-
    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    StringBuilder everything = new StringBuilder();
    String line;
    while( (line = in.readLine()) != null) 
    {
      everything.append(line);
    }
    in.close();
    log.info("OUTPUT: " + everything.toString());
    }

We tried adding the additional header -H "Content-Type: application/json" in the beanshell but in vain. 我们尝试在beanshell中添加额外的标头-H "Content-Type: application/json" ,但徒劳。

Can someone let us know what is missing in our command which is sent from Beanshell on why JSON data is not being displayed. 有人可以让我们知道从Beanshell发送的命令中缺少什么,为什么没有显示JSON数据。 shold we add any other header details. shold,我们添加任何其他标头详细信息。

  1. You might need to provide full path to curl utility like /usr/bin/curl 您可能需要提供curl实用程序的完整路径,例如/usr/bin/curl
  2. It might be the case your command fails with some error so make sure to handle p.getErrorStream() 您的命令可能因某些错误而失败,因此请确保处理p.getErrorStream()
  3. Be aware that starting from JMeter 3.1 it is recommended to use JSR223 Test Elements and Groovy language for scripting , consider switching to it as Beanshell performance might be a big question mark. 请注意, 从JMeter 3.1开始,建议使用JSR223测试元素和Groovy语言进行脚本编写 ,请考虑切换到它,因为Beanshell性能可能是一个很大的问号。 Moreover you will be able to convert your Beanshell code into something like: 此外,您将能够将Beanshell代码转换为类似以下内容的代码:

     def response = "curl -X POST -d \\"status=GREEN\\" -d 'info={\\"error\\":[{\\"info\\":\\"Text is missing\\"},{\\"info\\":\\"Please check.\\"}]}' http://example.com/api/run-dashboard/apikey=456655656".execute().text log.info(response) 

    JMeter Groovy卷发

    More information: Apache Groovy - Why and How You Should Use It 更多信息: Apache Groovy-为什么以及如何使用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM