Search code examples
springspring-mvccurlspring-web

Spring returns only the first param from the query string


Spring returns only the first param from the query string, subsequent params are missing.

When calling the following URL with curl:

 curl -i -X GET -b usercookie.txt -c usercookie.txt http://localhost:8080/appname/users/user-id/campaigns?title=JSON&itemPerPage=5&page=0&orderBy=startDate

Only the title param has non-null value, the request.getQueryString() contains only "title=JSON"

When calling this one:

curl -i -X GET -b usercookie.txt -c usercookie.txt http://localhost:8080/appname/users/user-id/campaigns?page=0&title=JSON&itemPerPage=5&orderBy=startDate

the request.getQueryString() contains only the "page=0"

Controller code:

@Controller
public class Campaign {

...

    @RequestMapping(value = {"/users/{userId}/campaigns", "/users/{userId}/campaigns/"}, 
            method = RequestMethod.GET)
    @ResponseBody
    public CampaignListResponse getCampaignList(
            @PathVariable(value="userId") String reqUserId,
            @RequestParam(required=false) Integer page, 
            @RequestParam(required=false) Integer itemPerPage,
            @RequestParam(required=false) String orderBy,
            @RequestParam(required=false) String status,
            @RequestParam(required=false) String title,                                         
            HttpServletRequest request,
            HttpServletResponse response,
            @CookieValue("session") String session) {
        LOGGER.debug("reqUserId:{} page:{}, itemPerPage:{}, orderBy:{}, state:{}, title:{}", reqUserId, page, itemPerPage, orderBy, status, title);
        LOGGER.debug("query string:{}", request.getQueryString());
...

What could be the cause of this? I expect all of the following params have a value both in the request.getQueryString(), and as individual @RequestParam variables:

page=0&title=JSON&itemPerPage=5&orderBy=startDate

Edit Spring Version: 3.2.2


Solution

  • From your terminal just put the whole URL between double quotes ! & is a special character that asks the task to be run in background. You won't have to change your code.

    Try this :

    curl -i -X GET -b usercookie.txt -c usercookie.txt "http://localhost:8080/appname/users/user-id/campaigns?title=JSON&itemPerPage=5&page=0&orderBy=startDate"