Well, the option of setting a dummy file (empty .txt) as the first file didn't
work for me for various reasons; the Content-Length was being set to 0 and our
product required it to be accurate. I wrote a pre-processor for it and this
works for me. Hopefully it will help someone else:
>>>>>>>>>>>>>>>>>
import org.apache.jmeter.protocol.http.util.*;
/*
This script is require as a workaround for a bug in JMeter 2.3.2. From the
JMeter forums:
"There is a bug in 2.3.2 - the first file entry does not get re-evaluated. This
has been fixed in SVN."
Basically, if using variables to point at file chunks while iterating through a
loop, the variables are
evaluated on the first iteration and not on subsequent iterations. This script
works around the issue by
setting the correct file chunk on each iteration.
*/
// Parameters are split on `|` and are assinged as follows (defaults in
brackets):
// 1. Filename of media chunk file (REQUIRED).
log.info("Starting AddMediaFileChunk.bsh");
log.debug("AddMediaFileChunk.bsh: Parameters: " + Parameters);
startTime = System.currentTimeMillis();
params = Parameters.split("\\|");
httpSampler = ctx.getCurrentSampler();
httpFiles = httpSampler.getHTTPFiles();
log.debug("AddMediaFileChunk.bsh: Adding: "+params[0]);
// Create file arg, add it to the file arg list and set it.
// Existing files specified inthe HTTP Sampler will be lost.
HTTPFileArg fileChunk = new HTTPFileArg(params[0]);
HTTPFileArg [] newList = {fileChunk};
httpSampler.setHTTPFiles(newList);
finishTime = System.currentTimeMillis();
log.info("Finished AddMediaFileChunk.bsh (" + (finishTime-startTime) + "ms)");
>>>>>>>>>>>>>>>
I pass a single parameter into the script, which is the location of the file I
need to upload (in my case, it's a file which it a chunk of a larger file,
broken up using `split`). By omitting the Content-Length header from the HTTP
Header config element the Sampler seems to set it correctly.
When I try to set the Content-Length header programatically (using
fileChunk.setHeader("Content-Length: 10000") for example) it doesn't seem to
get set, because when I read it back using getHeader() it always returns
`null`. Is this a bug?
Regards,
Noel
----- Original Message -----
From: "Noel O'Brien" <[email protected]>
To: "JMeter Users List" <[email protected]>
Sent: Wednesday, 6 May, 2009 09:16:38 GMT +00:00 GMT Britain, Ireland, Portugal
Subject: Re: HTTP Request File Path Dynamically Calculated?
Ok, I'll try that, thanks Sebb
Regards,
Noel
----- Original Message -----
From: "sebb" <[email protected]>
To: "JMeter Users List" <[email protected]>
Sent: Tuesday, 5 May, 2009 20:27:54 GMT +00:00 GMT Britain, Ireland, Portugal
Subject: Re: HTTP Request File Path Dynamically Calculated?
On 05/05/2009, Noel O'Brien <[email protected]> wrote:
> Hi ,
>
> Does anyone know if variables in the file paths of HTTP requests are
> calculated each time the sampler is executed or only once, upon
> initialisation? I'm trying to use a HTTP sampler in a Loop controller to send
> a file chunk each time. I use the following path:
>
> ${testplan.root}/data/resources/${medium.3gpp.filename}_${current.chunk.index}
>
>
> where ${current.chunk.index} increases each time the Loop Controller
> interates, but it seems to keep sending the first file chunk, which leads me
> to believe this is not evaluated each time the sampler is executed.
There is a bug in 2.3.2 - the first file entry does not get re-evaluated.
This has been fixed in SVN.
> Is there a workaround for this?
Use a dummy first file if you can.
> --
> Regards,
>
> Noel
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
--
Regards,
Noel
--
Regards,
Noel