Search code examples
javaspringkotlinspring-cloud-feignfeign

Cannot change Feign Default client. PATCH mapping does not work


Config file

@Configuration
public class MyApiConfig {
    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }

    @Bean
    public OkHttpClient client() {
        return new OkHttpClient();
    }
}

Client class

@FeignClient(
    name = "wallesterApi",
    url = "https://api-frontend.wallester.com/v1",
    primary = false,
    configuration = [MyApiConfig::class]
)
interface WallesterApi {

    @RequestMapping(value = ["/cards/{card_id}/replace"], method = [RequestMethod.PATCH])
    fun replaceCard(
        @RequestHeader(value = "Authorization") authorization: String,
        @PathVariable(name = "card_id") cardId: String
    ): WallesterCardResponse
}

application config with feign

feign:
  client:
    config:
      default:
        logger-level: full
  okhttp:
    enabled: true

I have also dependencies

    <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        <dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-okhttp</artifactId> <!-- Required to use PATCH -->
        </dependency>

Spring boot 2.7.3, Spring Cloud 2021.0.8

My HTTP PATCH requests fail with <--- ERROR ProtocolException: Invalid HTTP method: PATCH (4ms)


I tried guides that exist here, also tried http-client instead of okhttp

What I can see is that noting actually influences FeignAutoConfiguration class. I can't event get there with debug breakpoints. I still get default http client without PATCH support.


Solution

  • For some reason - adding dependencies or changing application.yml - was not a solution for me.

    I tried many different configurations and advices. I came to a custom solution, with overriding feign client configuration and client manually.

    I linked code that works for me in a simple example in GitHub https://github.com/vadimyemelyanov/feignpatchfix

    Hope that will help somebody ^)