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

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

2,直接上代码:

  

package com.mytest.functions;

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 Base64 extends AbstractFunction
{
  private static final List<String> desc = new LinkedList();
  private static final String KEY = "__Base64_string";
  private Object[] values;

  public synchronized String execute(SampleResult paramSampleResult, Sampler paramSampler)
    throws InvalidVariableException
  {
    JMeterVariables localJMeterVariables = getVariables();
    String str1 = ((CompoundVariable)this.values[0]).execute();

    String str2 = new BASE64Encoder().encode(str1.getBytes());

    if ((localJMeterVariables != null) && (this.values.length > 1)) {
      String str3 = ((CompoundVariable)this.values[1]).execute().trim();
      localJMeterVariables.put(str3, str2);
    }

    return str2;
  }

  public synchronized void setParameters(Collection<CompoundVariable> paramCollection)
    throws InvalidVariableException
  {
    checkMinParameterCount(paramCollection, 1);
    this.values = paramCollection.toArray();
  }

  public String getReferenceKey()
  {
    return "__Base64_string";
  }

  public List<String> getArgumentDesc()
  {
    return desc;
  }

  static
  {
    desc.add("String to calculate Base64 hash ");
    desc.add("Name of variable in which to store the result (optional),作者:guanyf");
  }
}

3,打包 jar ,放入指定位置就可以马上使用

 

转载于:https://www.cnblogs.com/guanyf/p/10912066.html

JMeter是一个开源的压力测试工具,用于对Web应用、应用程序接口(API)和其他网络服务进行性能测试。JMeter插件系统允许用户扩展JMeter的功能,并提供了一系列的插件来满足不同的测试需求。 `jmeter-plugins-cmn-jmeter-0.7.jar` 这个文件看起来像是 JMeter 的一个插件包,不过其版本信息似乎有些过时(0.7版),通常推荐使用最新的稳定版本以获得最佳功能和兼容性。 ### 下载步骤: 1. **访问官方站点**:首先前往 [Apache JMeter官方网站](https://jmeter.apache.org/) 或者 [Apache JMeter GitHub页面](https://github.com/apache/jmeter),获取关于最新版本的信息以及如何安装插件的相关指导。 2. **查找所需插件**:在网站上搜索 `Common Plugins` 或者直接输入 `jmeter-plugins-cmn` 来查找相关的插件列表。请注意,此插件的名称可能会有所不同,在最新的文档或API页面中,应找到对应的功能描述及下载链接。 3. **确认版本和兼容性**:在选择下载之前,请务必确认该插件是否与您当前使用的 JMeter 版本兼容。如果插件有多个版本供选择,请查阅它们之间的差异说明,选择最适合您的版本。 4. **下载并安装**:点击对应的下载链接,将文件保存到本地计算机上。然后打开JMeter,通过“添加JAR或目录”按钮,在JMeter的配置文件 `lib/ext` 目录下导入插件的 .jar 文件。确保在启动JMeter前已更新配置文件路径以包含新导入的插件。 5. **验证安装**:完成以上步骤后,重启JMeter并检查插件是否成功加载。通常,新插件会出现在JMeter的“取样器”、“监听器”等组件菜单中,你可以从这里确认插件是否可用。 ### 安全提示: - 确保下载来自可信源的插件。避免从不可信或未经授权的第三方站点下载文件,以防恶意软件感染。 - 使用杀毒软件扫描文件以确保安全性。 ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值