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"><html>
 <body>
 ERROR=0
 MSG=N/A
 FILELIST=1555;1340778737370;1526545487;
 VERSION=1.002
 URL=https://192.168.100.46/updserver/download?action=signature_download&token=
 INTERVAL=0
 </body>
 </html>
 </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&token=1555;1340778737370;1526545487;
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.
You can use Regular Expression extractor to extract the e-mail address from the request URL. Add Regular Expression Extractor as a child of sampler which sends the post request. In the Regular Expression Extractor select URL in Response Filed to check instead of Body.
JMeter Sampler elements allow taking actions in any place in the test, without depending on a specific request. In this example a JSR223 sampler will be used to send HTTP requests to either BlazeMeter or JMeter websites, based on the thread id.
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('
'\,'${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&token=
 FILELIST=1555;1340778737370;1526545487;
 NEW_URL=https://192.168.100.46/updserver/download?action=signature_download&token=1555;1340778737370;1526545487;
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
To capture part of the response use Regular Expression Extractor.
You can test your regex expression on response data using ViewResultsTree listener. Just select Regexp tester in the drop-down box at the bottom of the left hand panel in your ViewResultsTree listener.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With