Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring-cloud-starter-openfeign: Invalid HTTP method: PATCH executing PATCH

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 !

like image 956
Kris Avatar asked May 06 '20 17:05

Kris


2 Answers


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.

like image 58
Alexander Yushko Avatar answered Nov 18 '22 03:11

Alexander Yushko


Just Add:

<dependency>
     <groupId>io.github.openfeign</groupId>
     <artifactId>feign-httpclient</artifactId>
</dependency>
like image 9
Jay Avatar answered Nov 18 '22 04:11

Jay