spring-cloud-openfeign: Feign client returns empty response body, when http code is 401

FeignClient return an empty response body (response.body()) whenever the response status code is 401. I have did a direct call to the server through postman and the response is returning as expected with proper body. So no problem on server side.

I have also tried ApacheHttpClient as well as OkHttpClient and still the issue exits.

Version used: JDK 11, openfeign 2.2.6

You can find below snapshots of the dependencies I am using as well as configuration:

         <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>commons-io</groupId>
                    <artifactId>commons-io</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-okhttp</artifactId>
        </dependency>
feign:
  client:
    config:
      default:
        connectTimeout: 5000
        readTimeout: 30000
        loggerLevel: NONE

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 21

Most upvoted comments

It is very obvious that you get null body response when http code is 401. There is no further needed information.

Go write Feign configuration, send http request with it. If you get 401 from anywhere, anytime you will see at the debugger feign decoder reponse’ is always null

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@OlgaMaciaszek thanks for the links. that helped.

the following settings fix the problem for me:

add the following dependency at the gradle.build implementation 'io.github.openfeign:feign-hc5:13.3'

and enable the feign-hc5 client for spring cloud in the application.yml:

spring:
  cloud:
    openfeign:
      httpclient:
        hc5:
          enabled: true

@ulpcan if you want us to look at the issue, please provide a minimal, complete, verifiable example that reproduces the issue, as a link to a GitHub repo with a sample app or tests.

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@ariady-putra please provide a minimal, complete, verifiable example that reproduces the issue.