Search code examples
javajmeterbeanshell

Using Guava Optional with External SDK in JMeter


We are using an SDK that returns the type Guava Optional Optional<User> in a method. In JMeter, we are using beanshell sample script to call that method in the following manner:

Optional<User> = new SDKClass().retrieveUser(...);

The error that we're seeing is:

2015/10/06 14:02:18 WARN  - jmeter.protocol.java.sampler.BeanShellSampler: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval    Sourced file: inline evaluation of: ``import com.google.common.base.Optional; import com.google.gson.Gson; import com. . . . '' : Typed variable declaration : Method Invocation retrieveUser

In the SDK, the method we are trying to invoke has the following signature:

public Optional<User> retrieveUser(HttpServletRequest request, HttpServletResponse response) {

So, it looks like the JMeter beanshell script doesn't have a problem calling the SDK itself, only this specific method which returns the Guava Optional.


Solution

  • Beanshell does not understand generics syntax.

    Use JSR223 Test element + groovy.

    Download groovy, unzip it and put the groovy-all-xxx.jar located in embeddable in jmeter/lib, restart jmeter and it will be available.