1

Basically, what I am trying to do is make a request like this:

http://localhost:8085/api/candidates/searchWithFacet?q=helmut&page=0&size=20&fq=skills%3A%22Keine%20Angabe%22&

but Spring MVC is throwing this error:

java.net.URISyntaxException: Illegal character in query at index 51: /api/candidates/searchWithFacet?q=helmut&fq=skills:"Keine Angabe"?page=0&size=20

I don't understand why it is stating that I have an illegal character as I am encoding it. I have also tried encoding the whole URL, not just the last part of it like this:

http://localhost:8085/%2Fapi%2Fcandidates%2Fsearch%3Fq%3Dhelmut%26page%3D0%26size%3D20

The error I am receiving here is 400 - Bad Request.

My two involved Controller functions are:

@Timed
@RequestMapping(value = "/candidates/search", method = RequestMethod.GET, produces = {
        MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<CandidateListDTO> searchCandidatesWithFaceting(@RequestParam(name = "q") String query,
        Pageable page) throws SolrServerException, URISyntaxException {

...

@Timed
@RequestMapping(value = "/candidates/searchWithFacet", method = RequestMethod.GET, produces = {
        MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<CandidateListDTO> getCandidatesWithFacet(@RequestParam(name = "q") String query,
        @RequestParam(name = "fq") String facetQuery, Pageable page)
        throws SolrServerException, URISyntaxException {

Any help is appreciated, thanks in advance! :-)

Turbut Alin
  • 2,568
  • 1
  • 21
  • 30
  • Which Spring version and are you encoding the URL yourself? – Kayaman Apr 15 '16 at 07:17
  • I am encoding the URL with Javascript's encodeURIComponent() and the Spring's version is 4.2.5. – Turbut Alin Apr 15 '16 at 07:50
  • What happens if you don't encode it? URLs are supposed to handle multiple question marks [perfectly fine](http://stackoverflow.com/questions/2924160/is-it-valid-to-have-more-than-one-question-mark-in-a-url). – Kayaman Apr 15 '16 at 09:22
  • Same error as the first one. The problem is not with the question mark but with double quotes, space and illegal URL characters. Basically if I send it encoded or not, the error and the received URL is the same. I have tried changing the pathMatcher with no trim tokenization from this [example](http://stackoverflow.com/questions/26110136/spring-mvc-uri-mapping-with-percent-encoded-characters?rq=1), but the error is the same – Turbut Alin Apr 15 '16 at 09:35
  • Another mention is that I've tried the same URL and same method on another Spring server and the URL is handled just fine, so I am sure this has something to do with the Spring configuration, but I don't know with what exactly :( – Turbut Alin Apr 15 '16 at 09:39
  • Could be a Spring bug. See if you can find anything related in their issue tracker. – Kayaman Apr 15 '16 at 09:42
  • Is this error is still not solved?? – Prasanna Kumar H A Sep 29 '16 at 04:10

0 Answers0