jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: Custom function is not picked up
Date Tue, 03 Jul 2012 20:22:27 GMT
On 3 July 2012 19:56, Eric Jain <eric.jain@gmail.com> wrote:
> I created a function like the one below, and put the class file into a
> new jar file in JMeter's lib/ext. But when I use ${__Json()} (e.g. for
> the POST body of an HTTP request sampler), I always end up with
> '${__Json()}' instead of '{"x":42}'. Built-in functions such as
> ${__Random(1,10)} work fine. Do I need to register custom functions
> somewhere?

No, but they do need to be in a package with a specific naming convention

See the classfinder.functions. definitions in jmeter.properties (and
in the jmeter.log file)



>
> package testing;
>
> import java.util.Collection;
> import java.util.Collections;
> 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;
>
> public class RandomEventFunction extends AbstractFunction {
>
>         private static final String KEY = "__Json";
>
>         @Override
>         public List<String> getArgumentDesc() {
>                 return Collections.emptyList();
>         }
>
>         @Override
>         public String execute(SampleResult previouResult, Sampler sampler) {
>                 return "{\"x\":42}";
>         }
>
>         @Override
>         public String getReferenceKey() {
>                 return KEY;
>         }
>
>         @Override
>         public void setParameters(Collection<CompoundVariable> variable) {
>
>         }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Mime
View raw message