Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jmeter Http proxy server throws java.net.URISyntaxException: Illegal character in query at index error

I am trying to record my web client-server communication using Jmeter. After the Jmeter and browser are configured for recording the application. When a post request is made from client to server, the following error happens. Any idea how to encode the URL which is being recorded?

java.net.URISyntaxException: Illegal character in query at index 238: http://localhost:8080/updateBoxCorrectionInstantly?examKey=16-17-%3ECBSE-%3ETERM%20I-%3ESA1-%3EVI-%3EScience-%3EA&studentName=AMOGH%20YOGESH%20KALE&studentRollno=3&studentND=-1&sheetName=cb8e806b32e9d670698655e0d2da10e3_img001210.jpg&box={%22$center%22:%22(66.0,%202253.0)%22,%22$conf%22:%22H%22,%22$corrected%22:true,%22$isAdminCorrected%22:true,%22$correction%22:%22-%22,%22$isDrawn%22:false,%22coords%22:[36,2214,96,2292],%22isTitle%22:false,%22pos%22:%22-%22,%22pred%22:%22-%22,%22boxTypeId%22:0,%22score%22:1}
at java.net.URI$Parser.fail(URI.java:2829)
at java.net.URI$Parser.checkChars(URI.java:3002)
at java.net.URI$Parser.parseHierarchical(URI.java:3092)
at java.net.URI$Parser.parse(URI.java:3034)
at java.net.URI.<init>(URI.java:595)
at java.net.URL.toURI(URL.java:949)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:232)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:62)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1075)
at org.apache.jmeter.protocol.http.proxy.Proxy.run(Proxy.java:212)
like image 500
AbiSivam Avatar asked Jan 26 '17 13:01

AbiSivam


1 Answers

Specifically that exception is about curly braces in your URI:

/updateBoxCorrectionInstantly?<...>_img001210.jpg&box={

Curly brackets are considered unsafe:

Other characters are unsafe because gateways and other transport agents are known to sometimes modify such characters. These characters are "{", "}", "|", "\", "^", "~", "[", "]", and "`". All unsafe characters must always be encoded within a URL.

So you could replace all instances of the { with %7B, and all instances of } with %7D. My guess is that recorder is not encoding them because curly brackets are not "special" characters (they are just "unsafe"), while URI parser does not like them. So you can consider it a bug in JMeter recorder. Thus minimal solution is to set Path to:

/updateBoxCorrectionInstantly?examKey=16-17-%3ECBSE-%3ETERM%20I-%3ESA1-%3EVI-%3EScience-%3EA&studentName=AMOGH%20YOGESH%20KALE&studentRollno=3&studentND=-1&sheetName=cb8e806b32e9d670698655e0d2da10e3_img001210.jpg&box=%7B%22$center%22:%22(66.0,%202253.0)%22,%22$conf%22:%22H%22,%22$corrected%22:true,%22$isAdminCorrected%22:true,%22$correction%22:%22-%22,%22$isDrawn%22:false,%22coords%22:[36,2214,96,2292],%22isTitle%22:false,%22pos%22:%22-%22,%22pred%22:%22-%22,%22boxTypeId%22:0,%22score%22:1%7D

However, I think a more elegant solution is saving all parameters (past the ? mark) in Parameters section, which has few advantages:

  1. It has an option to automatically encode them
  2. You can clearly see which parameters you are sending
  3. You can use variables when you need to instead of static values (you can in Path as well, but not without a lot of tedious and error-prone configuring)

Here's a screenshot of how I would create this request:

enter image description here

Because the Method is set to GET, all parameters are going to be part of URL anyways, but they will be properly encoded, so here's how it's sent:

enter image description here

like image 166
ytrewq Avatar answered Oct 30 '22 20:10

ytrewq