0

I need to parse the queryString part of a URL. The answer to this other question makes a very important point about

The problem with query part of an url is that there is no clear specification about how to handle parameters duplication.

Specifically, I need to read some URLs from a log file and then parse them into the exact same MultiValueMap<String, String[]> object that would ordinarily be passed in to a Spring MVC @RequestMapping-annotated method. But being a Unit Test, I really need to do this outside of a web container.

Googling for "spring mvc parse query string" is fruitless as most folks are concerned with how to prevent parsing of the queryString -- a totally different problem.

Community
  • 1
  • 1
Alex R
  • 11,364
  • 15
  • 100
  • 180
  • 1
    The query string isn't parsed by Spring MVC. It's parsed by the Servlet container and exposed through `HttpServletRequest`. – Sotirios Delimanolis Dec 08 '15 at 02:06
  • Servlet containers don't create MultiValueMap. There is an additional level of abstraction/obscurity added by Spring. – Alex R Dec 08 '15 at 02:28
  • [That logic is trivial.](https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolver.java#L69) – Sotirios Delimanolis Dec 08 '15 at 02:30
  • It's impossible to call that code from the outside. – Alex R Dec 08 '15 at 02:45
  • What I'm saying is it's not that code (which you can just copy paste) that you should be worrying about. It's the code that does the actual parsing in the Servlet container. Choose one you like and go copy its logic. – Sotirios Delimanolis Dec 08 '15 at 02:47
  • It's indeed trivial, Even I just wrote one: https://github.com/omnifaces/omnifaces/blob/2.2/src/main/java/org/omnifaces/util/Servlets.java#L247 Multi valued parameters are just stored in the same order as they appear in query string. – BalusC Dec 08 '15 at 08:04

0 Answers0