JMeter (6), implementation of the Java request

1.jar包

Add jar package dependencies, and the same attention Jmeter versions:

ApacheJMeter_core.jar,ApacheJMeter_java.jar

2. Write Java request

First inherit AbstractJavaSamplerClient, or to achieve JavaSamplerClient,

The methods and parameters:

getDefaultParameters (), for customizing parameters.

runTest (), the request body.

Arguments categories: parameter management;

addAuguments () to add parameters.

JavaSamplerContext categories: javaSampler container class for receiving, processing the incoming user parameters.

the getParameter ( "parameter Name") is used to get the value of the specified parameter.

SampleResult class, request class.

Code





        // initialize class business functions. Business class is the real feature class used to implement the request. 
        The Request = Request new new the Request (); 
        // operational 
        the try { 
            // the request timed 
            sr.sampleStart (); 
            // call a business method. 
            Result = request.say String (the uname); 
            // setting request is displayed, non-essential. 
            sr.setSamplerData ( "the this IS the uname =" + the uname); 
            // set the response data must. 
            sr.setResponseData (Result, sr.TEXT); 
            // Set the end status request. 
            sr.setSuccessful (to true); 
        } the catch (Exception E) { 
            sr.setResponseData ( "Fail MSG:" + e.getMessage (), sr.TEXT); 
            sr.setSuccessful (to false); 
        } {the finally 
            // request the timer expires. 
            sr.sampleEnd (); 
        } 
        return SR; 
    } 
    
}

After written labeled jar package;

Package store 3.jar

· Extended component itself a jar, put Jmeter the lib \ ext directory.

· Business jar package and all its dependencies, Jmeter into the lib directory.

Then restart jmeter, add the Java request, you can see the new Java requests.

lib directory conflict management:

Some jar package need to use the business itself, may Jmeter lib directory of the original exists. Therefore the following problems:

· Conflict jar package versions.

Too many packets · jar, can not effectively distinguish.

Workaround: Set in plugin_dependency_path in Jmeter.properties

 

Guess you like

Origin www.cnblogs.com/yjh1995/p/12578474.html