2

I am using Spring-Boot 3.0.2 with openfeign 4.0.1 in a small Spring-boot application.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.0.2</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

...

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
    <version>4.0.1</version>
</dependency>

My feign client looks fairly easy:

@FeignClient
public interface MyFeignClient {

    @RequestLine("GET /Users")
    @CollectionFormat(feign.CollectionFormat.CSV)
    BaseResponseWithResultSetDto<UserResponseDto> getAllowedUsers(@SpringQueryMap QueryDTO query);
//...

The query dto consists of 2 fields, select and filter which both are list of strings.

public class QueryDTO{

    @JsonProperty("$select")
    private List<String> select;
    @JsonProperty("$filter")
    private List<String> filter;

// getters + setters + add

After I built the client with the feign builder I try to call my getAllowedUsers method and pass my dto for filtering and selecting fields for the response.

QueryDTO dto = new QueryDTO ();
dto.addSelect("UserCode");
dto.addSelect("InternalKey");
dto.addFilter("IsAllowed eq 'Y'");
BaseResponseWithResultSetDto<UserResponseDto> result = this.myFeignClient.getAllowedUsers(dto);

The expected request URL would be: /Users?$select=UserCode,InternalKey&$filter=IsAllowed eq 'Y'

But instead feign only generates /Users and passes the query map as body in the GET request. This can be seen in the DEBUG log:

2023-02-23T09:53:52.840+01:00 DEBUG 9236 --- [  restartedMain] org.apache.http.headers                  : http-outgoing-0 >> GET /b1s/v2/Users HTTP/1.1
...
2023-02-23T09:53:52.856+01:00 DEBUG 9236 --- [  restartedMain] org.apache.http.wire                     : http-outgoing-0 >> "[\r][\n]"
2023-02-23T09:53:52.857+01:00 DEBUG 9236 --- [  restartedMain] org.apache.http.wire                     : http-outgoing-0 >> "{[\r][\n]"
2023-02-23T09:53:52.858+01:00 DEBUG 9236 --- [  restartedMain] org.apache.http.wire                     : http-outgoing-0 >> "  "$select" : [ "UserCode", "InternalKey" ],[\r][\n]"
2023-02-23T09:53:52.858+01:00 DEBUG 9236 --- [  restartedMain] org.apache.http.wire                     : http-outgoing-0 >> "  "$filter" : [ "IsAllowed eq 'Y'" ][\r][\n]"
2023-02-23T09:53:52.859+01:00 DEBUG 9236 --- [  restartedMain] org.apache.http.wire                     : http-outgoing-0 >> "}"

Also in the access log of the corresponding service I only see requests to /Users [23/Feb/2023:09:53:52 +0100] 127.0.0.1 290582 "GET /b1s/v2/Users HTTP/1.1" 200 18291 ssl=TLSv1.2 t=0s pid=5232 sid=- sid2=- n=- +

Any ideas what I am missing? I am aware, that I could possibly use a PathParam, RequestParam, Param approach, but this is not what I intend for future use.

I read the docs for Spring Open Feign, but the docs are a bit meager about the use and the result of this implementation.

I expected that the resulting URL would be /Users?$select=UserCode,InternalKey&$filter=IsAllowed eq 'Y' but instead the query params were passed as body in my GET request.

kerbermeister
  • 2,985
  • 3
  • 11
  • 30
robhok
  • 21
  • 2

0 Answers0