leohoward
leohoward

Reputation: 39

Jmeter - jsr223 - Error with external library

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

enter image description here

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

enter image description here

Please advise Many thanks

Upvotes: 0

Views: 1039

Answers (1)

Dmitri T
Dmitri T

Reputation: 168157

  1. You should place any 3rd-party .jar libraries to lib folder. lib/ext is for JMeter Plugins. See JMeter Classpath user manual entry for more details.
  2. org.web3j.core library doesn't contain org.web3j.crypto.Credentials class, you will need to add this library to JMeter's lib folder
  3. Since JMeter 3.1 you're supposed to be using Groovy language for scripting especially when it comes to resource intensive cryptographic operations, see Beanshell vs. JSR223 vs. Java For JMeter: Complete Showdown for more details so consider switching the language to groovy because java is not real Java, it's Beanshell interpreter

Upvotes: 1

Related Questions