Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I would like to use JMeter to test a Java service. However the URL I want to test has to be dynamically generated (timestamps, payload hash, etc). I created a self executable jar that outputs a valid URL.

java -jar file.jar

http://www.example.com/api?params=...

The URL changes each iteration. Is there a way I can configure JMeter to run the Jar to get the URL for each HTTP request it makes? Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
221 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to use combination of the following:

  1. OS Process Sampler (to spawn your utility JAR)
  2. Regular Expression Extractor (to get generated URL)

Details:

Given you have java binary in your system path you need the following:

Under Thread Group add an OS Process Sampler

  • Set Command to be java (to be completely sure type full path to your java binary, i.e. "d:appsjava6injava.exe")
  • Under Command Parameters add following: -jar *your.jar* EACH ON SEPARATE LINE, again it's better to use full path to your jar.
  • Add View Results Tree listener at the same level as OS Process Sampler

If you run your Thead Group you should see the following:

System Call Complete. Process Output: http://example.com/api?params=....

I believe that you're interested in something, which comes after "params="

So get this value add a Regular Expression Extractor Post Processor as a child of OS Process sampler with following details:

  • Reference name - any meaningful name for variable, let it be "params"
  • Regular Expression - http://www.example.com/(.*)
  • Template - $1$

That will extract api?params=... so you'll be able to use it as path for your HTTP Request as ${params}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...