jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ivan Rancati <i...@sharpmind.de>
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 <ivan@sharpmind.de> 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";
codepage="utf-8";
//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();
while(in.ready()){
  str = in.readLine();
  matcher = pattern.matcher(str);
  out.println(matcher.replaceAll(rep_to));
}
in.close();
out.close();
-- 
View this message in context: http://www.nabble.com/Variable-substitution-in-POSTed-files-tf4055837.html#a11524588
Sent from the JMeter - User mailing list archive at Nabble.com.


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


Mime
View raw message