1
votes

i want to call REST API Controller from my REST API Controller.

"http://localhost:8080/function/1?filter={"id":1435263}"

Since we cannot send directly ({"id":1435263})JSON query String along with url because of spring mvc cannot read "{",i am sending query string(Search variables) in the form of map .

Object response = restTemplate.getForObject(crudControllerURL,
            Object.class, map);

where map contains the values .

On Server side i am unable to retrieve this map. I tried @RequestParam Object obj but it did not work . I am clueless how can i get these values there?

Do i need to convert it into POST?

EDIT

when i try to use whole url with query String then i recieve

java.lang.IllegalArgumentException: Not enough variable values available to expand '"id"'

Adding Server side contoller code snippet(not whole) and please note i need to access map in Server REST API Controller . Server side controller

    @RequestMapping(value = "/{function}/{type}", method = RequestMethod.GET)
public List<Order> performFetchAll(@PathVariable String function,
        HttpServletRequest request) throws JsonParseException,
        JsonMappingException, IOException, InvalidAttributesException {
    String requestQueryString = request.getQueryString();
    if (requestQueryString == null
            || requestQueryString.equalsIgnoreCase(""))
        return orderService.findAll();

Please provide your feedback. Thanks.

1
And how do you think this helps in solving your issue? You post the client code but omit the server side code, which is where the issue is. Also why send son as an argument instead of the body? - M. Deinum
what is the exception coming? Have you configured the message converters?? - Bilbo Baggins
i am doing that right away. - lesnar
@bilbo baggins no i have not configured any converters - lesnar
@M.Deinum ... this is search function. user should able to search using query string and my design demands it to go through url only. - lesnar

1 Answers

3
votes

You should do this probably than complicating the request:

URL can be changed like this : http://localhost:8080/function/1?idFilter=1435263

@RequestMapping(value = "/{function}/{type}", method = RequestMethod.GET)
public List<Order> performFetchAll(@PathVariable String function, @RequestParam("idFilter") String id, HttpServletRequest request) throws JsonParseException,
        JsonMappingException, IOException, InvalidAttributesException {
//DO something
}

If your filter request is going to be big and complex like a json, change your method to POST and take the JSON and do your logic.