jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Deepak Shetty <>
Subject Re: CSV with variable number of columns?
Date Tue, 06 Dec 2011 01:26:40 GMT
Assuming you have a CSV Data Set Config with a single line
/foo/bar.html|header1name: header1value|header2name:
header2value|headerNname: headerNvalue

Configure the CSV Data Set Config to have a single variable e.g. var1 and
delimiter ="," i.e. everything will be read into variable var1.
Then Attach a beanshell pre processor under the HTTP Sampler

So your test plan looks like
+CSV Data Set Config (delimiter is still ',' , single variable)
+HTTP Sampler
++BeanShell Pre Processor (With the code below)
++HTTP Header Manager (empty)
+Debug Sampler (for debug)
+HTTP Sampler
+View results Tree (for debug)

import org.apache.jmeter.protocol.http.control.HeaderManager;
import org.apache.jmeter.protocol.http.control.Header;

String val = vars.get("var1"); //var1 is what is defined in CSV data set
config as the variable name
String[] entries = val.split("\\|"); // | is special for regex so escape it
HeaderManager hm = sampler.getHeaderManager(); //needs a valid header
manager in scope
for(int i=1;i<entries.length;i++){ //because the first value is a path
   String entry = entries[i];
   String[] keyVal = entry.split(":");
   Header h = new Header(keyVal[0].trim(),keyVal[1].trim());

//sampler.setPath(entries[0]); //not sure if I should be doing this
basically this sets the sampler path to that read from the CSV

works on 2.3.4(no error checking!) - hopefully works on later versions
If you have a maximum number of entries allowed (i.e. at the most 10
headers , you might be able to avoid having to code it)


On Mon, Dec 5, 2011 at 4:42 PM, Jason Gilroy <>wrote:

> Thank you Deepak.  I would appreciate any sample code or useful references
> you could provide as I haven't touched any of the BeanShell stuff in JMeter
> before.
> Jason
> -----Original Message-----
> From: Deepak Shetty []
> Sent: Monday, December 05, 2011 7:17 PM
> To: JMeter Users List
> Subject: Re: CSV with variable number of columns?
> Hi
> One way is read all the header values from the CSV into a single variable .
> Then write a BeanShell Pre processor for the sampler which uses
>  sampler.getHeaderManager().add(header)
> So you will read the variable in beanshell, split it on the delimiter and
> add it to the sampler in a loop.
> Do you need sample code ?.
> regards
> deepak
> You want JMeter to make GET call which has a variable number of headers?
> and you have
> On Mon, Dec 5, 2011 at 1:46 PM, Jason Gilroy <
> >wrote:
> > I have a CSV (ok, PSV - pipe separated file) file that looks something
> > like:
> >
> > /foo/bar.html|header1name: header1value|header2name:
> > header2value|...|headerNname: headerNvalue
> >
> > (this is the GET request coming into our system, followed by the list of
> > HTTP Headers that accompanied that request.)  I'm trying to replay these
> in
> > a test environment, but having a tough time envisioning a way to handle
> the
> > variable number of headers that might come with each request; both
> getting
> > them into individual variables and then stuffing them into the Header
> > Manager.  I would really appreciate any ideas for how to approach this.
> >
> > Thanks,
> > J
> >
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message