feign.RetryableException: Invalid HTTP method: PATCH executing PATCH
I'm using the following versions Spring Boot 2.2.8 Spring Cloud Hoxton.SR4 Open Feign 2.2.2 Java 11
I'm trying to use feign client with PATCH method as following:
@PatchMapping("/clients/{clientId}")
Client updateClient(@PathVariable("clientId") String clientId, @RequestBody Client client);
but I got this error
feign.RetryableException: Invalid HTTP method: PATCH executing PATCH
Comment From: eduanb
@MahmoudRagab726 This is an issue with Java's HttpURLConnection
. The workaround is to not use HttpURLConnection
. There are some options like HttpClient
. See this from Stackoverflow https://stackoverflow.com/questions/35374030/invalid-http-method-patch-executing-patch-caused-by-feign-retryableexcepti
Comment From: agitrubard
It Works Seamlessly!
@MahmoudRagab726 This is an issue with Java's
HttpURLConnection
. The workaround is to not useHttpURLConnection
. There are some options likeHttpClient
. See this from Stackoverflow https://stackoverflow.com/questions/35374030/invalid-http-method-patch-executing-patch-caused-by-feign-retryableexcepti
Comment From: 90K2
If it applicable to post small solution right here I would like to leave it for descendants
- Add feign-okhttp as additional dependency into
build.gradle.kts
implementation("org.springframework.cloud:spring-cloud-starter-openfeign:4.0.3")
implementation("io.github.openfeign:feign-okhttp:13.5")
Create feign.okhttp.OkHttpClient bean (that replacing default HttpConection)
@Bean
fun okHttpClient() = OkHttpClient.Builder()
.retryOnConnectionFailure(true)
.build()
@Bean
fun feignClient(client: OkHttpClient) = feign.okhttp.OkHttpClient(client)