DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
BeanShell Sampler (Beta Code)
This sampler allows you to write a sampler using the \[http://www.beanshell.org/ BeanShell\] scripting language.unmigrated-wiki-markupWiki Markup
Please note that the \[http://www.beanshell.org/ BeanShell\] jar file is not included with JMeter; it needs to be separately downloaded. For full details on using \[http://www.beanshell.org/ BeanShell\] please see the \[http://www.beanshell.org/ BeanShell web-site\].
Parameters
Attribute | Description | Required | |||
Name | Descriptive name for this controller that is shown in the tree. | No | |||
Parameters | List of parameters to be passed to the script file or the script. | No | |||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="718fce1b-3ea3-4800-a256-16b4b9b9734f"><ac:plain-text-body><![CDATA[ | Script File | Name of a file to be used as a [http://www.beanshell.org/ BeanShell] script | Yes, unless Script filled in | ]]></ac:plain-text-body></ac:structured-macro> | <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="153592fa-afba-4fba-a008-c388314efadf"><ac:plain-text-body><![CDATA[ |
Script | Script to be passed to [http://www.beanshell.org/ BeanShell] | Yes, unless Script File filled in ]]></ac:plain-text-body></ac:structured-macro> |
N.B. Each Sampler instance has its own \[http://www.beanshell.org/ BeanShell\] interpeter, and Samplers are only called from a single thread.Wiki Markup
If the property "beanshell.sampler.init" is defined, it is passed to the Interpreter as the name of a sourced file. This can be used to define common methods and variables. There is a sample init file in the bin directory: BeanShellFunctionBeanShellSampler.bshrc.
If a script file is supplied, that will be used, otherwise the script will be used.unmigrated-wiki-markup
Before invoking the script, some variables are set up in the \[http://www.beanshell.org/ BeanShell\] interpreter:
The contents of the Parameters field is put into the variable "Parameters". The string is also split into separate tokens using a single space as the separator, and the resulting list is stored in the String array bsh.args.
...
| No Format |
|---|
if (bsh.args[0].equalsIgnoreCase("StopThread")) {
log.info("Stop Thread detected!");
SampleResult.StopThread(bsh.args[1]);
}
return "Data from sample with Label "+Label; |
With the following code you can access the HttpRequest body and modify it:
| No Format |
|---|
sampler = ctx.getCurrentSampler ();
args = sampler.getProperty ("HTTPsampler.Arguments");
httpArg = args.getObjectValue ().getArguments ().get (0);
body = httpArg.getObjectValue ().getProperty ("Argument.value").getStringValue (); |