OpenFeign / feign

Feign makes writing java http clients easier
Apache License 2.0
9.44k stars 1.92k forks source link

Configuration in feign client does not affect #2193

Closed hryharenkaandrei closed 3 weeks ago

hryharenkaandrei commented 12 months ago

Greetings. Can you please help me figure out next problem? I use next dependency :

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

I have multiply feign clients. These clients work by https . So I created bean Feign.Builder something like this pseudocode:

    @Bean
    public Feign.Builder feignBuilder() {
        HostnameVerifier hostnameVerifier = (hostname, session) -> true;
        return Feign.builder()
                .client(new Client.Default(createSocketFactory(), hostnameVerifier));
    }

Next moment is interceptor. I have interceptor

public class FooConfiguration {

    @Bean
    public RequestInterceptor fooInterceptor( {
        ... pseudocode
                return interceptor;
    }

}

finally feign client is

@FeignClient(name = "foo-client", url = "${foo-client.url}", configuration = FooConfiguration.class)
public interface FooFeignClient {

    @PostMapping("/foo")
    Dto findFoo(@RequestBody FooDto fooDto);
}

My problem is interceptor does not work and interceptor was not called. It seems like configuration is not applied when I use client with SSL. Also, I tested it without SSL -when I DONT USE Feign.Builder feignBuilder() it works correctly and Interceptor was triggered.

I use spring boot 3.1.4

How can I force an interceptor to work with SSL?

abhishekkishore commented 11 months ago

Based on the code in ResponseHandler.handleResponse(), decodeError() is thrown before decode() is called (which invokes the interceptor). So the interceptor is unused at the moment.

kdavisk6 commented 3 weeks ago

You directly configured the Feign builder and did not include your interceptor, so it's not on your chain. When overriding the Feign.Builder you have to provide the entire builder. Check the Spring Cloud OpenFeign documentation.