1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这里就不再赘述

2,代码如下:

package com.mytest.functions;

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 org.apache.jorphan.util.JOrphanUtils;

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;

import java.util.Collection;

import java.util.LinkedList;

import java.util.List;

public class MD5 extends AbstractFunction {

    private static final List<String> desc = new LinkedList<String>();

    private static final String KEY = "__MD5";

    static {

        desc.add("String to calculate MD5 hash");

        desc.add("Name of variable in which to store the result (optional),作者:管永飞");

    }

    private Object[] values;
public MD5() { } @Override public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException { JMeterVariables vars = getVariables(); String str = ((CompoundVariable) values[0]).execute(); MessageDigest digest; try { digest = MessageDigest.getInstance("md5"); } catch (NoSuchAlgorithmException ex) { return "Error creating digest: " + ex; } String res = JOrphanUtils.baToHexString(digest.digest(str.getBytes()));
if (vars != null && values.length > 1) { String varName = ((CompoundVariable) values[1]).execute().trim(); vars.put(varName, res);
}
return res; }
@Override public synchronized void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException { checkMinParameterCount(parameters, 1); values = parameters.toArray(); } @Override public String getReferenceKey() { return KEY; } @Override public List<String> getArgumentDesc() { return desc; } }

jmeter添加自定义扩展函数之MD5加密的更多相关文章

  1. jmeter添加自定义扩展函数之String---base64加密

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  2. Java语言编写MD5加密方法,Jmeter如何给字符串MD5加密

    package md5package; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; ...

  3. jmeter添加自定义扩展函数之图片base64编码

    打开eclipse,新建maven工程,在pom中引入jmeter核心jar包: <!-- https://mvnrepository.com/artifact/org.apache.jmete ...

  4. jmeter添加自定义扩展函数之DoubleSum

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  5. jmeter添加自定义扩展函数之if判断

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  6. jmeter添加自定义扩展函数之小写转换大写

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  7. jmeter添加自定义扩展函数之大写转换小写

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  8. jmeter添加自定义扩展函数之Strng---base64解密

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  9. jmeter添加自定义扩展函数之图片base64

    原文连接:---------https://www.cnblogs.com/qiaoyeye/p/7218770.html----------- 打开eclipse,新建maven工程,在pom中引用 ...

随机推荐

  1. Pikachu漏洞练习平台实验——php反序列化、XXE、SSRF(九)

    1.序列化和反序列化 1.1.概述 在理解这个漏洞前,你需要先搞清楚php中serialize(),unserialize()这两个函数. 序列化serialize()序列化说通俗点就是把一个对象变成 ...

  2. 初识内存分配ByteBuf

    初识ByteBuf: ByteBuf 是Netty 整个结构里面最为底层的模块,主要负责把数据从底层IO 里面读到ByteBuf,然后传递给应用程序,应用程序处理完成之后再把数据封装成ByteBuf ...

  3. LayaBox 常用技巧

    1.修改IDE的菜单 找到安装路径的LayaAirIDE\resources\app\out\vs\layaEditor\renders\laya.editorUI.xml 注意事项: 1.mask的 ...

  4. What is one-hot?

    SEO: libtorch 如何 OneHot ? torch OneHot 源代码 ? https://www.tensorflow.org/api_docs/python/tf/one_hot 最 ...

  5. PHP实现上传文件到服务器

    <?php /**************************** *** 功能:上传文件到服务器 ****************************/ session_start() ...

  6. K3 cloud选单时候必须把必录的数据录完以后才可以选单

    解决办法:在bos中把选单按钮的提交时候校验打勾

  7. 2018-8-10-C#-TextBlock-上标

    title author date CreateTime categories C# TextBlock 上标 lindexi 2018-08-10 19:16:52 +0800 2018-2-13 ...

  8. R语言ggplot2软件包

    相比r语言自带软件包,ggplot2有以下特色 图形语法的核心:统计图形是数据向几何对象属性的一个映射.

  9. zabbix入门之添加监控项

    zabbix入门之添加监控项 添加一个不带参数的监控项(system.cpu.switches) 进入"配置"-->"主机"选择某主机的"监控项 ...

  10. MySQL04-- 版本区别及管理

    目录 MySQL版本区别及管理 一.MySQL5.6与MySQL5.7安装的区别 二.MySQL用户权限管理 三.MySQL连接管理 四.MySQL启动关闭流程 五.MySQL实例初始化配置 六.My ...