22

we are using netflix feign to make call to restful web service. For patch request it looks like PATCH request is not supported.

Caused by: feign.RetryableException: Invalid HTTP method: PATCH executing PATCH https://projects.dev.xyz.com/projects/v1/users/{uid}/projects/{guid} at feign.FeignException.errorExecuting(FeignException.java:66) at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:100) at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:74) at feign.hystrix.HystrixInvocationHandler$1.run(HystrixInvocationHandler.java:54) at com.netflix.hystrix.HystrixCommand$1.call(HystrixCommand.java:294)

user2775185
  • 1,099
  • 3
  • 17
  • 30

5 Answers5

20

if someone encounters the same problem with spring-cloud-feign, using the httpClient from feign can be achieved by just adding the maven dependency:

    <dependency>
        <!-- Required to use PATCH -->
        <groupId>io.github.openfeign</groupId>
        <artifactId>feign-httpclient</artifactId>
        <version>${feign.version}</version>
    </dependency>
D-rk
  • 5,513
  • 1
  • 37
  • 55
  • True. And if you use the `Feign.builder()` keep on reading the next answer as well... ;) https://stackoverflow.com/a/38058469/1326662 – Ralf Oct 22 '20 at 15:24
14

You can solve this by using the httpClient from feign. You want to first add the module to your classpath, then configure it when you're building your object with Feign.builder().client(new ApacheHttpClient()). This adds support for PATCH requests.

Link to Doc: https://github.com/Netflix/feign/tree/master/httpclient

EDIT: there is also a feign object that wraps apache's http client, link here

Adam Karpowich
  • 161
  • 1
  • 9
3

I also faced the same issue but managed to solve it by adding the feign-httpclient dependency and adding a additional header X-HTTP-Method-Override : PATCH in the request.

<dependency>
    <!-- Required to use PATCH -->
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-httpclient</artifactId>
    <version>${feign.version}</version>
</dependency>

Add a header

@RequestHeader(value="X-HTTP-Method-Override", defaultValue="PATCH") String xHttpMethodOveride
Soumyajit Swain
  • 1,298
  • 1
  • 21
  • 35
3

if you using implementation("org.springframework.cloud:spring-cloud-starter-openfeign") and having issue with patch request then you can do below (kotlin) :

Add this dependency

 implementation("io.github.openfeign:feign-okhttp:10.2.0")

Create below configuration class

class FeignOkHttpConfiguration {

    @Bean
    fun client(): OkHttpClient {
        return OkHttpClient()
    }
}

and add this configuration to your client (if you like this to be common config for every feign client then you can also add @Configuration for class FeignOkHttpConfiguration).

@FeignClient(name = "YourClient", url = "\${base-url}", configuration = [FeignOkHttpConfiguration::class])
interface YourClient {

@PatchMapping
fun update(model: YourModel): ResponseEntity<String>

}
hitesh
  • 176
  • 1
  • 3
  • adding the okhttp bean and lib was the only method i could get working (Java) spring cloud 2022.0.1 and spring boot 3 – dale Jan 30 '23 at 12:46
0

I have dependency on

implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign'

and PATCH caused troubles, also I configured custom client in order to process raw response before mapping to response type. Solution is to add dependency with proper http client, this for instance

implementation group: 'io.github.openfeign', name: 'feign-httpclient', version: '11.7'

Then I configured my client with ApacheHttpClient like:

    @Bean
    Client customClient(SessionStorage sessionStorage) {
        return new CustomClient(new ApacheHttpClient(), sessionStorage);
    }
karma_police
  • 332
  • 2
  • 14