Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

java - JMeter - Use jar output for URL to load test

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

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

1 Reply

0 votes
by (71.8m points)

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}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...