You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Noel O'Brien <no...@newbay.com> on 2009/05/05 21:16:51 UTC

HTTP Request File Path Dynamically Calculated?

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. 

Is there a workaround for this? 

-- 
Regards, 
Noel 

Re: HTTP Request File Path Dynamically Calculated?

Posted by sebb <se...@gmail.com>.
On 06/05/2009, Noel O'Brien <no...@newbay.com> wrote:
> 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?

The HTTPFileArg header field is only intended for temporary storage of
the post body header by the methods that generate the body. It's
nothing to do with HTTP headers.

However, getHeader() should return whatever you add with setHeader() -
unless the HTTPFileArg has been used meanwhile.

>  Regards,
>  Noel
>
>
>  ----- Original Message -----
>  From: "Noel O'Brien" <no...@newbay.com>
>  To: "JMeter Users List" <jm...@jakarta.apache.org>
>
> 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" <se...@gmail.com>
>  To: "JMeter Users List" <jm...@jakarta.apache.org>
>  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 <no...@newbay.com> 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: jmeter-user-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>
>
>  --
>  Regards,
>  Noel
>
>
>
> --
>  Regards,
>
> Noel
>

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


Re: HTTP Request File Path Dynamically Calculated?

Posted by Noel O'Brien <no...@newbay.com>.
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" <no...@newbay.com> 
To: "JMeter Users List" <jm...@jakarta.apache.org> 
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" <se...@gmail.com> 
To: "JMeter Users List" <jm...@jakarta.apache.org> 
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 <no...@newbay.com> 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: jmeter-user-unsubscribe@jakarta.apache.org 
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org 



-- 
Regards, 
Noel 


-- 
Regards, 
Noel 

Re: HTTP Request File Path Dynamically Calculated?

Posted by Noel O'Brien <no...@newbay.com>.
Ok, I'll try that, thanks Sebb 

Regards, 
Noel 
----- Original Message ----- 
From: "sebb" <se...@gmail.com> 
To: "JMeter Users List" <jm...@jakarta.apache.org> 
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 <no...@newbay.com> 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: jmeter-user-unsubscribe@jakarta.apache.org 
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org 



-- 
Regards, 
Noel 

Re: HTTP Request File Path Dynamically Calculated?

Posted by sebb <se...@gmail.com>.
On 05/05/2009, Noel O'Brien <no...@newbay.com> 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: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org