Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feign Client does not resolve Query parameter

Here is my interface.

public interface SCIMServiceStub {

    @RequestLine("GET /Users/{id}")
    SCIMUser getUser(@Param("id") String id);

    @RequestLine("GET /Groups?filter=displayName+Eq+{roleName}")
    SCIMGroup isValidRole(@Param("roleName") String roleName);

}

Here getUser call works fine. But isValidRole is not working properly as the request is eventually sent like this.

/Groups?filter=displayName+Eq+{roleName}"

Here {roleName} is not resolved. What am I missing here? Appreciate some help, as I'm clueless at this point.

Edit: 1 more question: Is there a way to avoid automatic url encoding of query parameters?

like image 233
Bee Avatar asked May 09 '17 11:05

Bee


People also ask

How do you pass a query parameter in feign client?

Query parameters can be configured in Feign clients by using the @RequestParam annotation from the Spring web framework on method arguments which should be passed as query parameters when calling the remote service.

Is feign client blocking?

Spring WebClient is a non-blocking reactive client to make HTTP requests. Feign is a library which helps us to create declarative REST clients easily with annotations and it provides better abstraction when we need to call an external service in Microservices Architecture.

How do you pass a URL in feign client?

Feign has a way to provide the dynamic URLs and endpoints at runtime. The following steps have to be followed: In the FeignClient interface we have to remove the URL parameter. We have to use @RequestLine annotation to mention the REST method (GET, PUT, POST, etc.):

Is feign client deprecated?

Feign client is really convenient tool to use. But I recently came to know that Rest-Template is going to be deprecated and will be replaced by WebClient, and Feign Client internally uses Rest-Template.


2 Answers

Working fine using @QueryMap

URL: /api/v1/task/search?status=PENDING&size=20&page=0

Map<String, String> parameters = new LinkedHashMap<>()
        parameters.put("status", "PENDING")
        parameters.put("size", "20")
        parameters.put("page", "0")
        def tasks = restClientFactory.taskApiClient.searchTasks(parameters)

Inside Client Interface

@RequestLine("GET /api/v1/task/search?{parameters}")
List<Task> searchTasks(@QueryMap Map<String, String> parameters)
like image 183
Chinthaka Dinadasa Avatar answered Oct 18 '22 15:10

Chinthaka Dinadasa


With Spring feign client below works fine :

@GetMapping("/Groups?filter=displayName+Eq+{roleName}")
    SCIMGroup isValidRole(@PathVariable(value = "roleName") String roleName);
like image 20
hitesh Avatar answered Oct 18 '22 14:10

hitesh