tags:

views:

899

answers:

2

I'd like to test a Java Service Call. My first attempt was to use the "Java Request Sampler" The docu says

This sampler lets you control a java class that implements the JavaSamplerClient interface.

I'm not sure how to get the org.apache.jmeter.protocol.java.sampler.JavaSamplerClient Interface as there is no Maven Artifact nor provided binaries on the JMeter side. Just a JMeter Maven Plugin (which is not what I'm looking for). I could install the needed binaries in my local Maven Repository, I Just don't know where they are available.

Wondering if anybody at all is using the "Java Request Sampler" ?

P.S. Maybe I should try the JUnit Sampler

A: 

We are building with ANT and are using the JARs, which are located in the binary file from JMeter under \lib\ext. The AbstractJavaSamplerClient which is used for the Java Request Sampler is located in the file \lib\ext\ApacheJMeter_java.jar. For working with this abstract class, you also have to import the JAR file \lib\ext\ApacheJMeter_core.jar, which is for example holding the classe SampleResult.

After building our Java class we put the resulting JAR file also in the folder \lib\ext. After that, you can start JMeter and you're able to select your Java class in a Java Request Sampler.

Here is an example of such a Java Request Sampler:

public class JavaRequestSamplerDemo extends AbstractJavaSamplerClient {

  @Override
  public SampleResult runTest(JavaSamplerContext ctx) {
    JMeterVariables vars = JMeterContextService.getContext().getVariables();
    vars.put("demo", "demoVariableContent");

    SampleResult sampleResult = new SampleResult();
    sampleResult.setSuccessful(true);
    sampleResult.setResponseCodeOK();
    sampleResult.setResponseMessageOK();
    return sampleResult;
  }  
}
Steve
A: 

Anyone knows what JMeterContextService.getContext().getVariables(); gets? I mean, which UI element/area does this method try to fetch?

photon