Search code examples
jmeterbeanshell

Jmeter Typed variable declaration : Method Invocation


I have an issue when using Jmeter BeanShell preprocessor. The script invoke jars which I have put them under directory "D:\Software\apache-jmeter-3.0\lib\ext". enter image description here

here is my BeanShell code:

import com.evergrande.api.test.JsonClientUtil;
import com.evergrande.common.utils.JsonUtil;
import com.fasterxml.jackson.databind.node.ObjectNode;

JsonClientUtil jcu=new JsonClientUtil();
ObjectNode node = JsonUtil.createObjectNode();//when I try to use the method in JsonUtil(Class),it came out error

Error:

2016/09/24 22:48:06 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import com.evergrande.api.test.JsonClientUtil; import com.evergrande.common.util . . . '' : Typed variable declaration : Method Invocation JsonUtil.createObjectNode 
2016/09/24 22:48:06 WARN  - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval    Sourced file: inline evaluation of: ``import com.evergrande.api.test.JsonClientUtil; import com.evergrande.common.util . . . '' : Typed variable declaration : Method Invocation JsonUtil.createObjectNode 

I can invoke "createObjectNode" method in my java Code. So,how can I fix this issue? Thank you all.


Solution

    1. Don't put any jars to the lib/ext folder, it should be used for JMeter core components and plugins only. Put your .jar libraries to "lib" folder of somewhere else, they just need to be on the JMeter's Claspath. Alternative option is using Add directory or jar to classpath option on Test Plan level

      extra jars to classpath

    2. JMeter restart is required to pick the jars up.
    3. You can get more readable Beanshell error message by surrounding your code with try/catch block like

      import com.evergrande.api.test.JsonClientUtil;
      import com.evergrande.common.utils.JsonUtil;
      import com.fasterxml.jackson.databind.node.ObjectNode;
      
      try {
          JsonClientUtil jcu=new JsonClientUtil();
          ObjectNode node = JsonUtil.createObjectNode();
      }
      catch (Throwable ex) {
          log.error("Beanshell failure: ", ex);
          throw ex;
      }
      

      So if your script fails you will be able to see stacktrace details in the jmeter.log file. Another approach of getting to the bottom of your Beanshell script failure is adding debug(); command to the beginning of your script. It will trigger verbose output to the console. Check out How to Debug your Apache JMeter Script article for more information on JMeter debugging techniques.