我正在尝试使用JSR223预处理器在JMeter中实现以下代码,但是面临标题中提到的问题。

public class G2bApiServletReturns extends GstUtil
{

 GstUtil gstutil = new GstUtil();
 //generate EK using SEK in Auth response

 String
 SEK="L+Aafhigkjkvw6qkk3XT5TTQ4MbzEpjF+VoVHye8QFyq04bdtGOjvuHWvq3WQLfm";

 byte[] EK = gstutil.decodeBase64StringTOByte(SEK);

String payload="Hello;

//Encrypted Payload



 String encoded_json = GstUtil.encodeBase64String(payload);

 String encrypted_json = gstutil.encrypt(encoded_json, EK);

 //HMAC Value

 String hmac = gstutil.generateHmac(encoded_json, EK);


}
log.info(hmac);


这是错误-

Problem in JSR223 script, JSR223 PreProcessor
javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: hmac for class

最佳答案

删除类声明:

 GstUtil gstutil = new GstUtil();
 //generate EK using SEK in Auth response
 String SEK="L+Aafhigkjkvw6qkk3XT5TTQ4MbzEpjF+VoVHye8QFyq04bdtGOjvuHWvq3WQLfm";
 byte[] EK = gstutil.decodeBase64StringTOByte(SEK);
 String payload="Hello;
//Encrypted Payload
 String encoded_json = GstUtil.encodeBase64String(payload);
 String encrypted_json = gstutil.encrypt(encoded_json, EK);
 //HMAC Value
 String hmac = gstutil.generateHmac(encoded_json, EK);
 log.info(hmac);

07-25 21:42