jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ivan Rancati <>
Subject Re: Variable substitution in POSTed files
Date Tue, 10 Jul 2007 16:36:46 GMT

sebb-2 wrote:
> On 10/07/07, Ivan Rancati <> wrote:
> Not within JMeter.
> Though could use the BeanShell pre-processor to fixup the file if you
> are prepared to write the necessary Java code.

Thanks for the suggestion. It works well, with one small problem, which I am
sure depends on my misunderstanding of the BeanShell regex.
In the file to be processed, I can't specify the variables with the
${variablename} JMeter syntax, which causes BeanShell syntax errors when the
regex is compiled, regardless of how I escape the dollar sign (with zero,
one, two, four backslashes)

Here is some quick and dirty code, in case anybody else needs it. 

infile = "/u/ivan/svn/addCustomer.template";
outfile = "/u/ivan/svn/addCustomer.xml";
//this is the placeholder to look for in the file. If you get it to work
with ${USERNAME} let me know
rep_from = "USERNAME";
//this is the User Defined Variable in JMeter
rep_to = vars.get("username");

import java.util.regex.*;

Pattern pattern;
Matcher matcher;

pattern = Pattern.compile(rep_from);

in_file = new FileInputStream(infile);
in_r = new InputStreamReader(in_file,codepage);
in = new BufferedReader(in_r);
out_file = new FileOutputStream(outfile);
out_w = new OutputStreamWriter(out_file,codepage);
out = new PrintWriter(out_w);

StringBuffer sbr  = new StringBuffer();
  str = in.readLine();
  matcher = pattern.matcher(str);
View this message in context:
Sent from the JMeter - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message