在jmeter中运行bean脚本时无法导入com.paytm.merchant.CheckSumServiceHelper [英] Not able to import com.paytm.merchant.CheckSumServiceHelper when running beanshell script in jmeter

查看:89
本文介绍了在jmeter中运行bean脚本时无法导入com.paytm.merchant.CheckSumServiceHelper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Jmeter的JSR223预处理程序的新手.我们刚刚将Paytm的支付网关集成到了我们的产品中,我们不得不使用Jmeter运行负载测试.我们必须使用一组值生成一个校验和,然后将其注入到我们的Json有效负载中.我正在使用Java Beanshell执行代码.我在bin目录中添加了此处可用的jar文件,并将其添加到我的类路径中在开始测试之前.这是我的代码:

I am new to Jmeter's JSR223 PreProcessor. We have just integrated Paytm's payment gateway into our product and we had to run load tests using Jmeter. We have to generate a checksum using a set of values and then inject that into our Json payload. I am using Java Beanshell to execute the code. I have added the jar file available here in my bin directory and also added it to my class path before starting the tests. Here is what my code looks like:

import com.paytm.merchant.CheckSumServiceHelper;

com.paytm.merchant.CheckSumServiceHelper checkSumServiceHelper = com.paytm.merchant.CheckSumServiceHelper.getCheckSumServiceHelper();

TreeMap<String,String> parameters = new TreeMap<String,String>();
String merchantKey = "xxxxxxxxxxxxxxxxx";
parameters.put("MID", "xxxxxxxxxxxxxxxxxxxxxx");
parameters.put("ORDERID", "${orderId}");
parameters.put("TXNID", "20200113111212800110168201701179744");
parameters.put("TXN_AMOUNT", "10.01");
parameters.put("PAYMENTMODE", "DC");
parameters.put("CURRENCY", "INR");
parameters.put("TXNDATE", "2020-01-13 13:59:03.0");
parameters.put("STATUS", "TXN_SUCCESS");
parameters.put("RESPCODE", "01");
parameters.put("RESPMSG", "Txn Success");
parameters.put("GATEWAYNAME", "HDFC");
parameters.put("BANKTXNID", "777001911059826");
parameters.put("BANKNAME", "JPMORGAN CHASE BANK");
parameters.put("BANKNAME", "JPMORGAN CHASE BANK");

String checkSum = checkSumServiceHelper.genrateCheckSumGAE(merchantKey, parameters);

vars.put("checkSum", checkSum)

这是我得到的错误:

javax.script.ScriptException: Sourced file: inline evaluation of: ``import com.paytm.merchant.CheckSumServiceHelper;  com.paytm.merchant.CheckSumSer . . . '' : Typed variable declaration : Class: com.paytm.merchant.CheckSumServiceHelper not found in namespace : at Line: 3 : in file: inline evaluation of: ``import com.paytm.merchant.CheckSumServiceHelper;  com.paytm.merchant.CheckSumSer . . . '' : com .paytm .merchant .CheckSumServiceHelper 
 in inline evaluation of: ``import com.paytm.merchant.CheckSumServiceHelper;  com.paytm.merchant.CheckSumSer . . . '' at line number 3
    at bsh.engine.BshScriptEngine.evalSource(BshScriptEngine.java:93) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
    at bsh.engine.BshScriptEngine.eval(BshScriptEngine.java:46) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233) ~[java.scripting:?]
    at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:225) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
    at org.apache.jmeter.modifiers.JSR223PreProcessor.process(JSR223PreProcessor.java:44) [ApacheJMeter_components.jar:5.1.1 r1855137]
    at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:935) [ApacheJMeter_core.jar:5.1.1 r1855137]
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:537) [ApacheJMeter_core.jar:5.1.1 r1855137]
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486) [ApacheJMeter_core.jar:5.1.1 r1855137]
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253) [ApacheJMeter_core.jar:5.1.1 r1855137]
    at java.lang.Thread.run(Thread.java:830) [?:?]

对于解决此错误的任何帮助,我们将不胜感激.这可能是一个愚蠢的问题,但是我对此并不陌生,所以请帮忙! :)

Any kind of help to resolve this error will be highly appreciated. It might be a stupid question but I am new to this so please help!! :)

我现在正在使用groovy语法来做到这一点.我无法使用调试采样器在查看结果树"中查看我的校验和变量,但可以在控制台中看到它.该值在控制台中正确显示.但是该变量未导出.

I am now using the groovy syntax for doing this. I am not able to view my checksum variable in View Results Tree with my debug sampler but I am able to see it in the console. The value is shown correctly in console. But the variable is not being exported.

import com.paytm.pg.merchant.CheckSumServiceHelper;

com.paytm.pg.merchant.CheckSumServiceHelper checkSumServiceHelper = com.paytm.pg.merchant.CheckSumServiceHelper.getCheckSumServiceHelper();

TreeMap parameters = new TreeMap();
String merchantKey = "xxxxxxxxxxxxxxxxx";
parameters.put("MID", "xxxxxxxxxxxxxxxxxxxxxx");
parameters.put("ORDERID", "${orderId}");
parameters.put("TXNID", "20200113111212800110168201701179744");
parameters.put("TXN_AMOUNT", "10.01");
parameters.put("PAYMENTMODE", "DC");
parameters.put("CURRENCY", "INR");
parameters.put("TXNDATE", "2020-01-13 13:59:03.0");
parameters.put("STATUS", "TXN_SUCCESS");
parameters.put("RESPCODE", "01");
parameters.put("RESPMSG", "Txn Success");
parameters.put("GATEWAYNAME", "HDFC");
parameters.put("BANKTXNID", "777001911059826");
parameters.put("BANKNAME", "JPMORGAN CHASE BANK");
parameters.put("BANKNAME", "JPMORGAN CHASE BANK");

String checkSum = checkSumServiceHelper.genrateCheckSumGAE(merchantKey, parameters);
Out. println "s====================================ssssss"
OUT. println checkSum
props.put("checkSum", checkSum);

这是我执行此操作时出现的错误:

Here is the error when I run this:

javax.script.ScriptException: javax.script.ScriptException: java.security.InvalidKeyException: Invalid AES key length: 17 bytes

我认为此错误是由于我的输入值引起的.

I think this error is due to my input values.

推荐答案

Beanshell 不是Java,它也是并非100%与Java兼容,您需要坚持

Beanshell is not Java and it isn't 100% compliant with Java, you need to stick to Java 1.5 language level in general.

尤其是Beanshell不支持钻石运算符 ,您需要将其从代码中删除,例如:

In particular Beanshell doesn't support Diamond Operators, you need to remove them from your code like:

TreeMap parameters = new TreeMap();


通常从JMeter 3.1开始,建议使用JSR223测试元素和Groovy脚本语言,原因在:


In general starting from JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting, the reasons are in:

  • Groovy scripts can be compiled and cached while Beanshell is being evaluated each time it's called hence Groovy performance is much higher
  • Groovy supports all underlying JDK language features while Beanshell got stuck at Java 5
  • In addition Groovy provides a lot of enhancements over normal Java SDK

查看 Apache Groovy-为什么和如何使用它文章以获取更多详细信息.

Check out Apache Groovy - Why and How You Should Use It article for more details.

这篇关于在jmeter中运行bean脚本时无法导入com.paytm.merchant.CheckSumServiceHelper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆