zoukankan      html  css  js  c++  java
  • 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 ,放入指定位置就可以马上使用

  • 相关阅读:
    量子纠错码——Stabilizer codes
    量子计算机编程(三)——量子应用
    量子计算机编程(二)——QPU基础函数
    量子计算机编程(一)——QPU编程
    量子搜索算法 Grover search
    因数分解算法、周期查找算法(简化)
    量子傅里叶变换
    简单的量子算法(二):Simon's Algorithm
    简单的量子算法(一):Hadamard 变换、Parity Problem
    Web Scraper——轻量数据爬取利器
  • 原文地址:https://www.cnblogs.com/guanyf/p/10912066.html
Copyright © 2011-2022 走看看