8

Context

I have a spring boot (version 2.2.6.RELEASE) web project.

From this web application (I call "APP1") I want to call another URI using the PATCH method from another web application (Let's call it "APP2"). In my pom.xml, I have the following dependency:

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

Here is how I call the PATCH method of the other web application.

@FeignClient(name = "clientName", url = "base-uri")
public interface MyInterface{
   @PatchMapping(value = "/target-uri")
    void callClientMethod(Map<String, Object> args);

Problem

  • The APP2's PATCH method is effectively being called
  • But then APP1 throws the following error:
    • feign.RetryableException: Invalid HTTP method: PATCH executing PATCH

I looked on the Internet for a solution, and added the following snipet to my pom.xml

<dependency>
    <groupId>com.netflix.feign</groupId> <!-- Also tried io.github.openfeign -->
    <artifactId>feign-httpclient</artifactId>
    <version>8.18.0</version>
</dependency>

After that, APP2's PATCH method is stille properly called but in APP1 I got the following error : java.lang.NoSuchMethodError: feign.Response.create(ILjava/lang/String;Ljava/util/Map;Lfeign/Response$Body;)Lfeign/Response;

Question

  • Does anyone know how to solve this error ?

Thanks in advance for your help !

Alexander Yushko
  • 2,046
  • 13
  • 15
Kris
  • 351
  • 1
  • 6
  • 15

3 Answers3

24

I had the same problem and spent a lot of time for understand and resolve this problem.
First what you need to understand that is the Feign doesn't support PATCH http method for call from the box!
And if you can change methods in both services use PUT for update instead PATCH...

But if you integrate with third party implementation you should add some configurations:
1. Add dependency which support PATCH http method:

// https://mvnrepository.com/artifact/io.github.openfeign/feign-okhttp
compile group: 'io.github.openfeign', name: 'feign-okhttp', version: '10.2.0'

  1. Add configuration:
@Configuration 
public class FeignConfiguration {
    @Bean
    public OkHttpClient client() {
        return new OkHttpClient();
    } 
}
  1. And example for PATCH request with Feign:
@FeignClient(name = "someapi", url = "${client.someapi.url}")
@Component
@RequestMapping("/users")
public interface SomeClient {

    @RequestMapping(value = "/{id}",
            method = RequestMethod.PATCH,
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE)
    FeignUser update(@PathVariable("id") Long id, @RequestBody Map<String, Object> fields);
}

Hope it helps someone.

Alexander Yushko
  • 2,046
  • 13
  • 15
5

Just Add:

<dependency>
     <groupId>io.github.openfeign</groupId>
     <artifactId>feign-httpclient</artifactId>
</dependency>
Jay
  • 1,026
  • 13
  • 20
  • That is not sufficient by itself, you also need to provide `feign.httpclient.enabled: true`. – Shannon Aug 03 '21 at 21:15
  • Also, if you prefer to use Apache httpclient5, you can depend on `io.github.openfeign:feign-hc5` instead, and provide `feign.httpclient.hc5.enabled: true` – Shannon Aug 03 '21 at 21:17
-1

The following config works for me:

<dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-jackson</artifactId>
    <version>${feign.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-httpclient</artifactId>
    <version>${feign.version}</version>
</dependency>

Where:

feign.version - 11.0
Spring Boot - 2.3.0.RELEASE
Spring-cloud.version - 2.2.3.RELEASE

Alexander Yushko
  • 2,046
  • 13
  • 15
Dharma
  • 1