11

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 !

Olexander Yushko
  • 2,434
  • 16
  • 16
Kris
  • 401
  • 2
  • 7
  • 16

4 Answers4

34

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.

Olexander Yushko
  • 2,434
  • 16
  • 16
12

Just Add:

<dependency>
     <groupId>io.github.openfeign</groupId>
     <artifactId>feign-httpclient</artifactId>
</dependency>
Jay Ehsaniara
  • 1,421
  • 17
  • 24
  • 2
    That is not sufficient by itself, you also need to provide `feign.httpclient.enabled: true`. – Shannon Aug 03 '21 at 21:15
  • 1
    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
  • Adding this dependency it fails the application with: `Unsatisfied dependency expressed through method 'connectionManager' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.commons.httpclient.ApacheHttpClientConnectionManagerFactory' available` – f.trajkovski Aug 26 '22 at 12:14
  • This is to upvote @Shannon's comment. From the docs, "Starting with Spring Cloud OpenFeign 4, the Feign Apache HttpClient 4 is no longer supported. We suggest using Apache HttpClient 5 instead." So `io.github.openfeign:feign-hc5` provided with `feign.httpclient.hc5.enabled: true` is the go-to solution for newer versions of OpenFeign. – Sam S Feb 23 '23 at 12:48
3

If you are adding Feign with the following dependency:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId> <!-- has dependecy on spring-cloud-openfeign-core inside, which already maintains version of feign-okhttp artifact -->
</dependency>

you can add okhttp client (without hardcoding artifact version) to fix the issue with PATCH request:

<dependency>
      <groupId>io.github.openfeign</groupId>
      <artifactId>feign-okhttp</artifactId> <!-- Required to use PATCH -->
</dependency>

No other steps needed. The okhttp client will be applied automatically by auto configuration.

Also, this way you don't need to manage feign-okhttp artifact version. Spring Cloud will manage version for you.

Tested with Spring Boot 2.7.6

Eugene Maysyuk
  • 2,977
  • 25
  • 24
-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

Olexander Yushko
  • 2,434
  • 16
  • 16
Dharma
  • 1