最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jmeter添加自定義擴(kuò)展函數(shù)之圖片base64編碼示例詳解

 更新時間:2022年01月29日 13:47:50   作者:喬葉葉  
這篇文章主要介紹了jmeter添加自定義擴(kuò)展函數(shù)之圖片base64編碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

打開eclipse,新建maven工程,在pom中引入jmeter核心jar包:

<!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_core -->
<dependency>
    <groupId>org.apache.jmeter</groupId>
    <artifactId>ApacheJMeter_core</artifactId>
    <version>3.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_functions -->
<dependency>
    <groupId>org.apache.jmeter</groupId>
    <artifactId>ApacheJMeter_functions</artifactId>
    <version>3.2</version>
</dependency>

1. 新建一個包c(diǎn)om.mytest.functions,包名要包含functions,因?yàn)閖meter.properties對這塊有配置,可見該文件的classfinder.functions.contain=.functions.

2. 在該包下新建一個類并繼承AbstractFunction,重寫該類的所有方法,具體如下:

package com.mytest.functions;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import org.apache.jmeter.engine.util.CompoundVariable;
import org.apache.jmeter.functions.AbstractFunction;
import org.apache.jmeter.functions.InvalidVariableException;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;
import org.apache.jmeter.threads.JMeterVariables;
import sun.misc.BASE64Encoder;
public class MyBase64 extends AbstractFunction{
    //自定義function的描述
    private static final List<String> desc = new LinkedList<String>();
    static {
        desc.add("圖片路徑");
    }
        desc.add("圖片base64后存放變量");
    private static final String KEY = "__MyBase64";
   
    //存放傳入?yún)?shù)的值的變量
    private Object[] values;
    
    //描述參數(shù)
    public List<String> getArgumentDesc() {
        // TODO Auto-generated method stub
        return desc;
    @Override
    //函數(shù)的執(zhí)行
    public synchronized String execute(SampleResult arg0, Sampler arg1) throws InvalidVariableException {
        JMeterVariables localJMeterVariables = getVariables();
        String str1 = ((CompoundVariable)this.values[0]).execute();
        String str2 = getImgBase64(str1);
        if ((localJMeterVariables != null) && (this.values.length > 1)) {
          String str3 = ((CompoundVariable)this.values[1]).execute().trim();
          localJMeterVariables.put(str3, str2);
        }
        return str2;
    public String getReferenceKey() {
        //提供jmeter函數(shù)助手顯示的名稱
        return KEY;
    public synchronized void setParameters(Collection<CompoundVariable> arg0) throws InvalidVariableException {
        //檢查參數(shù)的個數(shù),支持的方法有2個,具體用法參加api:
        /**
         * protected void checkParameterCount(Collection<CompoundVariable> parameters,
                                   int count)
                            throws InvalidVariableException
            Utility method to check parameter counts.
            Parameters:
            parameters - collection of parameters
            count - number of parameters expected
         * */
        //-----------------
         * 
                                   int min,
                                   int max)
            min - minimum number of parameters allowed
            max - maximum number of parameters allowed
        //checkParameterCount(arg0, 1);
        checkParameterCount(arg0, 1, 2);
        //將參數(shù)值存入變量中
        this.values = arg0.toArray();
    public String getImgBase64(String filePath) {
        InputStream in = null;
        byte[] data = null;
        String result = null;
        try {
            in = new FileInputStream(filePath);
            data = new byte[in.available()];
            in.read(data);
            in.close();
            BASE64Encoder encoder = new BASE64Encoder();
            result = encoder.encode(data);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            
        
        return result;
}

3. 由于我寫的類沒有依賴第三方j(luò)ar包,引入的jmeter核心包都是jmeter自帶的,所以直接導(dǎo)出上面的類為一個jar包,并把這個jar放在jmeter安裝目錄的apache-jmeter-3.2\lib\ext下面

4. 重啟jmeter,打開函數(shù)助手,可看見如下圖:

5. 下面我們測試一下這個函數(shù)是否能使用,新建一個http請求,在post請求里分別添加${__MyBase64(D:\\aa.jpg,imgresult)}和${imgresult}如下圖,注意${__MyBase64(D:\\aa.jpg,imgresult)}一定要在上面

6. 運(yùn)行后可以看到已經(jīng)成功

到此這篇關(guān)于jmeter添加自定義擴(kuò)展函數(shù)之圖片base64編碼示例詳解的文章就介紹到這了,更多相關(guān)jmeter 圖片base64編碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • SpringAOP中的切點(diǎn)表達(dá)式Pointcut詳解

    SpringAOP中的切點(diǎn)表達(dá)式Pointcut詳解

    這篇文章主要介紹了SpringAOP中的切點(diǎn)表達(dá)式Pointcut詳解,Spring?的?AOP?中的一個核心概念是切點(diǎn)(Pointcut),切點(diǎn)表達(dá)式定義通知(Advice)執(zhí)行的范圍,需要的朋友可以參考下
    2023-08-08
  • SpringBoot結(jié)合JWT登錄權(quán)限控制的實(shí)現(xiàn)

    SpringBoot結(jié)合JWT登錄權(quán)限控制的實(shí)現(xiàn)

    本文主要介紹了SpringBoot結(jié)合JWT登錄權(quán)限控制的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • java安全停止線程的方法詳解

    java安全停止線程的方法詳解

    這篇文章主要介紹了java安全停止線程的方法詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-10-10
  • 利用Maven添加工程版本信息及時間戳

    利用Maven添加工程版本信息及時間戳

    這篇文章主要介紹了利用Maven添加工程版本信息及時間戳方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • Springboot hibernate envers使用過程詳解

    Springboot hibernate envers使用過程詳解

    這篇文章主要介紹了Springboot hibernate envers使用過程詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-06-06
  • RestTemplate實(shí)現(xiàn)發(fā)送帶headers的GET請求

    RestTemplate實(shí)現(xiàn)發(fā)送帶headers的GET請求

    這篇文章主要介紹了RestTemplate實(shí)現(xiàn)發(fā)送帶headers的GET請求,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • hibernate 配置數(shù)據(jù)庫方言的實(shí)現(xiàn)方法

    hibernate 配置數(shù)據(jù)庫方言的實(shí)現(xiàn)方法

    這篇文章主要介紹了hibernate 配置數(shù)據(jù)庫方言的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • java實(shí)現(xiàn)斐波那契數(shù)列的3種方法

    java實(shí)現(xiàn)斐波那契數(shù)列的3種方法

    這篇文章主要介紹了java實(shí)現(xiàn)斐波那契數(shù)列的3種方法,有需要的朋友可以參考一下
    2014-01-01
  • Spring IOC和aop的原理及實(shí)例詳解

    Spring IOC和aop的原理及實(shí)例詳解

    這篇文章主要介紹了Spring IOC和aop的原理及實(shí)例詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-11-11
  • 多線程(多窗口賣票實(shí)例講解)

    多線程(多窗口賣票實(shí)例講解)

    下面小編就為大家?guī)硪黄嗑€程(多窗口賣票實(shí)例講解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08

最新評論

高安市| 利辛县| 安阳县| 安图县| 焦作市| 大邑县| 宁河县| 贡嘎县| 苏尼特右旗| 绵阳市| 敦煌市| 呼玛县| 施秉县| 吴忠市| 乌兰察布市| 阿城市| 佛教| 灯塔市| 宁海县| 博爱县| 大竹县| 黄龙县| 通海县| 县级市| 马边| 冀州市| 久治县| 德钦县| 建湖县| 崇明县| 大同市| 烟台市| 肥东县| 南漳县| 洛阳市| 托克托县| 泽州县| 江都市| 绵竹市| 宽城| 苍梧县|