2

Does any one have a clue why jmeter is passing empty POST after I modify request body.

I have a request with massive JSON in a body (unfortunately I can't paste an image with it)

I have BSF PreProcessor attached to this request:

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.jmeter.config.Argument;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.samplers.Sampler;
import org.apache.jmeter.protocol.http.sampler.HTTPSampler;

Sampler sampler = ctx.getCurrentSampler();
String param = sampler.getArguments().toString();
String replacerMCI = vars.get("vMainCaseId");

Pattern r = Pattern.compile("(?<=mainCaseId\":\")(\\d{2,})");
Matcher m = r.matcher(param);
String paramRep = m.replaceAll(replacerMCI);

Argument arg = new Argument("", paramRep);
Arguments argList = new Arguments();
argList.addArgument(arg);
sampler.setArguments(argList);

When I'm logging to console to see if the argument is modified I can see it has a new value but when I start the test I see that POST is send with empty data.

POST https://servername:9443/teamworks/ajaxCoach
POST data:
Cookie Data:
[some cookie data]

1 Answers1

0

You code looks good, just remove the following line:

Sampler sampler = ctx.getCurrentSampler();

as

  1. org.apache.jmeter.samplers.Sampler class doesn't have "setArguments" mehod
  2. There is a pre-defined variable sampler which is a shorthand to parent sampler, I guess it's HTTPSamplerProxy in your case

Going forward if you experience any problem with your script look into jmeter.log file as for Pre and PostProcessors nothing will be shown in GUI even if they fail.

If you're using Beanshell as a BSF language you can add debug(); line at the beginning of your test, Beanshell interpreter will print debug information to STDOUT

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Hi Dmitri! Thanks for hints. I changed the implementation a bit. Now I use HTTPArgument directly and the POST is being send but... I found another issue. 1. The POST is send with equal sign at the begining of request body Is there any way to remove this equal sign from the message? POST looks like this: ={data:""; ...} – Olaf Pospischil Apr 07 '15 at 10:11
  • You can just remove it as `arg.setValue(arg.getValue().replaceFirst("\\=",""));` – Dmitri T Apr 07 '15 at 10:49
  • Hurra! ;-) So simple. Thanks for help. I can not give kudos unfortunately as I have not enough reputation points. – Olaf Pospischil Apr 07 '15 at 13:40