Ravi Varanasi
Ravi Varanasi

Reputation: 67

beanshell sampler, i want access java code from jmeter

I have stuck with below error in jmeter.

Response code: 500 Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval In file: inline evaluation of'

bean shell code:

import tools.JmeterTools; 

JmeterTools jt = new JmeterTools();  

int num = Integer.parseInt(vars.get("A1"));

num = jt.randInt(num);  

vars.put("A1", num.toString());  

num =  Integer.parseInt(vars.get("B1")); 

num = jt.sqrInt(num);   

vars.put("B1", num.toString());  

vars.put("B2", jt.sqrstr(vars.get("B2")));  

}

eclipse code:

package tools;
import java.util.Random;

public class JmeterTools {

    public JmeterTools(){
    }

    public int randInt (int x){
        Random randomGenerator= new Random();
        return randomGenerator.nextInt(x);
    }

    public int sqrInt(int x){
        return x*x;
    }

    public String sqrstr(String x){
        int y= Integer.parseInt(x);
        return String.valueOf(y*y);
    }

}

Upvotes: 0

Views: 1701

Answers (1)

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34556

Did you:

  • export your JmeterTools class as a JAR
  • Is the JAR OK ?
  • put the JAR in jmeter/lib folder ?

Also, you have a } at end of your beanshell code that shouldn't be there.

Upvotes: 1

Related Questions