You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Kornelis Sietsma <ko...@sietsma.com> on 2006/04/03 10:06:48 UTC

Re: embedding a regexp result in a http request

I did it eventually with a BeanShell function - and I've remembered why 
I have a love/hate relationship with Jmeter in the past - it's great 
when it works, but when something breaks, it has some of the worst error 
messages in the world...

I'm sure there are cleaner ways to do this, but what I did was:
- Create a beanshell init file (for a single point for global bean shell 
functions)
- Add a function to this file:
fixAmps(s) {
  return new String(s).replaceAll("&amp;","&");
}

- In my request, assuming the regexp containing my parameters is FOOBAR, 
set the Path to:
/myquery.do${__BeanShell(fixAmps("${FOOBAR}"))}

I tried this first in Javascript, but got so many meaningless error 
messages I gave up and tried BeanShell, which I could at least put 
neatly in a stand-alone file.

- Korny

sebb wrote:
> On 31/03/06, Kornelis Sietsma <ko...@sietsma.com> wrote:
>   
>> Hi - I'm having some pain trying to do something that should be simple.
>>
>> I have a page with a number of URLs in it, of the form:
>> a
>> href="/myquery.do;jsessionid=12345?param1=12345&amp;param2=abcde&amp;param3=foo"
>>
>> I'm trying to simply follow one of these URLs in a new http request -
>> but while I can grab the whole request into a regexp fairly easily, as
>> soon as I substitute it into a HTTP Request (by putting
>> "${MY_REGEXP_g1}" in the "Path" field) I have real pain - the escaped
>> form of the ampersands ("&amp;" is  sent to the tested application, so
>> it sees the parameters as "param1", "amp;param2", "amp;param3" and so on.
>>
>> Does anyone have any suggestions for getting around this?  Currently
>> I've changed my regexp to extract each param as a separate group, but
>> it's slow to build an expression this way, and a bit fragile if the
>> application changes it's parameter order or the like.
>>     
>
> You could use a javascript or beanshell function to replace the &amp;
> with & in the output variable - assuming you want to replace them all.
>
> You might be able to do this in the RegexExtractor itself, by wrapping
> the $1$ in a function call.
>
> Or you can do the same on the sampler.
>
> Or you could be really sneaky and use the BeanShell Assertion to
> change the value of the variable. This relies on the fact that
> Assertions are called after the Post-Processors, so the output
> variable from the Reg Ext will be available for use.
>
> S.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>   


-- 
Kornelis Sietsma e-mail: korny at my surname dot com


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


Re: embedding a regexp result in a http request

Posted by sebb <se...@gmail.com>.
On 03/04/06, Kornelis Sietsma <ko...@sietsma.com> wrote:
> I did it eventually with a BeanShell function - and I've remembered why
> I have a love/hate relationship with Jmeter in the past - it's great
> when it works, but when something breaks, it has some of the worst error
> messages in the world...

Please file bugs for ones that are not clear.

> I'm sure there are cleaner ways to do this, but what I did was:
> - Create a beanshell init file (for a single point for global bean shell
> functions)
> - Add a function to this file:
> fixAmps(s) {
>  return new String(s).replaceAll("&amp;","&");
> }
>
> - In my request, assuming the regexp containing my parameters is FOOBAR,
> set the Path to:
> /myquery.do${__BeanShell(fixAmps("${FOOBAR}"))}
>
> I tried this first in Javascript, but got so many meaningless error
> messages I gave up and tried BeanShell, which I could at least put
> neatly in a stand-alone file.

The errors were probably because of unescaped commas...

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