2

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)

Here is the error I am getting as a result:

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!! :)

EDIT:

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.

1 Answers1

1

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

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

TreeMap parameters = new TreeMap();

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

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

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks for your answer! I did remove the diamond operators, after that my code is getting compiled but it is still not executing the checksum generator code. But now there are no errors. I am doubtful that my code is running or not. Can I use a java package (jar file) in my groovy code? – Sankalan Parajuli Jan 16 '20 at 07:51
  • You can use 3rd-party jars given you copy them to [JMeter Classpath](https://jmeter.apache.org/usermanual/get-started.html#classpath) (including all the dependencies, if any). Given your code works you can check `checkSum` variable value using ]Debug Sampler and View Results Tree listener](https://www.blazemeter.com/blog/how-debug-your-apache-jmeter-script/), combination. If you don't see the variable - look for suspicious entries in [jmeter.log file](https://jmeter.apache.org/usermanual/get-started.html#logging) – Dmitri T Jan 16 '20 at 08:23
  • Thank you for your help! Doing that now! Edited my question with some more information. – Sankalan Parajuli Jan 16 '20 at 08:31
  • It worked! Thank you!! The Invalid key error was due to my input value!! – Sankalan Parajuli Jan 16 '20 at 08:50