jbarresi
jbarresi

Reputation: 33

Using JSON Search Queries with a GET request in JMeter

My org is trying to use JMeter as part of a test automation suite to test some back end REST APIs. Currently one of them supports using JSON queries as a way to get filtered results back from a GET request.

We are using the JMeter UI to create these tests and since all the other API calls work under the HttpClient3.1 HTTP Request implementation that is the implementation that I am currently using to get this to work. With this implementation I get the following when looking at the failure in the results tree (response data portion) I have made the error slightly more generic to protect some IP:

java.lang.IllegalArgumentException: Invalid uri 'https://server:port/restservice/v1/users?firstname_query={"in":["User1FirstName","User2FirstName"]}': Invalid query at org.apache.commons.httpclient.HttpMethodBase.(HttpMethodBase.java:222) at org.apache.commons.httpclient.methods.GetMethod.(GetMethod.java:89) at org.apache.jmeter.protocol.http.sampler.HTTPHC3Impl.sample(HTTPHC3Impl.java:229) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1146) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1135) at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:434) at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261) at java.lang.Thread.run(Unknown Source)

I have also tried the same request using the Java implementation and get a similar result.

If anyone has any ideas or if you need more information let me know and thank you again in advance for any help you may be able to provide.

Upvotes: 2

Views: 952

Answers (1)

Dmitri T
Dmitri T

Reputation: 168002

Your HTTP Request configuration is a little bit incorrect. JSON entities contain braces {} which are not allowed in URLs so you need to encode them.

Configure your HTTP Request sampler like:

HTTP Request JSON

Make sure "Encode" box is ticked.

And this way you will be able to send JSON with HTTP GET Requests. You can use View Results Tree listener to inspect request and response details:

View Results Tree

You might also need to add HTTP Header Manager to your Test Plan and configure it to send Content-Type header with the value of application/json. See Testing SOAP/REST Web Services Using JMeter article for more details on properly configuring JMeter for testing REST APIs.

Upvotes: 1

Related Questions