How to parse Jmeter response and make a new request

Simon Wang picture Simon Wang · Jul 3, 2012 · Viewed 64.8k times · Source

I'm using jMeter to test a Tomcat application. I need to parse the jMeter response and make a second request. The first response looks like this:

<responseData class="java.lang.String">&lt;html&gt;&#xd;
&lt;body&gt;&#xd;
ERROR=0&#xd;
MSG=N/A&#xd;
FILELIST=1555;1340778737370;1526545487;&#xd;
VERSION=1.002&#xd;
URL=https://192.168.100.46/updserver/download?action=signature_download&amp;token=&#xd;
INTERVAL=0&#xd;
&lt;/body&gt;&#xd;
&lt;/html&gt;&#xd;
</responseData>

I need to extract the "FILELIST" and "URL" variables and inject them into a new URL:

https://192.168.100.46/updserver/download?action=signature_download&amp;token=1555;1340778737370;1526545487;&#xd;

I know there is some post-processor to do that, but no clue how to do it. BTW, the second request will download some file from the Tomcat servlet, is there a way to let jMeter just download the stream but without writing to a physical file? So that I could do a load performance test against my servlet.

Answer

ant picture ant · Jul 3, 2012

Ok so you already know how to extract url out of your response, I described how in my previous answer :

https://stackoverflow.com/a/11188349/169277

But here I'll just expand on that. So you have your sampler and you already got ${url}. Now you need FILELIST and assemble new url.

Assuming you already have request and url extractor in place. Add a new Regular expression extractor.

Right click on request sampler -> Post Processors -> Regular Expression Extractor

Reference Name : FILELIST
Regular Expression : FILELIST=(\S+)
Template : $1$
Match No. (0 for Random): 1

So now you have 1 request sampler and 2 regular expression extractors. You need to add additional post processor to be able to assemble the new url.

Right click on request sampler -> Post Processors -> BSF PostProcessor

Choose the beanshell from the language droplist under the Script language and in the big field Script: paste this :

vars.put("NEW_URL", "${__javaScript('${url}'.replace('&#xd;'\,'${FILELIST}'))}");

And now you have ${NEW_URL} to use further in your tests.

There is always more than one way of solving problems, this one liner looks really ugly but it serves the purpose.

In my test the result is as you requested (Debug Sampler) :

url=https://192.168.100.46/updserver/download?action=signature_download&amp;token=&#xd;
FILELIST=1555;1340778737370;1526545487;&#xd;
NEW_URL=https://192.168.100.46/updserver/download?action=signature_download&amp;token=1555;1340778737370;1526545487;&#xd;

EDIT :

I think I don't understand how you name your variables. But the end result is the one you described in your question. Please see the .jmx test attached with working example :

http://www.filefactory.com/file/1q7nfitmh4qd/n/so_11309469_jmx

It's a jmeter .jmx file working with 2.6+ version of jmeter