Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude RequestInterceptor for an specific Spring Cloud Feign client?

I have a number of clients for which a "global" RequestInterceptor has been defined. For one of the clients I need this "global" interceptor to be excluded. Is it possible to override the full set of RequestInterceptors for a particular FeignClient?

@FeignClient(value = "foo", configuration = FooClientConfig.class)
public interface FooClient {
//operations
}

@Configuration
public class FooClientConfig{

//How do I exclude global interceptors from this client configuration?
}

The spring-cloud-netflix version in use is 1.1.0 M5

like image 686
Newbie Avatar asked Mar 15 '16 18:03

Newbie


1 Answers

It seems there is no easy way to override the global interceptor. I think you could do it like this:

@Configuration
public class FooClientConfig{

@Bean
RequestInterceptor globalRequestInterceptor() {
    return template -> {
        if (template.url().equals("/your_specific_url")) {
            //don't add global header for the specific url
            return;
        }

        //add header for the rest of requests
        template.header(AUTHORIZATION, String.format("Bearer %s", token));
    };
}
}
like image 142
fungbo Avatar answered Oct 18 '22 13:10

fungbo