On 10/07/07, Ivan Rancati <[EMAIL PROTECTED]> wrote:
sebb-2 wrote:
>
> On 10/07/07, Ivan Rancati <[EMAIL PROTECTED]> 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.
Actually that's Java 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)
The { and } are also meta-characters - repeat count - so you need to
escape those.
And if you define the script in the GUI panel, you need to beware of
JMeter variable replacement which occurs before the script is seen by
BeanShell. Best to use an init file in which you can define a suitable
method. You can pass in variables.
You can of course use any other variable marker characters if you
prefer, but staying with the JMeter syntax might prove useful if
variable replacement is ever added as an enhancement...
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]