2

I am trying to write a test case for a jersey resource using InMemory container provided by Jersey.

As my service method contains many multivalued parameters as filters, I opted to send all of those values as single JSON parameter, so that it will be easy to send a list of values for each filter.

When i send the JSON string using target("path").queryParam("filters", jsonString).request().get(); the call fails die to Jersey clients internal query builder, which is parsing the url and checking for path param templates in the url. Since the url contains my JSON with "{" in it, they are interpreted as path param. If I try to encode the JSON using URLEncode.encode(jsonStr, "UTF-8"), the path param template issue is solved but white spaces in JSON are received by server as "+" as jersey client encoding URL one more time, but server decoding it only once.

If I make the Queryparam as post param test is working, but i don't want to use POST for just to retrieve data.

I can't post original code due to company policies.

My question is, is there any way to disable path template check in jersey clieny by setting custom builder.

jnodorp
  • 217
  • 2
  • 10
Siva
  • 45
  • 1
  • 8

1 Answers1

4

A simpler solution would be to replace the '+' by '%20' as suggested here and here:

URLEncode.encode(jsonStr, "UTF-8").replaceAll("\\+", "%20");
Community
  • 1
  • 1
jnodorp
  • 217
  • 2
  • 10