Reputation: 39
Jmeter - jsr223 - Error with external library
My java code with import org.web3j, run as expected, no error
package test;
import java.nio.charset.StandardCharsets;
import org.web3j.crypto.Credentials;
import org.web3j.crypto.Sign;
import org.web3j.utils.Numeric;
public class test2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String privateAccountKey = "privateAccountKey ";
Credentials credentials = Credentials.create(privateAccountKey);
String message="messageABC";
byte[] messageBytes = message.getBytes(StandardCharsets.UTF_8);
Sign.SignatureData signature = Sign.signPrefixedMessage(messageBytes, credentials.getEcKeyPair());
byte[] value = new byte[65];
System.arraycopy(signature.getR(), 0, value, 0, 32);
System.arraycopy(signature.getS(), 0, value, 32, 32);
System.arraycopy(signature.getV(), 0, value, 64, 1);
System.out.println("signature: " + Numeric.toHexString(value));
}
}
In jmeter, I use JSR223 PostProcessor
I have added core-5.0.0.jar to folder apache-jmeter-5.5\lib\ext (Download from https://mvnrepository.com/artifact/org.web3j/core/5.0.0) and restart jmeter
After run, error is shown javax.script.ScriptException: Sourced file: inline evaluation of: import java.nio.charset.StandardCharsets; import org.web3j.crypto.Credentials; i . . . '' : Typed variable declaration : Class: Credentials not found in namespace : at Line: 7 : in file: inline evaluation of:
import java.nio.charset.StandardCharsets; import org.web3j.crypto.Credentials; i . . . '' : Credentials
in inline evaluation of: ``import java.nio.charset.StandardCharsets; import org.web3j.crypto.Credentials; i . . . '' at line number 7
Please advise Many thanks
Upvotes: 0
Views: 1039
Reputation: 168157
org.web3j.core
library doesn't contain org.web3j.crypto.Credentials
class, you will need to add this library to JMeter's lib foldergroovy
because java
is not real Java, it's Beanshell interpreterUpvotes: 1